Browse Source

Support wildcards in CLASSPATH. PR 46842. Based on patch by Mike Murray.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@955896 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
3ac732f3fa
4 changed files with 39 additions and 0 deletions
  1. +8
    -0
      WHATSNEW
  2. +6
    -0
      docs/manual/using.html
  3. +16
    -0
      src/main/org/apache/tools/ant/types/Path.java
  4. +9
    -0
      src/tests/antunit/types/path-test.xml

+ 8
- 0
WHATSNEW View File

@@ -87,6 +87,14 @@ Other changes:
earlier -propertfiles or defined via the -D option).
Bugzilla Report 18732.

* <pathelement>s can now contain wildcards in order to use wildcard
CLASSPATH entries introduced with Java6.
The wildcards are not expanded or even evaluated by Ant and will be
used literally. The resulting path may be unusable as a CLASSPATH
for Java versions prior to Java6 and likely doesn't mean anything
when used in any other way than a CLASSPATH for a forked Java VM.
Bugzilla Report 46842.

Changes from Ant 1.8.0 TO Ant 1.8.1
===================================



+ 6
- 0
docs/manual/using.html View File

@@ -262,6 +262,12 @@ or semicolon-separated lists of locations. The <code>path</code>
attribute is intended to be used with predefined paths - in any other
case, multiple elements with <code>location</code> attributes should be
preferred.</p>
<p><em>Since Ant 1.8.2</em> the location attribute can also contain a
wildcard in its last path component (i.e. it can end in a
&quot;*&quot;) in order to support wildcard CLASSPATHs introduced
with Java6. Ant will not expand or evaluate the wildcards and the
resulting path may not work as anything else but a CLASSPATH - or
even as a CLASSPATH for a Java VM prior to Java6.</p>
<p>As a shortcut, the <code>&lt;classpath&gt;</code> tag
supports <code>path</code> and
<code>location</code> attributes of its own, so:</p>


+ 16
- 0
src/main/org/apache/tools/ant/types/Path.java View File

@@ -342,6 +342,12 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
}
if (f.exists()) {
setLocation(f);
} else if (f.getParentFile() != null && f.getParentFile().exists()
&& containsWildcards(f.getName())) {
setLocation(f);
log("adding " + f + " which contains wildcards and may not"
+ " do what you intend it to do depending on your OS or"
+ " version of Java", Project.MSG_VERBOSE);
} else {
log("dropping " + f + " from path as it doesn't exist",
Project.MSG_VERBOSE);
@@ -759,4 +765,14 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
}
return preserveBC.booleanValue();
}

/**
* Does the given file name contain wildcards?
* @since Ant 1.8.2
*/
private static boolean containsWildcards(String path) {
return path != null
&& (path.indexOf("*") > -1 || path.indexOf("?") > -1);
}

}

+ 9
- 0
src/tests/antunit/types/path-test.xml View File

@@ -39,4 +39,13 @@
</path>
</target>

<target name="test-wildcard"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=46842">
<path id="with-wildcard">
<pathelement location="*"/>
</path>
<au:assertEquals expected="${basedir}${file.separator}*"
actual="${toString:with-wildcard}"/>
</target>

</project>

Loading…
Cancel
Save