diff --git a/WHATSNEW b/WHATSNEW index 30dc39db3..5ecb794d7 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -183,6 +183,10 @@ Fixed bugs: * ant -v -version would print the version information twice. Bugzilla Report 45695. + * when nested into builds that have been invoked by tasks + might set the wrong basedir on the called projects. + Bugzilla Report 30569. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 6c22eda99..307767869 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -655,6 +655,15 @@ public class Project implements ResourceFactory { return PropertyHelper.getPropertyHelper(this).getUserProperties(); } + /** + * 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 diff --git a/src/main/org/apache/tools/ant/PropertyHelper.java b/src/main/org/apache/tools/ant/PropertyHelper.java index 02a621167..cc87d1df4 100644 --- a/src/main/org/apache/tools/ant/PropertyHelper.java +++ b/src/main/org/apache/tools/ant/PropertyHelper.java @@ -774,6 +774,17 @@ public class PropertyHelper implements GetProperty { } } + /** + * 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 diff --git a/src/main/org/apache/tools/ant/taskdefs/Ant.java b/src/main/org/apache/tools/ant/taskdefs/Ant.java index 87bf4da54..6da7eb2bd 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Ant.java +++ b/src/main/org/apache/tools/ant/taskdefs/Ant.java @@ -215,7 +215,11 @@ public class Ant extends Task { } } // 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 @@ public class Ant extends Task { } 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 @@ public class Ant extends Task { p.setProject(newProject); p.execute(); } + if (allowNativeBasedir) { + addAlmostAll(getProject().getInheritedProperties(), + PropertyType.INHERITED); + } else { getProject().copyInheritedProperties(newProject); + } } /** @@ -601,23 +610,32 @@ public class Ant extends Task { * well as properties named basedir or ant.file. * @param props properties Hashtable 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 @@ public class Ant extends Task { 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(); + } } diff --git a/src/tests/antunit/taskdefs/subant-test.xml b/src/tests/antunit/taskdefs/subant-test.xml index 11f7d9f76..dc8b08663 100644 --- a/src/tests/antunit/taskdefs/subant-test.xml +++ b/src/tests/antunit/taskdefs/subant-test.xml @@ -54,7 +54,7 @@ - +