From d42256bf5456cb6a699edf64dd6b578d9d5074f0 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 8 Jan 2001 12:42:47 +0000 Subject: [PATCH] Add classpath attributes and elements to to specify a classpath to load resources from. Submitted by: Diane Holt git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268414 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 ++ docs/index.html | 17 +++++++++++ .../apache/tools/ant/taskdefs/Property.java | 29 ++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/WHATSNEW b/WHATSNEW index ae2f5754f..cdba3e1f6 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -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 + to make the resource attribute more powerful. + Fixed bugs: ----------- diff --git a/docs/index.html b/docs/index.html index 1bea0755e..8dd13ffd6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3954,7 +3954,24 @@ This also holds for properties loaded from a property file.

current platforms conventions). Otherwise it is taken as a path relative to the project's basedir and expanded. + + classpath + the classpath to use when looking up a resource. + No + + + classpathref + the classpath to use when looking up a resource, + given as reference to a PATH defined + elsewhere.. + No + +

Parameters specified as nested elements

+

classpath

+

Property's classpath attribute is a PATH like structure and can also be set via a nested +classpath element.

Examples

  <property name="foo.dist" value="dist" />

sets the property foo.dist to the value "dist".

diff --git a/src/main/org/apache/tools/ant/taskdefs/Property.java b/src/main/org/apache/tools/ant/taskdefs/Property.java index f74f5d1dc..f6148dc6a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Property.java +++ b/src/main/org/apache/tools/ant/taskdefs/Property.java @@ -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 {