You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by pe...@apache.org on 2003/07/04 10:48:20 UTC

cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Definer.java

peterreilly    2003/07/04 01:48:19

  Modified:    src/main/org/apache/tools/ant/taskdefs Definer.java
  Log:
  clean up to pass checkstyle
  
  Revision  Changes    Path
  1.32      +131 -42   ant/src/main/org/apache/tools/ant/taskdefs/Definer.java
  
  Index: Definer.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Definer.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- Definer.java	26 Jun 2003 08:54:29 -0000	1.31
  +++ Definer.java	4 Jul 2003 08:48:19 -0000	1.32
  @@ -55,21 +55,17 @@
   package org.apache.tools.ant.taskdefs;
   
   import java.io.File;
  -import java.io.FileInputStream;
   import java.io.IOException;
   import java.io.InputStream;
   import java.net.URL;
   import java.util.Enumeration;
  -import java.util.Locale;
   import java.util.Properties;
   
   import org.apache.tools.ant.AntTypeDefinition;
   import org.apache.tools.ant.AntClassLoader;
   import org.apache.tools.ant.ComponentHelper;
   import org.apache.tools.ant.BuildException;
  -import org.apache.tools.ant.Location;
   import org.apache.tools.ant.Project;
  -import org.apache.tools.ant.ProjectHelper;
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.Reference;
  @@ -91,34 +87,45 @@
       private File file;
       private String resource;
       private ClasspathUtils.Delegate cpDelegate;
  -    
  -    private   int    format = Format.PROPERTIES;
  +
       private   boolean definerSet = false;
       private   ClassLoader internalClassLoader;
       private   int         onError = OnError.FAIL;
       private   String      adapter;
       private   String      adaptTo;
  -    
  +
       private   Class       adapterClass;
       private   Class       adaptToClass;
  -    
  +
  +    /**
  +     * Enumerated type for onError attribute
  +     *
  +     * @see EnumeratedAttribute
  +     */
       public static class OnError extends EnumeratedAttribute {
  +        /** Enumerated values */
           public static final int  FAIL = 0, REPORT = 1, IGNORE = 2;
  +        /**
  +         * Constructor
  +         */
           public OnError() {
               super();
           }
  +
  +        /**
  +         * Constructor using a string.
  +         * @param value the value of the attribute
  +         */
           public OnError(String value) {
               setValue(value);
           }
  -        public String[] getValues() {
  -            return new String[] {"fail", "report", "ignore"};
  -        }
  -    }
   
  -    public static class Format extends EnumeratedAttribute {
  -        public static final int  PROPERTIES=0, XML=1;
  +        /**
  +         * get the values
  +         * @return an array of the allowed values for this attribute.
  +         */
           public String[] getValues() {
  -            return new String[] {"properties", "xml"};
  +            return new String[] {"fail", "report", "ignore"};
           }
       }
   
  @@ -137,13 +144,8 @@
       }
   
       /**
  -     * Sets the format of the file or resource
  -     */
  -    public void setFormat(Format format) {
  -        this.format = format.getIndex();
  -    }
  -
  -    /**
  +     * @param reverseLoader if true a delegated loader will take precedence over
  +     *                      the parent
        * @deprecated stop using this attribute
        * @ant.attribute ignore="true"
        */
  @@ -153,30 +155,53 @@
               Project.MSG_WARN);
       }
   
  +    /**
  +     * @return the name for this definition
  +     */
       public String getName() {
           return name;
       }
   
  +    /**
  +     * @return the class path path for this definition
  +     */
       public Path getClasspath() {
           return cpDelegate.getClasspath();
       }
   
  +    /**
  +     * @return the file containing definitions
  +     */
       public File getFile() {
           return file;
       }
   
  +    /**
  +     * @return the resource containing definitions
  +     */
       public String getResource() {
           return resource;
       }
   
  +    /**
  +     * @return the reverse loader attribute of the classpath delegate.
  +     */
       public boolean isReverseLoader() {
           return cpDelegate.isReverseLoader();
       }
   
  +    /**
  +     * Returns the loader id of the class path Delegate.
  +     * @return the loader id
  +     */
       public String getLoaderId() {
           return cpDelegate.getClassLoadId();
       }
   
  +    /**
  +     * Returns the class path id of the class path delegate.
  +     * @return the class path id
  +     */
       public String getClasspathId() {
           return cpDelegate.getClassLoadId();
       }
  @@ -191,7 +216,9 @@
       }
   
       /**
  -     * Create the classpath to be used when searching for component being defined
  +     * Create the classpath to be used when searching for component being
  +     * defined
  +     * @return the classpath of the this definition
        */
       public Path createClasspath() {
           return this.cpDelegate.createClasspath();
  @@ -200,6 +227,7 @@
       /**
        * reference to a classpath to use when loading the files.
        * To actually share the same loader, set loaderref as well
  +     * @param r the reference to the classpath
        */
       public void setClasspathRef(Reference r) {
           this.cpDelegate.setClasspathref(r);
  @@ -214,6 +242,7 @@
        * so they can be used together. It eliminate the need to
        * put them in the CLASSPATH.
        *
  +     * @param r the reference to locate the loader.
        * @since Ant 1.5
        */
       public void setLoaderRef(Reference r) {
  @@ -221,6 +250,11 @@
       }
   
   
  +    /**
  +     * Run the definition.
  +     *
  +     * @exception BuildException if an error occurs
  +     */
       public void execute() throws BuildException {
           ClassLoader al = createLoader();
   
  @@ -229,7 +263,7 @@
                   "name, file or resource attribute of "
                   + getTaskName() + " is undefined", getLocation());
           }
  -        
  +
           if (name != null) {
               if (classname == null) {
                   throw new BuildException(
  @@ -260,19 +294,19 @@
       }
   
       private URL fileToURL() {
  -        if (! file.exists()) {
  +        if (!(file.exists())) {
               log("File " + file + " does not exist", Project.MSG_WARN);
               return null;
           }
  -        if (! file.isFile()) {
  +        if (!(file.isFile())) {
               log("File " + file + " is not a file", Project.MSG_WARN);
               return null;
           }
           try {
               return file.toURL();
           } catch (Exception ex) {
  -            log("File " + file + " cannot use as URL: " +
  -                ex.toString(), Project.MSG_WARN);
  +            log("File " + file + " cannot use as URL: "
  +                + ex.toString(), Project.MSG_WARN);
               return null;
           }
       }
  @@ -288,7 +322,13 @@
           }
           return ret;
       }
  -    
  +
  +    /**
  +     * Load type definitions as properties from a url.
  +     *
  +     * @param al the classloader to use
  +     * @param url the url to get the definitions from
  +     */
       protected void loadProperties(ClassLoader al, URL url) {
           InputStream is = null;
           try {
  @@ -312,14 +352,15 @@
               if (is != null) {
                   try {
                       is.close();
  -                } catch (IOException e) {}
  +                } catch (IOException e) {
  +                }
               }
           }
       }
  -    
   
       /**
        * create a classloader for this definition
  +     * @return the classloader from the cpDelegate
        */
       protected ClassLoader createLoader() {
           if (internalClassLoader != null) {
  @@ -329,7 +370,7 @@
           // need to load Task via system classloader or the new
           // task we want to define will never be a Task but always
           // be wrapped into a TaskAdapter.
  -        ((AntClassLoader)al).addSystemPackageRoot("org.apache.tools.ant");
  +        ((AntClassLoader) al).addSystemPackageRoot("org.apache.tools.ant");
   
           return al;
       }
  @@ -337,6 +378,7 @@
       /**
        * Name of the property file  to load
        * ant name/classname pairs from.
  +     * @param file the file
        */
       public void setFile(File file) {
           if (definerSet) {
  @@ -349,6 +391,7 @@
       /**
        * Name of the property resource to load
        * ant name/classname pairs from.
  +     * @param res the resource to use
        */
       public void setResource(String res) {
           if (definerSet) {
  @@ -359,8 +402,8 @@
       }
   
       /**
  -     * Name of the property resource to load
  -     * ant name/classname pairs from.
  +     * Name of the definition
  +     * @param name the name of the definition
        */
       public void setName(String name) {
           if (definerSet) {
  @@ -373,6 +416,7 @@
       /**
        * Returns the classname of the object we are defining.
        * May be <code>null</code>.
  +     * @return the class name
        */
       public String getClassname() {
           return classname;
  @@ -382,27 +426,65 @@
        * The full class name of the object being defined.
        * Required, unless file or resource have
        * been specified.
  +     * @param classname the name of the class
        */
  -    public void setClassname(String v) {
  -        classname = v;
  +    public void setClassname(String classname) {
  +        this.classname = classname;
       }
   
  +    /**
  +     * Set the class name of the adapter class.
  +     * An adapter class is used to proxy the
  +     * definition class. It is used if the
  +     * definition class is not assignable to
  +     * the adaptto class, or if the adaptto
  +     * class is not present.
  +     *
  +     * @param adapter the name of the adapter class
  +     */
  +
       public void setAdapter(String adapter) {
           this.adapter = adapter;
       }
   
  +    /**
  +     * Set the adapter class.
  +     *
  +     * @param adapterClass the class to use to adapt the definition class
  +     */
       protected void setAdapterClass(Class adapterClass) {
           this.adapterClass = adapterClass;
       }
  -    
  +
  +    /**
  +     * Set the classname of the class that the definition
  +     * must be compatible with, either directly or
  +     * by use of the adapeter class.
  +     *
  +     * @param adaptTo the name of the adaptto class
  +     */
       public void setAdaptTo(String adaptTo) {
           this.adaptTo = adaptTo;
       }
   
  +    /**
  +     * Set the class for adaptToClass, to be
  +     * used by derived classes, used instead of
  +     * the adaptTo attribute.
  +     *
  +     * @param adaptToClass the class for adapto.
  +     */
       protected void setAdaptToClass(Class adaptToClass) {
           this.adaptToClass = adaptToClass;
       }
   
  +
  +    /**
  +     * Set the class loader, overrides the cpDelagate
  +     * classloader.
  +     *
  +     * @param classLoader a <code>ClassLoader</code> value
  +     */
       protected void setInternalClassLoader(ClassLoader classLoader) {
           this.internalClassLoader = classLoader;
       }
  @@ -416,9 +498,16 @@
           super.init();
       }
   
  +    /**
  +     * Add a definition using the attributes of Definer
  +     *
  +     * @param al the ClassLoader to use
  +     * @param name the name of the definition
  +     * @param classname the classname of the definition
  +     * @exception BuildException if an error occurs
  +     */
       protected void addDefinition(ClassLoader al, String name, String classname)
  -        throws BuildException
  -    {
  +        throws BuildException {
           Class cl = null;
           try {
               try {
  @@ -426,7 +515,7 @@
                       cl = al.loadClass(classname);
                       AntClassLoader.initializeClass(cl);
                   }
  -                
  +
                   if (adapter != null) {
                       adapterClass = al.loadClass(adapter);
                       AntClassLoader.initializeClass(adapterClass);
  @@ -476,7 +565,7 @@
   
       private void tooManyDefinitions() {
           throw new BuildException(
  -            "Only one of the attributes name,file,resource" +
  -            " can be set", getLocation());
  +            "Only one of the attributes name,file,resource"
  +            + " can be set", getLocation());
       }
   }
  
  
  

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


Re: cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Definer.java

Posted by peter reilly <pe...@corvil.com>.
Yep,
However it is not used at the moment, and it
got placed in by accident in the first place.
Peter

On Fri, 2003-07-04 at 10:01, Stefan Bodewig wrote:
> This also remove the format attribute, won't we need that for XML
> style task definitions to come?
> 
> Stefan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
> 
> 


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


Re: cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Definer.java

Posted by Stefan Bodewig <bo...@apache.org>.
This also remove the format attribute, won't we need that for XML
style task definitions to come?

Stefan

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