ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/types Mapper.java
Date Thu, 30 Nov 2000 14:20:23 GMT
bodewig     00/11/30 06:20:21

  Modified:    src/main/org/apache/tools/ant/types Mapper.java
  Log:
  Allow the user to specify a FileNameMapper by class name - and set the
  classpath to load it from.
  
  Revision  Changes    Path
  1.3       +72 -4     jakarta-ant/src/main/org/apache/tools/ant/types/Mapper.java
  
  Index: Mapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/Mapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Mapper.java	2000/11/28 15:10:32	1.2
  +++ Mapper.java	2000/11/30 14:20:19	1.3
  @@ -23,7 +23,7 @@
    *    Alternately, this acknowlegement may appear in the software itself,
    *    if and wherever such third-party acknowlegements normally appear.
    *
  - * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  + * 4. The names "The Jakarta Project", "Ant", and "Apache Software
    *    Foundation" must not be used to endorse or promote products derived
    *    from this software without prior written permission. For written
    *    permission, please contact apache@apache.org.
  @@ -54,6 +54,7 @@
   
   package org.apache.tools.ant.types;
   
  +import org.apache.tools.ant.AntClassLoader;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.util.*;
  @@ -86,6 +87,58 @@
           this.type = type;
       }
   
  +    protected String classname = null;
  +
  +    /**
  +     * Set the class name of the FileNameMapper to use.
  +     */
  +    public void setClassname(String classname) {
  +        if (isReference()) {
  +            throw tooManyAttributes();
  +        }
  +        this.classname = classname;
  +    }
  +
  +    protected Path classpath = null;
  +
  +    /**
  +     * Set the classpath to load the FileNameMapper through (attribute).
  +     */
  +    public void setClasspath(Path classpath) {
  +        if (isReference()) {
  +            throw tooManyAttributes();
  +        }
  +        if (this.classpath == null) {
  +            this.classpath = classpath;
  +        } else {
  +            this.classpath.append(classpath);
  +        }
  +    }
  +
  +    /**
  +     * Set the classpath to load the FileNameMapper through (nested element).
  +     */
  +    public Path createClasspath() {
  +        if (isReference()) {
  +            throw noChildrenAllowed();
  +        }
  +        if (this.classpath == null) {
  +            this.classpath = new Path(p);
  +        }
  +        return this.classpath.createPath();
  +    }
  +
  +    /**
  +     * Set the classpath to load the FileNameMapper through via
  +     * reference (attribute).
  +     */
  +    public void setClasspathRef(Reference r) {
  +        if (isReference()) {
  +            throw tooManyAttributes();
  +        }
  +        createClasspath().setRefid(r);
  +    }
  +
       protected String from = null;
   
       /**
  @@ -131,12 +184,27 @@
               return getRef().getImplementation();
           }
           
  -        if (type == null) {
  -            throw new BuildException("type attribute is required");
  +        if (type == null && classname == null) {
  +            throw new BuildException("one of the attributes type or classname is required");
  +        }
  +
  +        if (type != null && classname != null) {
  +            throw new BuildException("must not specify both type and classname attribute");
           }
   
           try {
  -            Class c = Class.forName(type.getImplementation());
  +            if (type != null) {
  +                classname = type.getImplementation();
  +            }
  +
  +            Class c = null;
  +            if (classpath == null) {
  +                c = Class.forName(classname);
  +            } else {
  +                AntClassLoader al = new AntClassLoader(p, classpath);
  +                c = al.loadClass(classname);
  +            }
  +            
               FileNameMapper m = (FileNameMapper) c.newInstance();
               m.setFrom(from);
               m.setTo(to);
  
  
  

Mime
View raw message