peterreilly    2003/07/04 02:35:31

  Modified:    src/main/org/apache/tools/ant AntTypeDefinition.java
                        ComponentHelper.java
               src/main/org/apache/tools/ant/taskdefs Definer.java
  Log:
  Remove cloning of AntTypeDefinition when creating a sub-project
  PR: 21296
  
  Revision  Changes    Path
  1.3       +22 -27    ant/src/main/org/apache/tools/ant/AntTypeDefinition.java
  
  Index: AntTypeDefinition.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/AntTypeDefinition.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AntTypeDefinition.java    4 Jul 2003 08:15:43 -0000       1.2
  +++ AntTypeDefinition.java    4 Jul 2003 09:35:31 -0000       1.3
  @@ -65,7 +65,6 @@
    * @author Peter Reilly
    */
   public class AntTypeDefinition {
  -    private Project     project;
       private String      name;
       private Class       clazz;
       private Class       adapterClass;
  @@ -74,13 +73,11 @@
       private ClassLoader classLoader;
   
       /**
  -     * Clone this definiton and changed the cloned definitions' project.
  -     * @param p   the project the cloned definition lives in
  +     * Clone this definition and changed the cloned definitions' project.
        * @return    the cloned definition
        */
  -    public AntTypeDefinition copy(Project p) {
  +    public AntTypeDefinition copy() {
           AntTypeDefinition copy = new AntTypeDefinition();
  -        copy.project = p;
           copy.name = name;
           copy.clazz = clazz;
           copy.adapterClass = adapterClass;
  @@ -91,14 +88,6 @@
       }
   
       /**
  -     * set the project on the definition
  -     * @param project the project this definition belongs in
  -     */
  -    public void setProject(Project project) {
  -        this.project = project;
  -    }
  -
  -    /**
        * set the definition's name
        * @param name the name of the definition
        */
  @@ -190,11 +179,12 @@
        * (adapted class) if there is an adpater
        * class and the definition class is not
        * assignable from the assignable class.
  +     * @param project the current project
        * @return the exposed class
        */
  -    public Class getExposedClass() {
  +    public Class getExposedClass(Project project) {
           if (adaptToClass != null) {
  -            Class z = getTypeClass();
  +            Class z = getTypeClass(project);
               if (z == null) {
                   return null;
               }
  @@ -205,14 +195,15 @@
           if (adapterClass != null) {
               return adapterClass;
           }
  -        return getTypeClass();
  +        return getTypeClass(project);
       }
   
       /**
        * get the definition class
  +     * @param project the current project
        * @return the type of the definition
        */
  -    public Class getTypeClass() {
  +    public Class getTypeClass(Project project) {
           if (clazz != null) {
               return clazz;
           }
  @@ -237,23 +228,24 @@
       /**
        * create an instance of the definition.
        * The instance may be wrapped in a proxy class.
  +     * @param project the current project
        * @return the created object
        */
  -    public Object create() {
  -        return  icreate();
  +    public Object create(Project project) {
  +        return  icreate(project);
       }
   
       /**
        * Create a component object based on
        * its definition
        */
  -    private Object icreate() {
  -        Class c = getTypeClass();
  +    private Object icreate(Project project) {
  +        Class c = getTypeClass(project);
           if (c == null) {
               return null;
           }
   
  -        Object o = createAndSet(c);
  +        Object o = createAndSet(project, c);
           if (o == null || adapterClass == null) {
               return o;
           }
  @@ -264,7 +256,8 @@
               }
           }
   
  -        TypeAdapter adapterObject = (TypeAdapter) createAndSet(adapterClass);
  +        TypeAdapter adapterObject = (TypeAdapter) createAndSet(
  +            project, adapterClass);
           if (adapterObject == null) {
               return null;
           }
  @@ -281,10 +274,11 @@
        *   <li>if the type is assignable from adapto</li>
        *   <li>if the type can be used with the adapter class</li>
        * </dl>
  +     * @param project the current project
        */
  -    public void checkClass() {
  +    public void checkClass(Project project) {
           if (clazz == null) {
  -            clazz = getTypeClass();
  +            clazz = getTypeClass(project);
               if (clazz == null) {
                   throw new BuildException(
                       "Unable to create class for " + getName());
  @@ -298,7 +292,8 @@
                   needToCheck = false;
               }
               if (needToCheck) {
  -                TypeAdapter adapter = (TypeAdapter) 
createAndSet(adapterClass);
  +                TypeAdapter adapter = (TypeAdapter) createAndSet(
  +                    project, adapterClass);
                   if (adapter == null) {
                       throw new BuildException("Unable to create adapter 
object");
                   }
  @@ -311,7 +306,7 @@
        * get the constructor of the defintion
        * and invoke it.
        */
  -    private Object createAndSet(Class c) {
  +    private Object createAndSet(Project project, Class c) {
           try {
               java.lang.reflect.Constructor ctor = null;
               boolean noArg = false;
  
  
  
  1.15      +8 -12     ant/src/main/org/apache/tools/ant/ComponentHelper.java
  
  Index: ComponentHelper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/ComponentHelper.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ComponentHelper.java      27 Jun 2003 18:16:59 -0000      1.14
  +++ ComponentHelper.java      4 Jul 2003 09:35:31 -0000       1.15
  @@ -154,7 +154,6 @@
           AntTypeTable typeTable = helper.antTypeTable;
           for (Iterator i = typeTable.values().iterator(); i.hasNext();) {
               AntTypeDefinition def = (AntTypeDefinition) i.next();
  -            def = def.copy(project);
               antTypeTable.put(def.getName(), def);
           }
       }
  @@ -256,7 +255,6 @@
       public void addTaskDefinition(String taskName, Class taskClass) {
           checkTaskClass(taskClass);
           AntTypeDefinition def = new AntTypeDefinition();
  -        def.setProject(project);
           def.setName(taskName);
           def.setClassLoader(taskClass.getClassLoader());
           def.setClass(taskClass);
  @@ -386,7 +384,6 @@
        */
       public void addDataTypeDefinition(String typeName, Class typeClass) {
           AntTypeDefinition def = new AntTypeDefinition();
  -        def.setProject(project);
           def.setName(typeName);
           def.setClass(typeClass);
           updateDataTypeDefinition(def);
  @@ -567,7 +564,7 @@
           Class elementClass = element.getClass();
           for (Iterator i = antTypeTable.values().iterator(); i.hasNext();) {
               AntTypeDefinition def = (AntTypeDefinition) i.next();
  -            if (elementClass == def.getExposedClass()) {
  +            if (elementClass == def.getExposedClass(project)) {
                   return "The <" + def.getName() + "> type"; 
               }
           }
  @@ -578,10 +575,11 @@
       /** return true if the two definitions are the same */
       private boolean sameDefinition(
           AntTypeDefinition def, AntTypeDefinition old) {
  -        if (! (old.getTypeClass().equals(def.getTypeClass()))) {
  +        if (! (old.getTypeClass(project).equals(def.getTypeClass(project)))) 
{
               return false;
           }
  -        if (! (old.getExposedClass().equals(def.getExposedClass()))) {
  +        if (! (old.getExposedClass(project).equals(
  +                   def.getExposedClass(project)))) {
               return false;
           }
           return true;
  @@ -649,7 +647,6 @@
                   String name = (String) enum.nextElement();
                   String className = props.getProperty(name);
                   AntTypeDefinition def = new AntTypeDefinition();
  -                def.setProject(project);
                   def.setName(name);
                   def.setClassName(className);
                   def.setClassLoader(classLoader);
  @@ -692,7 +689,6 @@
                   String name = (String) enum.nextElement();
                   String className = props.getProperty(name);
                   AntTypeDefinition def = new AntTypeDefinition();
  -                def.setProject(project);
                   def.setName(name);
                   def.setClassName(className);
                   def.setClassLoader(classLoader);
  @@ -733,7 +729,7 @@
               if (def == null) {
                   return null;
               }
  -            return def.create();
  +            return def.create(project);
           }
               
           public Class getTypeClass(String name) {
  @@ -741,7 +737,7 @@
               if (def == null) {
                   return null;
               }
  -            return def.getTypeClass();
  +            return def.getTypeClass(project);
           }
   
           public Class getExposedClass(String name) {
  @@ -749,13 +745,13 @@
               if (def == null) {
                   return null;
               }
  -            return def.getExposedClass();
  +            return def.getExposedClass(project);
           }
   
           public boolean contains(Object clazz) {
               for (Iterator i = values().iterator(); i.hasNext();) {
                   AntTypeDefinition def = (AntTypeDefinition) i.next();
  -                Class c = def.getExposedClass();
  +                Class c = def.getExposedClass(project);
                   if (c == clazz)
                       return true;
               }
  
  
  
  1.33      +1 -2      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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Definer.java      4 Jul 2003 08:48:19 -0000       1.32
  +++ Definer.java      4 Jul 2003 09:35:31 -0000       1.33
  @@ -528,14 +528,13 @@
   
                   AntTypeDefinition def = new AntTypeDefinition();
                   def.setName(name);
  -                def.setProject(getProject());
                   def.setClassName(classname);
                   def.setClass(cl);
                   def.setAdapterClass(adapterClass);
                   def.setAdaptToClass(adaptToClass);
                   def.setClassLoader(al);
                   if (cl != null) {
  -                    def.checkClass();
  +                    def.checkClass(project);
                   }
                   ComponentHelper.getComponentHelper(getProject())
                       .addDataTypeDefinition(def);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to