git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273479 13f79535-47bb-0310-9956-ffa450edef68master
@@ -22,8 +22,8 @@ Fixed bugs: | |||||
* <manifest> wouldn't update an existing manifest if only an attribute | * <manifest> wouldn't update an existing manifest if only an attribute | ||||
of an existing section changed. | of an existing section changed. | ||||
* ant.bat now supports the ANT_ARGS environment variable again (like | |||||
Ant 1.5 did). | |||||
* ant.bat now supports the ANT_ARGS and JAVACMD environment variables | |||||
again (like Ant 1.5 did). | |||||
* The "plain" <junit> <formatter> could throw a NullPointerException | * The "plain" <junit> <formatter> could throw a NullPointerException | ||||
if an error occured in setUp. | if an error occured in setUp. | ||||
@@ -79,6 +79,7 @@ import org.apache.tools.ant.BuildException; | |||||
import org.apache.tools.ant.taskdefs.XSLTLiaison; | import org.apache.tools.ant.taskdefs.XSLTLiaison; | ||||
import org.apache.tools.ant.taskdefs.XSLTLogger; | import org.apache.tools.ant.taskdefs.XSLTLogger; | ||||
import org.apache.tools.ant.taskdefs.XSLTLoggerAware; | import org.apache.tools.ant.taskdefs.XSLTLoggerAware; | ||||
import org.apache.tools.ant.util.JAXPUtils; | |||||
import org.xml.sax.EntityResolver; | import org.xml.sax.EntityResolver; | ||||
import org.xml.sax.InputSource; | import org.xml.sax.InputSource; | ||||
import org.xml.sax.XMLReader; | import org.xml.sax.XMLReader; | ||||
@@ -144,7 +145,7 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware | |||||
fos = new BufferedOutputStream(new FileOutputStream(outfile)); | fos = new BufferedOutputStream(new FileOutputStream(outfile)); | ||||
StreamResult res = new StreamResult(fos); | StreamResult res = new StreamResult(fos); | ||||
// not sure what could be the need of this... | // not sure what could be the need of this... | ||||
res.setSystemId(getSystemId(outfile)); | |||||
res.setSystemId(JAXPUtils.getSystemId(outfile)); | |||||
Source src = getSource(fis, infile); | Source src = getSource(fis, infile); | ||||
transformer.transform(src, res); | transformer.transform(src, res); | ||||
} finally { | } finally { | ||||
@@ -192,7 +193,7 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware | |||||
} else { | } else { | ||||
src = new StreamSource(is); | src = new StreamSource(is); | ||||
} | } | ||||
src.setSystemId(getSystemId(infile)); | |||||
src.setSystemId(JAXPUtils.getSystemId(infile)); | |||||
return src; | return src; | ||||
} | } | ||||
@@ -218,7 +219,7 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware | |||||
StreamSource src = new StreamSource(xslStream); | StreamSource src = new StreamSource(xslStream); | ||||
// Always set the systemid to the source for imports, includes... | // Always set the systemid to the source for imports, includes... | ||||
// in xsl and xml... | // in xsl and xml... | ||||
src.setSystemId(getSystemId(stylesheet)); | |||||
src.setSystemId(JAXPUtils.getSystemId(stylesheet)); | |||||
Templates templates = getFactory().newTemplates(src); | Templates templates = getFactory().newTemplates(src); | ||||
Transformer transformer = templates.newTransformer(); | Transformer transformer = templates.newTransformer(); | ||||
@@ -244,23 +245,6 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware | |||||
} | } | ||||
} | } | ||||
// make sure that the systemid is made of '/' and not '\' otherwise | |||||
// crimson will complain that it cannot resolve relative entities | |||||
// because it grabs the base uri via lastIndexOf('/') without | |||||
// making sure it is really a /'ed path | |||||
protected String getSystemId(File file) { | |||||
String path = file.getAbsolutePath(); | |||||
path = path.replace('\\', '/'); | |||||
// on Windows, use 'file:///' | |||||
if (File.separatorChar == '\\') { | |||||
return FILE_PROTOCOL_PREFIX + "/" + path; | |||||
} | |||||
// Unix, use 'file://' | |||||
return FILE_PROTOCOL_PREFIX + path; | |||||
} | |||||
/** | /** | ||||
* return the Transformer factory associated to this liaison. | * return the Transformer factory associated to this liaison. | ||||
* @return the Transformer factory associated to this liaison. | * @return the Transformer factory associated to this liaison. | ||||
@@ -400,4 +384,12 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware | |||||
logger.log(msg.toString()); | logger.log(msg.toString()); | ||||
} | } | ||||
// kept for backwards compatibility | |||||
/** | |||||
* @deprecated use org.apache.tools.ant.util.JAXPUtils#getSystemId instead | |||||
*/ | |||||
protected String getSystemId(File file) { | |||||
return JAXPUtils.getSystemId(file); | |||||
} | |||||
} //-- TraXLiaison | } //-- TraXLiaison |
@@ -64,6 +64,7 @@ import javax.xml.parsers.DocumentBuilderFactory; | |||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
import org.apache.tools.ant.util.JAXPUtils; | |||||
import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
import org.w3c.dom.Document; | import org.w3c.dom.Document; | ||||
@@ -212,20 +213,18 @@ public class AggregateTransformer { | |||||
if (NOFRAMES.equals(format)){ | if (NOFRAMES.equals(format)){ | ||||
xslname = "junit-noframes.xsl"; | xslname = "junit-noframes.xsl"; | ||||
} | } | ||||
URL url = null; | |||||
if (styleDir == null){ | if (styleDir == null){ | ||||
url = getClass().getResource("xsl/" + xslname); | |||||
URL url = getClass().getResource("xsl/" + xslname); | |||||
if (url == null){ | if (url == null){ | ||||
throw new FileNotFoundException("Could not find jar resource " + xslname); | throw new FileNotFoundException("Could not find jar resource " + xslname); | ||||
} | } | ||||
} else { | |||||
File file = new File(styleDir, xslname); | |||||
if (!file.exists()){ | |||||
throw new FileNotFoundException("Could not find file '" + file + "'"); | |||||
} | |||||
url = new URL("file", "", file.getAbsolutePath()); | |||||
return url.toExternalForm(); | |||||
} | |||||
File file = new File(styleDir, xslname); | |||||
if (!file.exists()){ | |||||
throw new FileNotFoundException("Could not find file '" + file + "'"); | |||||
} | } | ||||
return url.toExternalForm(); | |||||
return JAXPUtils.getSystemId(file); | |||||
} | } | ||||
} | } |
@@ -53,6 +53,7 @@ | |||||
*/ | */ | ||||
package org.apache.tools.ant.util; | package org.apache.tools.ant.util; | ||||
import java.io.File; | |||||
import javax.xml.parsers.FactoryConfigurationError; | import javax.xml.parsers.FactoryConfigurationError; | ||||
import javax.xml.parsers.ParserConfigurationException; | import javax.xml.parsers.ParserConfigurationException; | ||||
import javax.xml.parsers.SAXParser; | import javax.xml.parsers.SAXParser; | ||||
@@ -74,6 +75,11 @@ import org.xml.sax.XMLReader; | |||||
*/ | */ | ||||
public class JAXPUtils { | public class JAXPUtils { | ||||
/** | |||||
* The file protocol: 'file://' | |||||
*/ | |||||
private static final String FILE_PROTOCOL_PREFIX = "file://"; | |||||
/** | /** | ||||
* Parser factory to use to create parsers. | * Parser factory to use to create parsers. | ||||
* @see #getParserFactory | * @see #getParserFactory | ||||
@@ -147,6 +153,27 @@ public class JAXPUtils { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* This is a best attempt to provide a URL.toExternalForm() from | |||||
* a file URL. Some parsers like Crimson choke on uri that are made of | |||||
* backslashed paths (ie windows) as it is does not conform | |||||
* URI specifications. | |||||
* @param file the file to create the system id from. | |||||
* @return the systemid corresponding to the given file. | |||||
* @since Ant 1.5.2 | |||||
*/ | |||||
public static String getSystemId(File file){ | |||||
String path = file.getAbsolutePath(); | |||||
path = path.replace('\\', '/'); | |||||
// on Windows, use 'file:///' | |||||
if (File.separatorChar == '\\') { | |||||
return FILE_PROTOCOL_PREFIX + "/" + path; | |||||
} | |||||
// Unix, use 'file://' | |||||
return FILE_PROTOCOL_PREFIX + path; | |||||
} | |||||
/** | /** | ||||
* @return a new SAXParser instance as helper for getParser and | * @return a new SAXParser instance as helper for getParser and | ||||
* getXMLReader. | * getXMLReader. | ||||
@@ -2,7 +2,6 @@ package org.apache.tools.ant.taskdefs.optional; | |||||
import org.apache.tools.ant.taskdefs.XSLTLiaison; | import org.apache.tools.ant.taskdefs.XSLTLiaison; | ||||
import org.apache.tools.ant.taskdefs.XSLTLogger; | import org.apache.tools.ant.taskdefs.XSLTLogger; | ||||
import org.apache.tools.ant.taskdefs.condition.Os; | |||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import java.io.File; | import java.io.File; | ||||
@@ -0,0 +1,80 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2002 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.util; | |||||
import junit.framework.TestCase; | |||||
import java.io.File; | |||||
/** | |||||
* JAXPUtils test case | |||||
* @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | |||||
*/ | |||||
public class JAXPUtilsTest extends TestCase { | |||||
public JAXPUtilsTest(String name){ | |||||
super(name); | |||||
} | |||||
public void testGetSystemId(){ | |||||
File file = null; | |||||
if ( File.separatorChar == '\\' ){ | |||||
file = new File("d:\\jdk"); | |||||
} else { | |||||
file = new File("/user/local/bin"); | |||||
} | |||||
String systemid = JAXPUtils.getSystemId(file); | |||||
assertTrue("SystemIDs should start by file:///", systemid.startsWith("file:///")); | |||||
assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////")); | |||||
} | |||||
} |