ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Available.java
Date Sun, 17 Sep 2000 00:07:14 GMT
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 <classpath> 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;
           }
       }
  
  
  

Mime
View raw message