Return-Path: Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 2191 invoked by uid 500); 17 Sep 2000 00:07:15 -0000 Delivered-To: apmail-jakarta-ant-cvs@apache.org Received: (qmail 2188 invoked by uid 1010); 17 Sep 2000 00:07:14 -0000 Date: 17 Sep 2000 00:07:14 -0000 Message-ID: <20000917000714.2187.qmail@locus.apache.org> From: stefano@locus.apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Available.java stefano 00/09/16 17:07:14 Modified: src/main/org/apache/tools/ant/taskdefs Available.java Log: Updated this task so that you can have inside that tells the Available where to look for classes and resources. It is completely back compatible so should cause any harm to anybody. Revision Changes Path 1.11 +39 -5 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java Index: Available.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- Available.java 2000/09/14 10:49:54 1.10 +++ Available.java 2000/09/17 00:07:14 1.11 @@ -54,9 +54,10 @@ package org.apache.tools.ant.taskdefs; -import org.apache.tools.ant.*; import java.io.*; import java.util.*; +import org.apache.tools.ant.*; +import org.apache.tools.ant.types.*; /** * Will set the given property if the requested resource is available at runtime. @@ -70,8 +71,29 @@ private String classname; private File file; private String resource; + private Path classpath; + private AntClassLoader loader; private String value = "true"; + 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 setProperty(String property) { this.property = property; } @@ -93,6 +115,10 @@ } public void execute() throws BuildException { + if (classpath != null) { + this.loader = new AntClassLoader(project, classpath, false); + } + if ((classname != null) && !checkClass(classname)) return; if ((file != null) && !checkFile(file)) return; if ((resource != null) && !checkResource(resource)) return; @@ -105,15 +131,23 @@ } private boolean checkResource(String resource) { - return (ClassLoader.getSystemResource(resource) != null); + if (loader != null) { + return (loader.getResourceAsStream(resource) != null); + } else { + return (this.getClass().getResourceAsStream(resource) != null); + } } private boolean checkClass(String classname) { try { - Class.forName(classname); + if (loader != null) { + loader.loadClass(classname); + } else { + this.getClass().getClassLoader().loadClass(classname); + } return true; - } catch (Throwable t) { - log(t.toString(), Project.MSG_VERBOSE); + } catch (ClassNotFoundException e) { + log(e.toString(), Project.MSG_VERBOSE); return false; } }