From a1608d62d4c274d15e2ad27ddfc2c96a1762dcb8 Mon Sep 17 00:00:00 2001 From: Jan Materne Date: Tue, 18 Jul 2006 08:28:25 +0000 Subject: [PATCH] Bug 21042 "Setting XSL parameter to input filename when processed whole directory." * 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-ffa450edef68 --- docs/manual/CoreTasks/style.html | 11 ++++++----- .../apache/tools/ant/taskdefs/XSLTProcess.java | 18 ++++++++++++++---- .../apache/tools/ant/taskdefs/StyleTest.java | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/docs/manual/CoreTasks/style.html b/docs/manual/CoreTasks/style.html index 307419721..01271b367 100644 --- a/docs/manual/CoreTasks/style.html +++ b/docs/manual/CoreTasks/style.html @@ -191,8 +191,8 @@ element which is used to perform Entity and URI resolution.

filenameparameter - Specifies a xsl parameter for accessing the name - of the current processed file. If not set, the file name is not + 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. Since Ant 1.7. No @@ -200,8 +200,9 @@ element which is used to perform Entity and URI resolution.

filedirparameter 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. Since Ant 1.7. No @@ -454,7 +455,7 @@ See resources to see the concrete synt </xsl:template> </xsl:stylesheet> - +
diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java index dff574c90..315540212 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java +++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java @@ -1037,13 +1037,23 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { File inFile ) throws Exception { 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) { - liaison.addParam(fileNameParameter, inFile.getName()); + liaison.addParam(fileNameParameter, name); } if (fileDirParameter != null) { - liaison.addParam(fileDirParameter, (file.getParent()!=null) ? file.getParent() : "" ); + liaison.addParam(fileDirParameter, dir); } } diff --git a/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java b/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java index be6063565..60d9fd22a 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java @@ -168,7 +168,7 @@ public class StyleTest extends BuildFileTest { public void testFilenameAndFiledirAsParam() throws Exception { executeTarget("testFilenameAndFiledirAsParam"); 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", "filedir ='dir'"); }