ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Available.java
Date Wed, 10 Apr 2002 11:15:37 GMT
bodewig     02/04/10 04:15:37

  Modified:    src/main/org/apache/tools/ant/taskdefs Available.java
  Log:
  Make sure <available>'s isTask member gets reset if eval throws an
  exception as well.
  
  Some documentation and indentation patches.
  
  Revision  Changes    Path
  1.39      +59 -38    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.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- Available.java	8 Apr 2002 03:34:57 -0000	1.38
  +++ Available.java	10 Apr 2002 11:15:37 -0000	1.39
  @@ -65,6 +65,7 @@
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.Reference;
   import org.apache.tools.ant.util.FileUtils;
  +import org.apache.tools.ant.util.StringUtils;
   
   /**
    * Will set the given property if the requested resource is available at runtime.
  @@ -159,32 +160,38 @@
   
       public void execute() throws BuildException {
           if (property == null) {
  -            throw new BuildException("property attribute is required", location);
  +            throw new BuildException("property attribute is required", 
  +                                     location);
           }
   
           isTask = true;
  -        if (eval()) {
  -            String lSep = System.getProperty("line.separator");
  -            if (null != project.getProperty(property)) {
  -                log("DEPRECATED - <available> used to override an existing"
  -                    + " property."
  -                    + lSep
  -                    + "  Build file should not reuse the same property name"
  -                    + " for different values.");
  +        try {
  +            if (eval()) {
  +                if (null != getProject().getProperty(property)) {
  +                    log("DEPRECATED - <available> used to override an existing"
  +                        + " property."
  +                        + StringUtils.LINE_SEP
  +                        + "  Build file should not reuse the same property"
  +                        + " name for different values.");
  +                }
  +                getProject().setProperty(property, value);
               }
  -            this.project.setProperty(property, value);
  +        } finally {
  +            isTask = false;
           }
  -        isTask = false;
       }
   
       public boolean eval() throws BuildException {
           if (classname == null && file == null && resource == null) {
  -            throw new BuildException("At least one of (classname|file|resource) is required",
location);
  +            throw new BuildException("At least one of (classname|file|"
  +                                     + "resource) is required", location);
           }
   
           if (type != null){
               if (file == null){
  -                throw new BuildException("The type attribute is only valid when specifying
the file attribute.");
  +                throw new BuildException("The type attribute is only valid "
  +                                         + "when specifying the file "
  +                                         + "attribute.", location);
               }
           }
   
  @@ -201,13 +208,15 @@
           }
   
           if ((classname != null) && !checkClass(classname)) {
  -            log("Unable to load class " + classname + appendix, Project.MSG_VERBOSE);
  +            log("Unable to load class " + classname + appendix, 
  +                Project.MSG_VERBOSE);
               return false;
           }
   
           if ((file != null) && !checkFile()) {
               if (type != null) {
  -                log("Unable to find " + type + " " + file + appendix, Project.MSG_VERBOSE);
  +                log("Unable to find " + type + " " + file + appendix, 
  +                    Project.MSG_VERBOSE);
               } else {
                   log("Unable to find " + file + appendix, Project.MSG_VERBOSE);
               }
  @@ -215,12 +224,14 @@
           }
   
           if ((resource != null) && !checkResource(resource)) {
  -            log("Unable to load resource " + resource + appendix, Project.MSG_VERBOSE);
  +            log("Unable to load resource " + resource + appendix, 
  +                Project.MSG_VERBOSE);
               return false;
           }
   
           if (loader != null) {
               loader.cleanup();
  +            loader = null;
           }
   
           if (!isTask) {
  @@ -230,6 +241,22 @@
           return true;
       }
   
  +    /**
  +     * Search for file/directory either either relative to project's
  +     * basedir or in the path given as filepath.
  +     *
  +     * <p>filepath can be a list of directory and/or file names (gen'd
  +     * via <fileset>)</p>
  +     *
  +     * <p>look for:</p><ul>
  +     *   <li>full-pathname specified == path in list</li>
  +     *   <li>full-pathname specified == parent dir of path in list</li>
  +     *   <li>simple name specified   == path in list</li>
  +     *   <li>simple name specified   == path in list + name</li>
  +     *   <li>simple name specified   == parent dir + name</li>
  +     *   <li>simple name specified   == parent of parent dir + name</li>
  +     * </ul>
  +     */
       private boolean checkFile() {
           if (filepath == null) {
               return checkFile(project.resolveFile(file), file);
  @@ -237,19 +264,6 @@
               String[] paths = filepath.list();
               for(int i = 0; i < paths.length; ++i) {
                   log("Searching " + paths[i], Project.MSG_DEBUG);
  -                /*
  -                ** filepath can be a list of directory and/or
  -                ** file names (gen'd via <fileset>)
  -                **
  -                ** look for:
  -                **   full-pathname specified == path in list
  -                **   full-pathname specified == parent dir of path in list
  -                **   simple name specified   == path in list
  -                **   simple name specified   == path in list + name
  -                **   simple name specified   == parent dir + name
  -                **   simple name specified   == parent of parent dir + name
  -                **
  -                */
                   File path = new File(paths[i]);
   
                   // **   full-pathname specified == path in list
  @@ -318,6 +332,9 @@
           return false;
       }
   
  +    /**
  +     * Check if a given file exists and matches the required type.
  +     */
       private boolean checkFile(File f, String text) {
           if (type != null) {
               if (type.isDir()) {
  @@ -338,6 +355,9 @@
           return f.exists();
       }
   
  +    /**
  +     * Check if a given resource can be loaded.
  +     */
       private boolean checkResource(String resource) {
           if (loader != null) {
               return (loader.getResourceAsStream(resource) != null);
  @@ -352,25 +372,26 @@
           }
       }
   
  +    /**
  +     * Check if a given class can be loaded.
  +     */
       private boolean checkClass(String classname) {
           try {
               Class requiredClass = null;
               if( ignoreSystemclasses ) {
                   loader = new AntClassLoader(null,getProject(),classpath,false);
  -            if (loader != null) {
  +                if (loader != null) {
                       try {
                           loader.findClass(classname);
  -                    }
  -                    catch( SecurityException se ) {
  -            // class found but restricted name; this is actually
  -            // the case we're looking for, so catch the exception
  -            // and return
  +                    } catch( SecurityException se ) {
  +                        // class found but restricted name; this is actually
  +                        // the case we're looking for, so catch the exception
  +                        // and return
                           return true;
  -            }
  +                    }
                   }
                   return false;
  -            }
  -            else if (loader != null) {
  +            } else if (loader != null) {
                   requiredClass = loader.loadClass(classname);
               } else {
                   ClassLoader l = this.getClass().getClassLoader();
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message