Hello:

The enclosed patch adds a new "inheritAll" attribute to the <ant> task.
The attribute defaults to "true" which preserves current behavior.
If set to "false," the only properties passed along to the sub-build
are userProperties (i.e., properties specified on the command line) and
properties specified within the actual <ant> call.

Please see my earlier message for more background information:
http://marc.theaimsgroup.com/?l=ant-dev&m=99323191628596&w=2

Thanks!

--Craeg

Apologies! I have enclosed an updated version of the "inheritAll" patch with
a bugfix. Please disregard the previous version. Thanks again,


--Craeg
Index: Ant.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
retrieving revision 1.22
diff -u -r1.22 Ant.java
--- Ant.java    2001/03/12 09:22:04     1.22
+++ Ant.java    2001/06/28 23:57:51
@@ -83,10 +83,20 @@
     private String antFile = null;
     private String target = null;
     private String output = null;
+        private boolean inheritAll = true;
 
     Vector properties=new Vector();
     Project p1;
 
+    /**
+     * If true, inherit all properties from parent Project
+         * If false, inherit only userProperties and those defined
+         * inside the ant call itself
+     **/
+    public void setInheritAll(boolean inherit) {
+                inheritAll = inherit;
+    } //-- setInheritAll
+
     public void init() {
         p1 = new Project();
         p1.setJavaVersionProperty();
@@ -149,13 +159,20 @@
             p1.addDataTypeDefinition(typeName, typeClass);
         }
 
-        // set user-define properties
-        Hashtable prop1 = project.getProperties();
+        // set user-defined or all properties from calling project
+        Hashtable prop1;
+                 if (inheritAll == true)
+                         prop1 = project.getProperties();
+                 else
+                         prop1 = project.getUserProperties();
         e = prop1.keys();
         while (e.hasMoreElements()) {
             String arg = (String) e.nextElement();
             String value = (String) prop1.get(arg);
-            p1.setProperty(arg, value);
+                               if (inheritAll == true)
+                                       p1.setProperty(arg, value);
+                               else
+                                       p1.setUserProperty(arg, value);
         }
     }
 

Reply via email to