as relative to the basdir attribute. Make sure it works when handed an absolute path. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268820 13f79535-47bb-0310-9956-ffa450edef68master
@@ -6,9 +6,6 @@ Changes that could break older environments: | |||||
* Zip.setWhenempty() has changed its signature. | * Zip.setWhenempty() has changed its signature. | ||||
* <style>'s style attribute will be resolved as relative to the | |||||
projects basedir instead of the basedir attribute of the task. | |||||
Fixed bugs: | Fixed bugs: | ||||
----------- | ----------- | ||||
@@ -27,6 +24,8 @@ Fixed bugs: | |||||
* won't try to pass a -bootclasspath flag to javac 1.1 anymore | * won't try to pass a -bootclasspath flag to javac 1.1 anymore | ||||
* <style>'s style attribute no handles absolute paths correctly. | |||||
Changes from Ant 1.2 to Ant 1.3 | Changes from Ant 1.2 to Ant 1.3 | ||||
=========================================== | =========================================== | ||||
@@ -52,7 +52,8 @@ inclusion/exclusion of files works, and how to write patterns.</p> | |||||
</tr> | </tr> | ||||
<tr> | <tr> | ||||
<td valign="top">style</td> | <td valign="top">style</td> | ||||
<td valign="top">name of the stylesheet to use.</td> | |||||
<td valign="top">name of the stylesheet to use - given either relative | |||||
to the basedir attribute or as an absolute path.</td> | |||||
<td align="center" valign="top">Yes</td> | <td align="center" valign="top">Yes</td> | ||||
</tr> | </tr> | ||||
<tr> | <tr> | ||||
@@ -537,7 +537,13 @@ public class Project { | |||||
} while (!curtarget.getName().equals(targetName)); | } while (!curtarget.getName().equals(targetName)); | ||||
} | } | ||||
public File resolveFile(String fileName) { | |||||
/** | |||||
* Return the canonical form of fileName as an absolute path. | |||||
* | |||||
* <p>If fileName is a relative file name, resolve it relative to | |||||
* rootDir.</p> | |||||
*/ | |||||
public File resolveFile(String fileName, File rootDir) { | |||||
fileName = fileName.replace('/', File.separatorChar).replace('\\', File.separatorChar); | fileName = fileName.replace('/', File.separatorChar).replace('\\', File.separatorChar); | ||||
// deal with absolute files | // deal with absolute files | ||||
@@ -580,14 +586,14 @@ public class Project { | |||||
return new File(sb.toString()); | return new File(sb.toString()); | ||||
} | } | ||||
File file = new File(baseDir.getAbsolutePath()); | |||||
File file = new File(rootDir.getAbsolutePath()); | |||||
StringTokenizer tok = new StringTokenizer(fileName, File.separator, false); | StringTokenizer tok = new StringTokenizer(fileName, File.separator, false); | ||||
while (tok.hasMoreTokens()) { | while (tok.hasMoreTokens()) { | ||||
String part = tok.nextToken(); | String part = tok.nextToken(); | ||||
if (part.equals("..")) { | if (part.equals("..")) { | ||||
String parentFile = file.getParent(); | String parentFile = file.getParent(); | ||||
if (parentFile == null) { | if (parentFile == null) { | ||||
throw new BuildException("The file or path you specified (" + fileName + ") is invalid releative to " + baseDir.getAbsolutePath()); | |||||
throw new BuildException("The file or path you specified (" + fileName + ") is invalid releative to " + rootDir.getAbsolutePath()); | |||||
} | } | ||||
file = new File(parentFile); | file = new File(parentFile); | ||||
} else if (part.equals(".")) { | } else if (part.equals(".")) { | ||||
@@ -607,6 +613,10 @@ public class Project { | |||||
} | } | ||||
} | } | ||||
public File resolveFile(String fileName) { | |||||
return resolveFile(fileName, baseDir); | |||||
} | |||||
/** | /** | ||||
* Translate a path into its native (platform specific) format. | * Translate a path into its native (platform specific) format. | ||||
* <p> | * <p> | ||||
@@ -92,7 +92,7 @@ public class XSLTProcess extends MatchingTask { | |||||
private File baseDir = null; | private File baseDir = null; | ||||
private File xslFile = null; | |||||
private String xslFile = null; | |||||
private String targetExtension = ".html"; | private String targetExtension = ".html"; | ||||
private Vector params = new Vector(); | private Vector params = new Vector(); | ||||
@@ -153,10 +153,11 @@ public class XSLTProcess extends MatchingTask { | |||||
long styleSheetLastModified = 0; | long styleSheetLastModified = 0; | ||||
if (xslFile != null) { | if (xslFile != null) { | ||||
try { | try { | ||||
File file = project.resolveFile(xslFile, baseDir); | |||||
// Create a new XSL processor with the specified stylesheet | // Create a new XSL processor with the specified stylesheet | ||||
styleSheetLastModified = xslFile.lastModified(); | |||||
log( "Loading stylesheet " + xslFile, Project.MSG_INFO); | |||||
liaison.setStylesheet( xslFile.toString() ); | |||||
styleSheetLastModified = file.lastModified(); | |||||
log( "Loading stylesheet " + file, Project.MSG_INFO); | |||||
liaison.setStylesheet( file.toString() ); | |||||
for(Enumeration e = params.elements();e.hasMoreElements();) { | for(Enumeration e = params.elements();e.hasMoreElements();) { | ||||
Param p = (Param)e.nextElement(); | Param p = (Param)e.nextElement(); | ||||
liaison.addParam( p.getName(), p.getExpression() ); | liaison.addParam( p.getName(), p.getExpression() ); | ||||
@@ -213,15 +214,13 @@ public class XSLTProcess extends MatchingTask { | |||||
} //-- setDestDir | } //-- setDestDir | ||||
/** | /** | ||||
* Sets the file to use for styling relative to the base directory. | |||||
* Sets the file to use for styling relative to the base directory | |||||
* of this task. | |||||
*/ | */ | ||||
public void setStyle(File xslFile) { | |||||
public void setStyle(String xslFile) { | |||||
this.xslFile = xslFile; | this.xslFile = xslFile; | ||||
} | } | ||||
/** | |||||
* Sets the file to use for styling relative to the base directory. | |||||
*/ | |||||
public void setProcessor(String processor) throws Exception { | public void setProcessor(String processor) throws Exception { | ||||
if (processor.equals("trax")) { | if (processor.equals("trax")) { | ||||