diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index d108fe47a..d588225d2 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -822,7 +822,7 @@ public class Project implements ResourceFactory { this.baseDir = baseDir; setPropertyInternal(MagicNames.PROJECT_BASEDIR, this.baseDir.getPath()); String msg = "Project base dir set to: " + this.baseDir; - log(msg, MSG_VERBOSE); + log(msg, MSG_VERBOSE); } /** diff --git a/src/main/org/apache/tools/ant/taskdefs/Ant.java b/src/main/org/apache/tools/ant/taskdefs/Ant.java index fcbe41066..6b6e65e83 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Ant.java +++ b/src/main/org/apache/tools/ant/taskdefs/Ant.java @@ -106,6 +106,15 @@ public class Ant extends Task { /** whether the target attribute was specified **/ private boolean targetAttributeSet = false; + /** + * Whether the basedir of the new project should be the same one + * as it would be when running the build file directly - + * independent of dir and/or inheritAll settings. + * + * @since Ant 1.8.0 + */ + private boolean allowNativeBasedir = false; + /** * simple constructor */ @@ -121,6 +130,16 @@ public class Ant extends Task { bindToOwner(owner); } + /** + * Whether the basedir of the new project should be the same one + * as it would be when running the build file directly - + * independent of dir and/or inheritAll settings. + * + * @since Ant 1.8.0 + */ + public void setAllowNativeBasedir(boolean b) { + allowNativeBasedir = b; + } /** * If true, pass all properties to the new Ant project. @@ -321,12 +340,14 @@ public class Ant extends Task { initializeProject(); if (dir != null) { + if (!allowNativeBasedir) { newProject.setBaseDir(dir); if (savedDir != null) { // has been set explicitly newProject.setInheritedProperty(MagicNames.PROJECT_BASEDIR, dir.getAbsolutePath()); } + } } else { dir = getProject().getBaseDir(); } diff --git a/src/main/org/apache/tools/ant/taskdefs/SubAnt.java b/src/main/org/apache/tools/ant/taskdefs/SubAnt.java index be728ac63..4f7d7ae37 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SubAnt.java +++ b/src/main/org/apache/tools/ant/taskdefs/SubAnt.java @@ -553,6 +553,8 @@ public class SubAnt extends Task { if (directory != null) { antTask.setDir(directory); + } else { + antTask.setAllowNativeBasedir(true); } antTask.setInheritAll(inheritAll); diff --git a/src/tests/antunit/taskdefs/subant-test.xml b/src/tests/antunit/taskdefs/subant-test.xml index 673c7d24b..11f7d9f76 100644 --- a/src/tests/antunit/taskdefs/subant-test.xml +++ b/src/tests/antunit/taskdefs/subant-test.xml @@ -59,4 +59,10 @@ target="testSubAntDoesntSetBasedir"/> + + + +