Since the <property> task allows for a "resource" to be specified, and
that can be a file inside a jar-file, it should also allow for a nested
<classpath> so it can actually find the jar-file :)
As always, I snarfed most of the code to do this from other source-files,
but (as always) it should probably still be given a second look by someone
who actually knows Java. (It seems to work fine, but I can't say for sure
that it means it's necessarily completely correct.)
Patch-file is attached.
Thanks,
Diane
=====
([EMAIL PROTECTED])
__________________________________________________
Do You Yahoo!?
Yahoo! Photos - Share your holiday photos online!
http://photos.yahoo.com/
--- Property.java.orig Wed Jan 3 16:54:23 2001
+++ Property.java Wed Jan 3 16:59:18 2001
@@ -73,6 +73,8 @@
protected String value;
protected File file;
protected String resource;
+ private AntClassLoader loader;
+ private Path classpath;
protected String env;
protected Reference ref = null;
@@ -122,6 +124,25 @@
return resource;
}
+ 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 setEnvironment(String env) {
this.env = env;
}
@@ -185,29 +206,32 @@
}
}
- protected void loadResource( String name ) {
- Properties props = new Properties();
- log("Resource Loading " + name, Project.MSG_VERBOSE);
- try {
- ClassLoader cL = this.getClass().getClassLoader();
- InputStream is = null;
-
- if (cL == null) {
- is = ClassLoader.getSystemResourceAsStream(name);
- } else {
- is = cL.getResourceAsStream(name);
- }
-
- if (is != null) {
- props.load(is);
- addProperties(props);
- } else {
- log("Unable to find resource " + name, Project.MSG_WARN);
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
+ protected void loadResource( String name ) {
+ Properties props = new Properties();
+ log("Resource Loading " + name, Project.MSG_VERBOSE);
+ try {
+ ClassLoader loader = null;
+ InputStream is = null;
+
+ if (classpath != null) {
+ AntClassLoader al = new AntClassLoader(project, classpath,
+ false);
+ loader = al;
+ } else {
+ loader = this.getClass().getClassLoader();
+ }
+ is = loader.getResourceAsStream(name);
+
+ if (is != null) {
+ props.load(is);
+ addProperties(props);
+ } else {
+ log("Unable to find resource " + name, Project.MSG_WARN);
+ }
+ } catch (Exception ex) {
+ throw new BuildException(ex, location);
+ }
+ }
protected void loadEnvironment( String prefix ) {
Properties props = new Properties();