Hello, I've attached a patch that adds support for recursively processing
a pom <extend> element. The current behavior stops at just the parent pom,
even if the parent pom also specifies an extend.

Also included in the patch is an alternative way to specify custom
properties in the project pom. Currently the behavior is the following:

...
<properties>
   <someproperty>value</someproperty>
</properties>
...

The patch adds support for the following syntax as well:

...
<properties>
   <property name="someproperty" value="value"/>
</properties>
...

I added this because I saw a case where my property name might not be a
valid XML element name. The patch is backwards compatable with the
existing syntax.

Let me know if any of this is a problem. Thanks.

Regards,

--mike

Index: src/java/org/apache/maven/MavenUtils.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java,v
retrieving revision 1.45
diff -u -r1.45 MavenUtils.java
--- src/java/org/apache/maven/MavenUtils.java   25 Aug 2002 12:38:08 -0000      1.45
+++ src/java/org/apache/maven/MavenUtils.java   4 Oct 2002 00:23:14 -0000
@@ -165,11 +165,23 @@
         Project project = (Project) projectBeanReader.parse(projectDescriptor);
 
         String pomToExtend = project.getExtend();
-        if (pomToExtend != null)
+        File currentFile = projectDescriptor;
+        File currentDir = dir;
+        while (pomToExtend != null)
         {
-            Project parent = (Project) projectBeanReader.parse(new File(dir,
-                pomToExtend));
+            File pomToExtendFile = new File(currentDir, pomToExtend);
+
+            // add guard against infinite extend
+            if (pomToExtendFile.equals(currentFile)) 
+            {
+                break;
+            }
+
+            currentFile = pomToExtendFile;
+            currentDir = currentFile.getParentFile();
+            Project parent = (Project) projectBeanReader.parse(currentFile);
             project = (Project) mergeBeans(project, parent);
+            pomToExtend = parent.getExtend();
         }
                 
         project = getJellyProject(project, parentContext);
@@ -257,7 +269,7 @@
         beanWriter.setXMLIntrospector(createXMLIntrospector());
         beanWriter.setWriteIDs(true);
         beanWriter.write(project);
-        
+
         return projectStream.toString();
     }
 
@@ -547,6 +559,9 @@
         BeanReader beanReader = new BeanReader();
         ExtendedBaseRules ebr = new ExtendedBaseRules();
         beanReader.setRules(new ExtendedBaseRules());
+        beanReader.addCallMethod("*/properties/entry", "setProperty", 2, new 
+Class[]{java.lang.String.class, java.lang.String.class});
+        beanReader.addCallParam("*/properties/entry/key", 0);
+        beanReader.addCallParam("*/properties/entry/value", 1);
         beanReader.addRule("*/properties/?", new MetaPropertiesRule());
         beanReader.setXMLIntrospector(createXMLIntrospector());
         beanReader.registerBeanClass(clazz);
Index: src/java/org/apache/maven/MetaPropertiesRule.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-maven/src/java/org/apache/maven/MetaPropertiesRule.java,v
retrieving revision 1.2
diff -u -r1.2 MetaPropertiesRule.java
--- src/java/org/apache/maven/MetaPropertiesRule.java   22 Aug 2002 19:40:43 -0000     
 1.2
+++ src/java/org/apache/maven/MetaPropertiesRule.java   4 Oct 2002 00:23:14 -0000
@@ -56,6 +56,8 @@
  * ====================================================================
  */
 
+import org.xml.sax.Attributes;
+
 import org.apache.commons.digester.Rule;
 
 import org.apache.maven.project.BaseObject;
