peterreilly    2003/12/30 05:05:50

  Modified:    src/main/org/apache/tools/ant Tag: ANT_16_BRANCH
                        IntrospectionHelper.java ProjectHelper.java
  Log:
  Sync with HEAD
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.65.2.6  +38 -33    
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.65.2.5
  retrieving revision 1.65.2.6
  diff -u -r1.65.2.5 -r1.65.2.6
  --- IntrospectionHelper.java  17 Dec 2003 15:37:27 -0000      1.65.2.5
  +++ IntrospectionHelper.java  30 Dec 2003 13:05:49 -0000      1.65.2.6
  @@ -974,16 +974,6 @@
   
                   };
   
  -        // resolve relative paths through Project
  -        } else if 
(org.apache.tools.ant.types.Path.class.equals(reflectedArg)) {
  -            return new AttributeSetter() {
  -                    public void set(Project p, Object parent, String value)
  -                        throws InvocationTargetException, 
IllegalAccessException {
  -                        m.invoke(parent, new Path[] {new Path(p, value)});
  -                    }
  -
  -                };
  -
           // EnumeratedAttributes have their own helper class
           } else if (EnumeratedAttribute.class.isAssignableFrom(reflectedArg)) 
{
               return new AttributeSetter() {
  @@ -1001,37 +991,52 @@
                   };
   
           // worst case. look for a public String constructor and use it
  +        // also supports new Whatever(Project, String) as for Path or 
Reference
           // This is used (deliberately) for all primitives/wrappers other than
           // char and boolean
           } else {
   
  +            boolean includeProject;
  +            Constructor c;
               try {
  -                final Constructor c =
  -                    reflectedArg.getConstructor(new Class[] 
{java.lang.String.class});
  -
  -                return new AttributeSetter() {
  -                        public void set(Project p, Object parent,
  -                                        String value)
  -                            throws InvocationTargetException,
  -                                   IllegalAccessException, BuildException {
  -                            try {
  -                                Object attribute = c.newInstance(new 
String[] {value});
  -                                if (p != null) {
  -                                    p.setProjectReference(attribute);
  -                                }
  -                                m.invoke(parent, new Object[] {attribute});
  -                            } catch (InstantiationException ie) {
  -                                throw new BuildException(ie);
  -                            }
  -                        }
  -                    };
  -
  +                // First try with Project.
  +                c = reflectedArg.getConstructor(new Class[] {Project.class, 
String.class});
  +                includeProject = true;
               } catch (NoSuchMethodException nme) {
  -                // ignore
  +                // OK, try without.
  +                try {
  +                    c = reflectedArg.getConstructor(new Class[] 
{String.class});
  +                    includeProject = false;
  +                } catch (NoSuchMethodException nme2) {
  +                    // Well, no matching constructor.
  +                    return null;
  +                }
               }
  +            final boolean finalIncludeProject = includeProject;
  +            final Constructor finalConstructor = c;
  +            
  +            return new AttributeSetter() {
  +                public void set(Project p, Object parent, String value)
  +                        throws InvocationTargetException, 
IllegalAccessException, BuildException {
  +                    try {
  +                        Object[] args;
  +                        if (finalIncludeProject) {
  +                            args = new Object[] {p, value};
  +                        } else {
  +                            args = new Object[] {value};
  +                        }
  +                        Object attribute = 
finalConstructor.newInstance(args);
  +                        if (p != null) {
  +                            p.setProjectReference(attribute);
  +                        }
  +                        m.invoke(parent, new Object[] {attribute});
  +                    } catch (InstantiationException ie) {
  +                        throw new BuildException(ie);
  +                    }
  +                }
  +            };
  +            
           }
  -
  -        return null;
       }
   
       /**
  
  
  
  1.101.2.4 +2 -2      ant/src/main/org/apache/tools/ant/ProjectHelper.java
  
  Index: ProjectHelper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
  retrieving revision 1.101.2.3
  retrieving revision 1.101.2.4
  diff -u -r1.101.2.3 -r1.101.2.4
  --- ProjectHelper.java        18 Nov 2003 11:29:06 -0000      1.101.2.3
  +++ ProjectHelper.java        30 Dec 2003 13:05:49 -0000      1.101.2.4
  @@ -569,10 +569,10 @@
               + ex.getLocation().toString()
               + ex.getMessage();
           if (newLocation == null) {
  -            return new BuildException(errorMessage);
  +            return new BuildException(errorMessage, ex);
           } else {
               return new BuildException(
  -                errorMessage, newLocation);
  +                errorMessage, ex, newLocation);
           }
       }
   }
  
  
  

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

Reply via email to