From c1142173a2238a4059462ab05d6935be88d454c5 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 18 Jul 2008 14:21:38 +0000 Subject: [PATCH] new attribute allowNativeBasedir for . Not yet documented. Not yet complete (doesn't work when basedir is a user or inherited property). Work in progress. Needed for PR 30569. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@677914 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/Project.java | 2 +- .../org/apache/tools/ant/taskdefs/Ant.java | 21 +++++++++++++++++++ .../org/apache/tools/ant/taskdefs/SubAnt.java | 2 ++ src/tests/antunit/taskdefs/subant-test.xml | 6 ++++++ 4 files changed, 30 insertions(+), 1 deletion(-) 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"/> + + + +