Browse Source

Add classpath attributes and elements to <property> to specify a

classpath to load resources from.

Submitted by:	Diane Holt <holtdl@yahoo.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268414 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
d42256bf54
3 changed files with 48 additions and 1 deletions
  1. +3
    -0
      WHATSNEW
  2. +17
    -0
      docs/index.html
  3. +28
    -1
      src/main/org/apache/tools/ant/taskdefs/Property.java

+ 3
- 0
WHATSNEW View File

@@ -54,6 +54,9 @@ Other changes:
* Added nested format elements to the tstamp task allowing additional time
formats to be defined for arbitrary properties.

* Added classpath attribute and nested classpath element to <property>
to make the resource attribute more powerful.

Fixed bugs:
-----------



+ 17
- 0
docs/index.html View File

@@ -3954,7 +3954,24 @@ This also holds for properties loaded from a property file.</p>
current platforms conventions). Otherwise it is taken as a path
relative to the project's basedir and expanded.</td>
</tr>
<tr>
<td valign="top">classpath</td>
<td valign="top">the classpath to use when looking up a resource.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">classpathref</td>
<td valign="top">the classpath to use when looking up a resource,
given as <a href="#references">reference</a> to a PATH defined
elsewhere..</td>
<td align="center" valign="top">No</td>
</tr>
</table>
<h3>Parameters specified as nested elements</h3>
<h4>classpath</h4>
<p><code>Property</code>'s <em>classpath</em> attribute is a <a
href="#path">PATH like structure</a> and can also be set via a nested
<em>classpath</em> element.</p>
<h3>Examples</h3>
<pre> &lt;property name=&quot;foo.dist&quot; value=&quot;dist&quot; /&gt;</pre>
<p>sets the property <code>foo.dist</code> to the value &quot;dist&quot;.</p>


+ 28
- 1
src/main/org/apache/tools/ant/taskdefs/Property.java View File

@@ -55,6 +55,7 @@
package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.*;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import java.io.*;
import java.util.*;
@@ -73,6 +74,7 @@ public class Property extends Task {
protected String value;
protected File file;
protected String resource;
protected Path classpath;
protected String env;
protected Reference ref = null;

@@ -130,6 +132,25 @@ public class Property extends Task {
return env;
}

public void setClasspath(Path classpath) {
if (this.classpath == null) {
this.classpath = classpath;
} else {
this.classpath.append(classpath);
}
}
public Path createClasspath() {
if (this.classpath == null) {
this.classpath = new Path(project);
}
return this.classpath.createPath();
}
public void setClasspathRef(Reference r) {
createClasspath().setRefid(r);
}

public void setUserProperty(boolean userProperty) {
this.userProperty = userProperty;
}
@@ -189,9 +210,15 @@ public class Property extends Task {
Properties props = new Properties();
log("Resource Loading " + name, Project.MSG_VERBOSE);
try {
ClassLoader cL = this.getClass().getClassLoader();
ClassLoader cL = null;
InputStream is = null;

if (classpath != null) {
cL = new AntClassLoader(project, classpath, false);
} else {
cL = this.getClass().getClassLoader();
}

if (cL == null) {
is = ClassLoader.getSystemResourceAsStream(name);
} else {


Loading…
Cancel
Save