On Sat, 2002-05-25 at 14:30, James Strachan wrote:
> From: "James Taylor" <[EMAIL PROTECTED]>
> > So here is my (shaky) +1.
> 
> Does anyone fancy committing this patch into CVS please? Already Jelly's CVS
> image depends on it and I'd rather not back these changes out and start
> hand-crafting classpaths again.

I'm just catching up now, but looking at it now it seems fine so I will
get it in ASAP. I just need to do a little catching up.
 
> If there's any controversy over changing the org.apache.maven.ant.Ant task
> (which AFAIK noone uses yet anyways) then we could always add it to Maven
> CVS as another task name? I'd really like to start using <maven-ant> in a
> few different builds, Jelly, betwixt, dom4j etc. Just having one Ant task
> somewhere in maven.jar to do this seems a low risk strategy - its not going
> to break anyones Maven builds.


> James
> ----
> 

> Index: src/java/org/apache/maven/ant/Ant.java
> ===================================================================
> RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/ant/Ant.java,v
> retrieving revision 1.2
> diff -u -r1.2 Ant.java
> --- src/java/org/apache/maven/ant/Ant.java    22 Apr 2002 00:15:04 -0000      1.2
> +++ src/java/org/apache/maven/ant/Ant.java    24 May 2002 07:00:52 -0000
> @@ -121,6 +121,12 @@
>      /** should we inherit references from the parent ? */
>      private boolean inheritRefs = false;
>  
> +    /** should we export all properties to the parent ? */
> +    private boolean exportAll = true;
> +    
> +    /** should we export references to the parent ? */
> +    private boolean exportRefs = true;
> +    
>      /** the properties to pass to the new project */
>      private Vector properties = new Vector();
>  
> @@ -154,6 +160,33 @@
>      }
>  
>      /**
> +     * <p>If true, all properties defined in the child Project
> +     * are exported to the parent Project so long as they are not
> +     * already defined. No properties will ever be overwritten.
> +     * If false, properties are not exported to the parent project
> +     * </p>
> +     * 
> +     * <p>This property defaults to true</p>
> +     */
> +    public void setExportAll(boolean value) {
> +        exportAll = value;
> +    }
> +
> +    /**
> +     * <p>If true, all references will be exported from the child Project
> +     * into the parent Project after the child project has been executed
> +     * providing they don't already exist in the parent Project.
> +     * No references will ever be overwritten.
> +     * If false, references are not exported to the parent project
> +     * </p>
> +     * 
> +     * <p>This property defaults to true</p>
> +     */
> +    public void setExportRefs(boolean value) {
> +        exportRefs = value;
> +    }
> +
> +    /**
>       * Creates a Project instance for the project to call.
>       */
>      public void init()
> @@ -403,6 +436,9 @@
>              }
>  
>              newProject.executeTarget(target);
> +            
> +            exportProperties();
> +            exportReferences();
>          }
>          finally
>          {
> @@ -451,14 +487,13 @@
>          Hashtable thisReferences = (Hashtable) project.getReferences().clone();
>          Hashtable newReferences = newProject.getReferences();
>          Enumeration e;
> -        if (references.size() > 0)
> +        if (references.size() > 0) 
>          {
>              for (e = references.elements(); e.hasMoreElements(); ) 
>              {
>                  Reference ref = (Reference) e.nextElement();
>                  String refid = ref.getRefId();
> -                if (refid == null) 
> -                {
> +                if (refid == null) {
>                      throw new BuildException("the refid attribute is required"
>                                               + " for reference elements");
>                  }
> @@ -482,12 +517,12 @@
>  
>          // Now add all references that are not defined in the
>          // subproject, if inheritRefs is true
> -        if (inheritRefs)
> +        if (inheritRefs) 
>          {
> -            for (e = thisReferences.keys(); e.hasMoreElements(); )
> +            for (e = thisReferences.keys(); e.hasMoreElements(); ) 
>              {
>                  String key = (String) e.nextElement();
> -                if (newReferences.containsKey(key))
> +                if (newReferences.containsKey(key)) 
>                  {
>                      continue;
>                  }
> @@ -509,8 +544,25 @@
>          //Object orig = project.getReference(oldKey);
>          // Changed this to make it work with ant 1.4
>          Object orig = project.getReferences().get(oldKey);
> -        Class c = orig.getClass();
> +        
> +        copyReference(orig, newKey, newProject);
> +    }
> +
> +    /**
> +     * Try to clone the given reference .
> +     *
> +     * <p>If we cannot clone it, lets reuse the existing 
> +     * reference and keep our fingers crossed.</p>
> +     * 
> +     * @param orig is the reference to be cloned
> +     * @param key is the key for the newly created reference
> +     * @param aProject is the project to add the new reference to
> +     * @return a new cloned reference, ready for adding to a different project
> +     */
> +    private void copyReference(Object orig, String key, Project aProject)
> +    {
>          Object copy = orig;
> +        Class c = orig.getClass();
>          try
>          {
>              Method cloneM = c.getMethod("clone", new Class[0]);
> @@ -527,7 +579,7 @@
>  
>          if (copy instanceof ProjectComponent)
>          {
> -            ((ProjectComponent) copy).setProject(newProject);
> +            ((ProjectComponent) copy).setProject(aProject);
>          }
>          else
>          {
> @@ -537,7 +589,7 @@
>                      c.getMethod("setProject", new Class[] {Project.class});
>                  if (setProjectM != null)
>                  {
> -                    setProjectM.invoke(copy, new Object[] {newProject});
> +                    setProjectM.invoke(copy, new Object[] {aProject});
>                  }
>              }
>              catch (NoSuchMethodException e)
> @@ -548,11 +600,68 @@
>              catch (Exception e2)
>              {
>                  String msg = "Error setting new project instance for "
> -                    + "reference with id " + oldKey;
> +                    + "reference with new id " + key;
>                  throw new BuildException(msg, e2, location);
>              }
>          }
> -        newProject.addReference(newKey, copy);
> +        aProject.addReference(key, copy);
> +    }
> +
> +    /**
> +     * Export any references defined in the child project to the parent
> +     * Project providing that they don't already exist in the parent
> +     * project.
> +     */
> +    private void exportReferences() throws BuildException {
> +        if (exportRefs) {
> +            Hashtable thisReferences = (Hashtable) project.getReferences().clone();
> +            Hashtable newReferences = newProject.getReferences();
> +            
> +            for (Enumeration e = newReferences.keys(); e.hasMoreElements(); )
> +            {
> +                String refid = (String) e.nextElement();
> +                if (refid != null)
> +                {
> +                    // do not overwrite any existing references
> +                    if (!thisReferences.containsKey(refid)) 
> +                    {
> +                        Object reference = newReferences.get(refid);
> +                        
> +                        log("exporting reference for id: " + refid, 
>Project.MSG_VERBOSE);
> +                        
> +                        copyReference(reference, refid, project);
> +                    }
> +                }
> +            }
> +        }
> +    }
> +    
> +
> +    /**
> +     * Export any properties defined in the child project to the parent
> +     * Project providing that they don't already exist in the parent
> +     * project.
> +     */
> +    private void exportProperties() throws BuildException {
> +        if (exportAll) {
> +            Hashtable thisProperties = (Hashtable) project.getProperties().clone();
> +            Hashtable newProperties = newProject.getProperties();
> +            
> +            for (Enumeration e = newProperties.keys(); e.hasMoreElements(); )
> +            {
> +                String key = (String) e.nextElement();
> +                if (key != null)
> +                {
> +                    // do not overwrite any existing properties
> +                    if (!thisProperties.containsKey(key)) 
> +                    {
> +                        log("exporting property for key: " + key, 
>Project.MSG_VERBOSE);
> +                        
> +                        project.setProperty(key, newProject.getProperty(key));
> +                    }
> +                }
> +            }
> +        }
>      }
>  
>      /**
> 
> ----
> 

> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
-- 
jvz.

Jason van Zyl
[EMAIL PROTECTED]

http://tambora.zenplex.org


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

Reply via email to