You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/08/29 15:29:13 UTC

svn commit: r690251 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/Project.java src/main/org/apache/tools/ant/PropertyHelper.java src/main/org/apache/tools/ant/taskdefs/Ant.java src/tests/antunit/taskdefs/subant-test.xml

Author: bodewig
Date: Fri Aug 29 06:29:12 2008
New Revision: 690251

URL: http://svn.apache.org/viewvc?rev=690251&view=rev
Log:
make allowNativeBasedir work even when nested, PR 45711.  fixes PR 30569 at the same time.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/Project.java
    ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ant.java
    ant/core/trunk/src/tests/antunit/taskdefs/subant-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=690251&r1=690250&r2=690251&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Aug 29 06:29:12 2008
@@ -183,6 +183,10 @@
  * ant -v -version would print the version information twice.
    Bugzilla Report 45695.
 
+ * when nested into builds that have been invoked by <ant> tasks
+   <subant> might set the wrong basedir on the called projects.
+   Bugzilla Report 30569.
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/Project.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Project.java?rev=690251&r1=690250&r2=690251&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Project.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Project.java Fri Aug 29 06:29:12 2008
@@ -656,6 +656,15 @@
     }
 
     /**
+     * Return a copy of the inherited property hashtable.
+     * @return a hashtable containing just the inherited properties.
+     * @since Ant 1.8.0
+     */
+    public Hashtable getInheritedProperties() {
+        return PropertyHelper.getPropertyHelper(this).getInheritedProperties();
+    }
+
+    /**
      * Copy all user properties that have been set on the command
      * line or a GUI tool from this instance to the Project instance
      * given as the argument.

Modified: ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java?rev=690251&r1=690250&r2=690251&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java Fri Aug 29 06:29:12 2008
@@ -775,6 +775,17 @@
     }
 
     /**
+     * Returns a copy of the inherited property hashtable
+     * @return a hashtable containing just the inherited properties
+     */
+    public Hashtable getInheritedProperties() {
+        //avoid concurrent modification:
+        synchronized (inheritedProperties) {
+            return new Hashtable(inheritedProperties);
+        }
+    }
+
+    /**
      * special back door for subclasses, internal access to the hashtables
      * @return the live hashtable of all properties
      */

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ant.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ant.java?rev=690251&r1=690250&r2=690251&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ant.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ant.java Fri Aug 29 06:29:12 2008
@@ -215,7 +215,11 @@
             }
         }
         // set user-defined properties
+        if (allowNativeBasedir) {
+            addAlmostAll(getProject().getUserProperties(), PropertyType.USER);
+        } else {
         getProject().copyUserProperties(newProject);
+        }
 
         if (!inheritAll) {
            // set Ant's built-in properties separately,
@@ -224,13 +228,13 @@
 
         } else {
             // set all properties from calling project
-            addAlmostAll(getProject().getProperties());
+            addAlmostAll(getProject().getProperties(), PropertyType.PLAIN);
         }
 
         Enumeration e = propertySets.elements();
         while (e.hasMoreElements()) {
             PropertySet ps = (PropertySet) e.nextElement();
-            addAlmostAll(ps.getProperties());
+            addAlmostAll(ps.getProperties(), PropertyType.PLAIN);
         }
     }
 
@@ -490,7 +494,12 @@
             p.setProject(newProject);
             p.execute();
         }
+        if (allowNativeBasedir) {
+            addAlmostAll(getProject().getInheritedProperties(),
+                         PropertyType.INHERITED);
+        } else {
         getProject().copyInheritedProperties(newProject);
+        }
     }
 
     /**
@@ -601,23 +610,32 @@
      * well as properties named basedir or ant.file.
      * @param props properties <code>Hashtable</code> to copy to the
      * new project.
-     * @since Ant 1.6
+     * @param the type of property to set (a plain Ant property, a
+     * user property or an inherited property).
+     * @since Ant 1.8.0
      */
-    private void addAlmostAll(Hashtable props) {
+    private void addAlmostAll(Hashtable props, PropertyType type) {
         Enumeration e = props.keys();
         while (e.hasMoreElements()) {
             String key = e.nextElement().toString();
-            if (MagicNames.PROJECT_BASEDIR.equals(key) || MagicNames.ANT_FILE.equals(key)) {
+            if (MagicNames.PROJECT_BASEDIR.equals(key)
+                || MagicNames.ANT_FILE.equals(key)) {
                 // basedir and ant.file get special treatment in execute()
                 continue;
             }
 
             String value = props.get(key).toString();
+            if (type == PropertyType.PLAIN) {
             // don't re-set user properties, avoid the warning message
             if (newProject.getProperty(key) == null) {
                 // no user property
                 newProject.setNewProperty(key, value);
             }
+            } else if (type == PropertyType.USER) {
+                newProject.setUserProperty(key, value);
+            } else if (type == PropertyType.INHERITED) {
+                newProject.setInheritedProperty(key, value);
+            }
         }
     }
 
@@ -801,4 +819,11 @@
             return name;
         }
     }
+
+    private static final class PropertyType {
+        private PropertyType() {}
+        private static final PropertyType PLAIN = new PropertyType();
+        private static final PropertyType INHERITED = new PropertyType();
+        private static final PropertyType USER = new PropertyType();
+    }
 }

Modified: ant/core/trunk/src/tests/antunit/taskdefs/subant-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/subant-test.xml?rev=690251&r1=690250&r2=690251&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/subant-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/subant-test.xml Fri Aug 29 06:29:12 2008
@@ -54,7 +54,7 @@
     <ant antfile="${ant.file}" target="testSubAntDoesntSetBasedir"/>
   </target>
 
-  <target name="XtestSubAntDoesntSetBasedirAfterAntWithDir">
+  <target name="testSubAntDoesntSetBasedirAfterAntWithDir">
     <ant antfile="${ant.file}" dir="${basedir}"
          target="testSubAntDoesntSetBasedir"/>
   </target>