@@ -70,6 +72,7 @@
 public class MetaPropertiesRule 
     extends Rule
 {
+    private Attributes attributes;
     private String value;
     
     /**
@@ -82,6 +85,11 @@
     // Rule interface
     //-------------------------------------------------------------------------
 
+    public void begin(Attributes attributes) 
+    {
+       this.attributes = attributes;
+    }
+
     /**
      * Process the body of this element.
      *
@@ -104,6 +112,13 @@
     {
         BaseObject baseObject = (BaseObject) getDigester().peek();
         String name = getDigester().getCurrentElementName();
-        baseObject.addProperty(name + ":" + value);
+
+       if ("property".equals(name)) 
+       {
+           name = this.attributes.getValue("name");
+           value = this.attributes.getValue("value");
+       }
+
+       baseObject.setProperty(name, value);
     }
 }
Index: src/java/org/apache/maven/app/PluginManager.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-maven/src/java/org/apache/maven/app/PluginManager.java,v
retrieving revision 1.34
diff -u -r1.34 PluginManager.java
--- src/java/org/apache/maven/app/PluginManager.java    1 Oct 2002 21:28:25 -0000      
 1.34
+++ src/java/org/apache/maven/app/PluginManager.java    4 Oct 2002 00:23:15 -0000
@@ -289,7 +289,7 @@
         
Forehead.getInstance().getClassLoader("root.maven").addURL(getPluginDir(name).toURL());
         Project pluginProject = MavenUtils.getProject(new 
File(getPluginDir(name),"project.xml"));
         
-        Map pluginProperties = pluginProject.resolvedProperties();
+        Map pluginProperties = pluginProject.getProperties();
         integrateProps(pluginProperties);
         
         if (!isPluginProcessed(name))
Index: src/java/org/apache/maven/project/BaseObject.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-maven/src/java/org/apache/maven/project/BaseObject.java,v
retrieving revision 1.16
diff -u -r1.16 BaseObject.java
--- src/java/org/apache/maven/project/BaseObject.java   25 Aug 2002 15:04:39 -0000     
 1.16
+++ src/java/org/apache/maven/project/BaseObject.java   4 Oct 2002 00:23:15 -0000
@@ -61,6 +61,7 @@
 import java.util.Map;
 import java.util.List;
 import java.util.HashMap;
+import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
 
@@ -90,12 +91,7 @@
      * Meta information that can be used by all objects
      * derived from <code>BaseObject</code>
      */
-    private Map properties;
-    
-    /**
-     * properties that are in the format name:value
-     */
-    private List combinedProperties = new ArrayList();
+    private Map properties = new HashMap();
     
     /**
      * Sets the name attribute
@@ -145,98 +141,48 @@
     /**
      * Add a meta property to this object.
      *
-     * @param combinedProperty The property that is fed in by
-     *        the MetaPropertiesRule is in the form name:value
-     *        so that we can fake out betwixt. Not beautiful
-     *        but it works and when we find a better solution
-     *        nothing will change for users.
+     * @param name the meta property name.
+     * @param value the meta property value.
      */
-    public void addProperty(String combinedProperty)
+    public void setProperty(String name, String value)
     {
-        combinedProperties.add(combinedProperty);
+       if (name != null && name.length() > 0) 
+       {
+           if (value != null) 
+           {
+               this.properties.put(name, value);
+           } 
+           else 
+           {
+               this.properties.remove(name);
+           }
+       }
     }
 
     /**
-     * Get a meta property. The first time one is retrieved we
-     * create a property Map from the name:value entries in the
-     * list we have used to store the meta properties during
-     * mapping through betwixt.
+     * Lookup a meta property value. If the property is not defined,
+     * a <code>null</code> value is returned.
      * 
      * @param name the name of the property to retrieve
-     * @return the property value
+     * @return the property value, or <code>null</code> if the property 
+     *  is not defined.
      */
     public String getProperty(String name)
-    {
-        if (properties == null)
-        {
-            resolveProperties();
-        }
-    
+    {    
         return (String) properties.get(name);
     }
-    
-    /**
-     * Set meta properties. They are stored in a {@link List} of
-     * name:value entries.
-     * 
-     * @param combinedProperties a list of name:value strings
-     */
-    public void setProperties(List combinedProperties)
-    {
-        this.combinedProperties = combinedProperties;
-    }        
 
     /**
-     * Get meta properties.
+     * Return a <code>Map</code> containing all the custom meta
+     * properties defined for this instance.
      * 
-     * @return a {@link List} of name:value entries
+     * @return a {@link Map} containing all the custom meta properties
+     *  defined for this instance.  
      */
-    public List getProperties()
+    public Map getProperties()
     {
-        return combinedProperties;
-    }        
-    
-    /**
-     * Get the resolved properties after the name:value
-     * processing has been done.
-     * 
-     * @return a map from the {@link #getProperties() meta properties} turning
-     * the name:value strings into a key and value for the map
-     */
-    public Map resolvedProperties()
-    {
-        if (properties == null)
-        {
-            resolveProperties();
-        }
-        
-        return properties;
-    }        
-    
-    /**
-     * Resolve the name:value list into a real Map.
-     */
-    private void resolveProperties()
-    {
-        properties = new HashMap();
-            
-        for (Iterator i = combinedProperties.iterator(); i.hasNext();)
-        {
-            String combinedProperty = (String) i.next();
-            String[] s = StringUtils.split(combinedProperty, ":");
-            
-            if (s.length == 3)
-            {
-                // Property is specific and has a value.
-                properties.put(s[1], s[2]);
-            }
-            else
-            {
-                // Property is specific but has no value.
-                properties.put(s[1], "");
-            }                
-        }
-    }        
+       return properties;
+    }
     
     /**
      * Return a string suitable for display/debugging
--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to