Browse Source

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
master
Jan Materne 19 years ago
parent
commit
a1608d62d4
3 changed files with 21 additions and 10 deletions
  1. +6
    -5
      docs/manual/CoreTasks/style.html
  2. +14
    -4
      src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
  3. +1
    -1
      src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java

+ 6
- 5
docs/manual/CoreTasks/style.html View File

@@ -191,8 +191,8 @@ element which is used to perform Entity and URI resolution.</p>
</tr>
<tr>
<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.
<em>Since Ant 1.7</em>.</td>
<td valign="top" align="center">No</td>
@@ -200,8 +200,9 @@ element which is used to perform Entity and URI resolution.</p>
<tr>
<td valign="top">filedirparameter</td>
<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>
<td valign="top" align="center">No</td>
</tr>
@@ -454,7 +455,7 @@ See <a href="../CoreTypes/resources.html">resources</a> to see the concrete synt
&lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;
</pre>
</pre>

</blockquote>
<hr>


+ 14
- 4
src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java View File

@@ -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);
}
}



+ 1
- 1
src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java View File

@@ -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'");
}


Loading…
Cancel
Save