ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umag...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/types/selectors ExtendSelector.java
Date Mon, 14 Apr 2003 17:21:28 GMT
umagesh     2003/04/14 10:21:27

  Modified:    src/main/org/apache/tools/ant ComponentHelper.java
                        IntrospectionHelper.java Main.java Project.java
               src/main/org/apache/tools/ant/filters/util
                        ChainReaderHelper.java
               src/main/org/apache/tools/ant/types Mapper.java
               src/main/org/apache/tools/ant/types/selectors
                        ExtendSelector.java
  Log:
  Call setproject for all created objects.
  
  PR: 18312
  
  Submitted by: peter.reilly@corvil.com (peter reilly)
  
  Revision  Changes    Path
  1.4       +3 -4      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ComponentHelper.java	10 Feb 2003 14:13:30 -0000	1.3
  +++ ComponentHelper.java	14 Apr 2003 17:21:25 -0000	1.4
  @@ -407,6 +407,7 @@
   
           try {
               Object o = c.newInstance();
  +            Project.setProjectOnObject(project, o);
               Task task = null;
               if (o instanceof Task) {
                   task = (Task) o;
  @@ -415,9 +416,9 @@
                   // and an Adapter
                   TaskAdapter taskA = new TaskAdapter();
                   taskA.setProxy(o);
  +                Project.setProjectOnObject(project, taskA);
                   task = taskA;
               }
  -            task.setProject(project);
               task.setTaskType(taskType);
   
               // set default value, can be changed by the user
  @@ -520,9 +521,7 @@
               } else {
                   o = ctor.newInstance(new Object[] {this});
               }
  -            if (o instanceof ProjectComponent) {
  -                ((ProjectComponent) o).setProject(project);
  -            }
  +            Project.setProjectOnObject(project, o);
               String msg = "   +DataType: " + typeName;
               project.log(msg, Project.MSG_DEBUG);
               return o;
  
  
  
  1.54      +3 -9      ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
  
  Index: IntrospectionHelper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- IntrospectionHelper.java	14 Apr 2003 14:47:41 -0000	1.53
  +++ IntrospectionHelper.java	14 Apr 2003 17:21:25 -0000	1.54
  @@ -538,9 +538,7 @@
               DynamicConfigurator dc = (DynamicConfigurator) parent;
               Object nestedElement = dc.createDynamicElement(elementName);
               if (nestedElement != null) {
  -                if (nestedElement instanceof ProjectComponent) {
  -                    ((ProjectComponent) nestedElement).setProject(project);
  -                }
  +                Project.setProjectOnObject(project, nestedElement);
                   return nestedElement;
               }
           }
  @@ -549,9 +547,7 @@
           }
           try {
               Object nestedElement = nc.create(parent);
  -            if (nestedElement instanceof ProjectComponent) {
  -                ((ProjectComponent) nestedElement).setProject(project);
  -            }
  +            Project.setProjectOnObject(project, nestedElement);
               return nestedElement;
           } catch (IllegalAccessException ie) {
               // impossible as getMethods should only return public methods
  @@ -842,9 +838,7 @@
                               throws InvocationTargetException, IllegalAccessException, BuildException
{
                               try {
                                   Object attribute = c.newInstance(new String[] {value});
  -                                if (attribute instanceof ProjectComponent) {
  -                                    ((ProjectComponent) attribute).setProject(p);
  -                                }
  +                                Project.setProjectOnObject(p, attribute);
                                   m.invoke(parent, new Object[] {attribute});
                               } catch (InstantiationException ie) {
                                   throw new BuildException(ie);
  
  
  
  1.81      +2 -0      ant/src/main/org/apache/tools/ant/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Main.java,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- Main.java	12 Feb 2003 05:04:31 -0000	1.80
  +++ Main.java	14 Apr 2003 17:21:25 -0000	1.81
  @@ -649,6 +649,7 @@
               try {
                   BuildListener listener =
                       (BuildListener) Class.forName(className).newInstance();
  +                Project.setProjectOnObject(project, listener);
                   project.addBuildListener(listener);
               } catch (Throwable exc) {
                   throw new BuildException("Unable to instantiate listener "
  @@ -671,6 +672,7 @@
               try {
                   handler = (InputHandler)
                       (Class.forName(inputHandlerClassname).newInstance());
  +                Project.setProjectOnObject(project, handler);
               } catch (ClassCastException e) {
                   String msg = "The specified input handler class "
                       + inputHandlerClassname
  
  
  
  1.135     +33 -4     ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.134
  retrieving revision 1.135
  diff -u -r1.134 -r1.135
  --- Project.java	14 Apr 2003 11:58:03 -0000	1.134
  +++ Project.java	14 Apr 2003 17:21:25 -0000	1.135
  @@ -58,6 +58,7 @@
   import java.io.IOException;
   import java.io.EOFException;
   import java.io.InputStream;
  +import java.lang.reflect.Method;
   import java.lang.reflect.Modifier;
   import java.util.Enumeration;
   import java.util.Hashtable;
  @@ -1133,6 +1134,7 @@
   
           try {
               Object o = c.newInstance();
  +            setProjectOnObject(this, o);
               Task task = null;
               if (o instanceof Task) {
                  task = (Task) o;
  @@ -1245,9 +1247,7 @@
               } else {
                    o = ctor.newInstance(new Object[] {this});
               }
  -            if (o instanceof ProjectComponent) {
  -                ((ProjectComponent) o).setProject(this);
  -            }
  +            setProjectOnObject(this, o);
               String msg = "   +DataType: " + typeName;
               log (msg, MSG_DEBUG);
               return o;
  @@ -2305,4 +2305,33 @@
               return get(key) != null;
           }
       }
  +    
  +    /**
  +     * set the project on a created object using object.setProject(project).
  +     * Need to set the project before other set/add elements
  +     * are called
  +     * @param project the project object
  +     * @param obj the object to invoke setProject(project) on
  +     */
  +    public static void setProjectOnObject(Project project, Object obj) {
  +        if (project == null)
  +            return;
  +        if (obj instanceof ProjectComponent) {
  +            ((ProjectComponent) obj).setProject(project);
  +            return;
  +        }
  +        try {
  +            Method method = 
  +                obj.getClass().getMethod(
  +                    "setProject", new Class[] {Project.class});
  +            if (method != null) {
  +                method.invoke(obj, new Object[] {project});
  +            }
  +        } catch (Throwable e) {
  +            // ignore this if the object does not have
  +            // a set project method or the method
  +            // is private/protected.
  +        }
  +    }
  +
   }
  
  
  
  1.12      +19 -10    ant/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java
  
  Index: ChainReaderHelper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ChainReaderHelper.java	14 Apr 2003 11:58:03 -0000	1.11
  +++ ChainReaderHelper.java	14 Apr 2003 17:21:26 -0000	1.12
  @@ -196,11 +196,7 @@
                                   final Reader[] rdr = {instream};
                                   instream =
                                       (Reader) constructors[j].newInstance(rdr);
  -                                if (project != null &&
  -                                        instream instanceof BaseFilterReader) {
  -                                    ((BaseFilterReader)
  -                                        instream).setProject(project);
  -                                }
  +                                setProjectOnObject(instream);
                                   if (Parameterizable.class.isAssignableFrom(clazz)) {
                                       final Parameter[] params = filter.getParams();
                                       ((Parameterizable)
  @@ -217,18 +213,31 @@
                               throw new BuildException(ite);
                           }
                       }
  -                } else if (o instanceof ChainableReader &&
  -                           o instanceof Reader) {
  -                    if (project != null && o instanceof BaseFilterReader) {
  -                        ((BaseFilterReader) o).setProject(project);
  -                    }
  +                } else if (o instanceof ChainableReader) {
  +                    setProjectOnObject(o);
                       instream = ((ChainableReader) o).chain(instream);
  +                    setProjectOnObject(instream);
                   }
               }
           }
           return instream;
       }
   
  +    /**
  +     * helper method to set the project on an object.
  +     * the reflection setProject does not work for anonymous/protected/private
  +     * classes, even if they have public methods.
  +     */
  +    private void setProjectOnObject(Object obj) {
  +        if (project == null)
  +            return;
  +        if (obj instanceof BaseFilterReader) {
  +            ((BaseFilterReader) obj).setProject(project);
  +            return;
  +        }
  +        Project.setProjectOnObject(project, obj);
  +    }
  +    
       /**
        * Read data from the reader and return the
        * contents as a string.
  
  
  
  1.17      +1 -0      ant/src/main/org/apache/tools/ant/types/Mapper.java
  
  Index: Mapper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/Mapper.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Mapper.java	7 Mar 2003 11:23:07 -0000	1.16
  +++ Mapper.java	14 Apr 2003 17:21:27 -0000	1.17
  @@ -204,6 +204,7 @@
               }
   
               FileNameMapper m = (FileNameMapper) c.newInstance();
  +            Project.setProjectOnObject(getProject(), m);
               m.setFrom(from);
               m.setTo(to);
               return m;
  
  
  
  1.7       +2 -0      ant/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java
  
  Index: ExtendSelector.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ExtendSelector.java	10 Feb 2003 14:14:35 -0000	1.6
  +++ ExtendSelector.java	14 Apr 2003 17:21:27 -0000	1.7
  @@ -56,6 +56,7 @@
   
   import java.io.File;
   import java.util.Vector;
  +import org.apache.tools.ant.Project;
   import org.apache.tools.ant.AntClassLoader;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.types.Parameter;
  @@ -106,6 +107,7 @@
                       AntClassLoader.initializeClass(c);
                   }
                   dynselector = (FileSelector) c.newInstance();
  +                Project.setProjectOnObject(getProject(), dynselector);
               }
               catch (ClassNotFoundException cnfexcept) {
                   setError("Selector " + classname +
  
  
  

Mime
View raw message