* changed from File.getParent() to String.substring() to avoid changing between / and \ * "dir" defaults to '.' instead of empty string, so dir+'/'+name would not result in an absolute path git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@423009 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -191,8 +191,8 @@ element which is used to perform Entity and URI resolution.</p> | |||||
| </tr> | </tr> | ||||
| <tr> | <tr> | ||||
| <td valign="top">filenameparameter</td> | <td valign="top">filenameparameter</td> | ||||
| <td valign="top">Specifies a xsl parameter for accessing the name | |||||
| of the current processed file. If not set, the file name is not | |||||
| <td valign="top">Specifies a xsl parameter for accessing the name | |||||
| of the current processed file. If not set, the file name is not | |||||
| passed to the transformation. | passed to the transformation. | ||||
| <em>Since Ant 1.7</em>.</td> | <em>Since Ant 1.7</em>.</td> | ||||
| <td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
| @@ -200,8 +200,9 @@ element which is used to perform Entity and URI resolution.</p> | |||||
| <tr> | <tr> | ||||
| <td valign="top">filedirparameter</td> | <td valign="top">filedirparameter</td> | ||||
| <td valign="top">Specifies a xsl parameter for accessing the directory | <td valign="top">Specifies a xsl parameter for accessing the directory | ||||
| of the current processed file. If not set, the directory is not | |||||
| passed to the transformation. | |||||
| of the current processed file. For files in the current directory a | |||||
| value of '.' will be passed to the transformation. | |||||
| If not set, the directory is not passed to the transformation. | |||||
| <em>Since Ant 1.7</em>.</td> | <em>Since Ant 1.7</em>.</td> | ||||
| <td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
| </tr> | </tr> | ||||
| @@ -454,7 +455,7 @@ See <a href="../CoreTypes/resources.html">resources</a> to see the concrete synt | |||||
| </xsl:template> | </xsl:template> | ||||
| </xsl:stylesheet> | </xsl:stylesheet> | ||||
| </pre> | |||||
| </pre> | |||||
| </blockquote> | </blockquote> | ||||
| <hr> | <hr> | ||||
| @@ -1037,13 +1037,23 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| File inFile | File inFile | ||||
| ) throws Exception { | ) throws Exception { | ||||
| String fileName = FileUtils.getRelativePath(baseDir, inFile); | String fileName = FileUtils.getRelativePath(baseDir, inFile); | ||||
| File file = new File(fileName); | |||||
| String name; | |||||
| String dir; | |||||
| int lastDirSep = fileName.lastIndexOf("/"); | |||||
| if (lastDirSep > -1) { | |||||
| name = fileName.substring(lastDirSep + 1); | |||||
| dir = fileName.substring(0, lastDirSep); | |||||
| } else { | |||||
| name = fileName; | |||||
| dir = "."; // so a dir+"/"+name would not result in an absolute path | |||||
| } | |||||
| if (fileNameParameter != null) { | if (fileNameParameter != null) { | ||||
| liaison.addParam(fileNameParameter, inFile.getName()); | |||||
| liaison.addParam(fileNameParameter, name); | |||||
| } | } | ||||
| if (fileDirParameter != null) { | if (fileDirParameter != null) { | ||||
| liaison.addParam(fileDirParameter, (file.getParent()!=null) ? file.getParent() : "" ); | |||||
| liaison.addParam(fileDirParameter, dir); | |||||
| } | } | ||||
| } | } | ||||
| @@ -168,7 +168,7 @@ public class StyleTest extends BuildFileTest { | |||||
| public void testFilenameAndFiledirAsParam() throws Exception { | public void testFilenameAndFiledirAsParam() throws Exception { | ||||
| executeTarget("testFilenameAndFiledirAsParam"); | executeTarget("testFilenameAndFiledirAsParam"); | ||||
| assertFileContains("out/out/one.txt", "filename='one.xml'"); | assertFileContains("out/out/one.txt", "filename='one.xml'"); | ||||
| assertFileContains("out/out/one.txt", "filedir =''"); | |||||
| assertFileContains("out/out/one.txt", "filedir ='.'"); | |||||
| assertFileContains("out/out/dir/four.txt", "filename='four.xml'"); | assertFileContains("out/out/dir/four.txt", "filename='four.xml'"); | ||||
| assertFileContains("out/out/dir/four.txt", "filedir ='dir'"); | assertFileContains("out/out/dir/four.txt", "filedir ='dir'"); | ||||
| } | } | ||||