diff --git a/src/etc/poms/ant-antlr/pom.xml b/src/etc/poms/ant-antlr/pom.xml
index 783b15daf..35a112c3b 100644
--- a/src/etc/poms/ant-antlr/pom.xml
+++ b/src/etc/poms/ant-antlr/pom.xml
@@ -73,7 +73,12 @@
../../../..
../../../..
- true
+
+
+ ant.test.basedir.ignore
+ true
+
+
diff --git a/src/etc/poms/ant-imageio/pom.xml b/src/etc/poms/ant-imageio/pom.xml
index 39f90d117..bb62b2ba8 100644
--- a/src/etc/poms/ant-imageio/pom.xml
+++ b/src/etc/poms/ant-imageio/pom.xml
@@ -65,8 +65,13 @@
../../../..
../../../..
- true
-
+
+
+ ant.test.basedir.ignore
+ true
+
+
+
../../../../src/main
diff --git a/src/etc/poms/ant-jai/pom.xml b/src/etc/poms/ant-jai/pom.xml
index 971cfc87c..90a43685d 100644
--- a/src/etc/poms/ant-jai/pom.xml
+++ b/src/etc/poms/ant-jai/pom.xml
@@ -84,7 +84,12 @@
../../../..
../../../..
- true
+
+
+ ant.test.basedir.ignore
+ true
+
+
diff --git a/src/etc/poms/ant-jdepend/pom.xml b/src/etc/poms/ant-jdepend/pom.xml
index 9b30cbcd3..98c1e60c0 100644
--- a/src/etc/poms/ant-jdepend/pom.xml
+++ b/src/etc/poms/ant-jdepend/pom.xml
@@ -71,7 +71,12 @@
../../../..
../../../..
- true
+
+
+ ant.test.basedir.ignore
+ true
+
+
diff --git a/src/main/org/apache/tools/ant/MagicNames.java b/src/main/org/apache/tools/ant/MagicNames.java
index 5457e6287..2479bce6e 100644
--- a/src/main/org/apache/tools/ant/MagicNames.java
+++ b/src/main/org/apache/tools/ant/MagicNames.java
@@ -321,5 +321,41 @@ public final class MagicNames {
* @since Ant 1.10.2
*/
public static final String TSTAMP_NOW_ISO = "ant.tstamp.now.iso";
+
+ /**
+ * Magic property that makes unit tests based on BuildFileTest
+ * or BuildFileRule ignore externally set basedir
+ * (typically by Surefire/Failsafe)
+ *
+ * Value: {@value}
+ * @since Ant 1.10.6
+ */
+ public static final String TEST_BASEDIR_IGNORE = "ant.test.basedir.ignore";
+
+ /**
+ * Magic property that makes unit tests based on BuildFileTest
+ * or BuildFileRule use build files in alternative locations
+ * (relative to "root" directory)
+ *
+ * Value: {@value}
+ * @since Ant 1.10.6
+ */
+ public static final String TEST_ROOT_DIRECTORY = "root";
+
+ /**
+ * Property for ant process ID set in unit tests by BuildFileTest
+ * or BuildFileRule.
+ *
+ * Value: {@value}
+ */
+ public static final String TEST_PROCESS_ID = "ant.processid";
+
+ /**
+ * Property for ant thread name set in unit tests by BuildFileTest
+ * or BuildFileRule.
+ *
+ * Value: {@value}
+ */
+ public static final String TEST_THREAD_NAME = "ant.threadname";
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/CallTarget.java b/src/main/org/apache/tools/ant/taskdefs/CallTarget.java
index d8a0e8c84..ebef7c4b3 100644
--- a/src/main/org/apache/tools/ant/taskdefs/CallTarget.java
+++ b/src/main/org/apache/tools/ant/taskdefs/CallTarget.java
@@ -21,6 +21,7 @@ package org.apache.tools.ant.taskdefs;
import java.io.IOException;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.PropertySet;
@@ -99,7 +100,7 @@ public class CallTarget extends Task {
"Attribute target or at least one nested target is required.",
getLocation());
}
- callee.setAntfile(getProject().getProperty("ant.file"));
+ callee.setAntfile(getProject().getProperty(MagicNames.ANT_FILE));
callee.setInheritAll(inheritAll);
callee.setInheritRefs(inheritRefs);
callee.execute();
diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java b/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java
index 796dcff55..fcb104bb8 100644
--- a/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java
+++ b/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java
@@ -18,6 +18,7 @@
package org.apache.tools.ant.taskdefs.condition;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.util.DeweyDecimal;
@@ -104,7 +105,7 @@ public class AntVersion extends Task implements Condition {
p.init();
StringBuilder sb = new StringBuilder();
boolean foundFirstDigit = false;
- for (char versionChar : p.getProperty("ant.version").toCharArray()) {
+ for (char versionChar : p.getProperty(MagicNames.ANT_VERSION).toCharArray()) {
if (Character.isDigit(versionChar)) {
sb.append(versionChar);
foundFirstDigit = true;
diff --git a/src/tests/junit/org/apache/tools/ant/BuildFileRule.java b/src/tests/junit/org/apache/tools/ant/BuildFileRule.java
index 51cc3955f..48c71adbc 100644
--- a/src/tests/junit/org/apache/tools/ant/BuildFileRule.java
+++ b/src/tests/junit/org/apache/tools/ant/BuildFileRule.java
@@ -153,11 +153,14 @@ public class BuildFileRule extends ExternalResource {
logBuffer = new StringBuffer();
fullLogBuffer = new StringBuffer();
project = new Project();
+ if (Boolean.getBoolean(MagicNames.TEST_BASEDIR_IGNORE)) {
+ System.clearProperty(MagicNames.PROJECT_BASEDIR);
+ }
project.init();
- File antFile = new File(System.getProperty("root"), filename);
- project.setProperty("ant.processid", ProcessUtil.getProcessId(""));
- project.setProperty("ant.threadname", Thread.currentThread().getName());
- project.setUserProperty("ant.file", antFile.getAbsolutePath());
+ File antFile = new File(System.getProperty(MagicNames.TEST_ROOT_DIRECTORY), filename);
+ project.setProperty(MagicNames.TEST_PROCESS_ID, ProcessUtil.getProcessId(""));
+ project.setProperty(MagicNames.TEST_THREAD_NAME, Thread.currentThread().getName());
+ project.setUserProperty(MagicNames.ANT_FILE, antFile.getAbsolutePath());
project.addBuildListener(new AntTestListener(logLevel));
ProjectHelper.configureProject(project, antFile);
}
diff --git a/src/tests/junit/org/apache/tools/ant/BuildFileTest.java b/src/tests/junit/org/apache/tools/ant/BuildFileTest.java
index c2af9c99d..723e4e1c7 100644
--- a/src/tests/junit/org/apache/tools/ant/BuildFileTest.java
+++ b/src/tests/junit/org/apache/tools/ant/BuildFileTest.java
@@ -327,12 +327,15 @@ public abstract class BuildFileTest extends TestCase {
logBuffer = new StringBuffer();
fullLogBuffer = new StringBuffer();
project = new Project();
+ if (Boolean.getBoolean(MagicNames.TEST_BASEDIR_IGNORE)) {
+ System.clearProperty(MagicNames.PROJECT_BASEDIR);
+ }
project.init();
- File antFile = new File(System.getProperty("root"), filename);
- project.setUserProperty("ant.file", antFile.getAbsolutePath());
+ File antFile = new File(System.getProperty(MagicNames.TEST_ROOT_DIRECTORY), filename);
+ project.setUserProperty(MagicNames.ANT_FILE, antFile.getAbsolutePath());
// set two new properties to allow to build unique names when running multithreaded tests
- project.setProperty("ant.processid", ProcessUtil.getProcessId(""));
- project.setProperty("ant.threadname", Thread.currentThread().getName());
+ project.setProperty(MagicNames.TEST_PROCESS_ID, ProcessUtil.getProcessId(""));
+ project.setProperty(MagicNames.TEST_THREAD_NAME, Thread.currentThread().getName());
project.addBuildListener(new AntTestListener(logLevel));
ProjectHelper.configureProject(project, antFile);
}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java
index 9e57dd498..1e77d251f 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java
@@ -28,6 +28,7 @@ import java.util.GregorianCalendar;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.util.FileUtils;
@@ -66,7 +67,7 @@ public class ExecTaskTest {
buildRule.getProject().executeTarget("setUp");
assumeNotNull(buildRule.getProject().getProperty("test.can.run"));
MonitoredBuild myBuild = new MonitoredBuild(new File(
- buildRule.getProject().getProperty("ant.file")), "spawn");
+ buildRule.getProject().getProperty(MagicNames.ANT_FILE)), "spawn");
File logFile = FILE_UTILS.createTempFile("spawn", "log",
new File(buildRule.getProject().getProperty("output")), false, false);
// this is guaranteed by FileUtils#createTempFile
@@ -131,7 +132,7 @@ public class ExecTaskTest {
this.target = target;
project = new Project();
project.init();
- project.setUserProperty("ant.file", myBuildFile.getAbsolutePath());
+ project.setUserProperty(MagicNames.ANT_FILE, myBuildFile.getAbsolutePath());
ProjectHelper.configureProject(project, myBuildFile);
}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java
index 1aab81191..de8047bd4 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java
@@ -19,6 +19,8 @@
package org.apache.tools.ant.taskdefs;
import java.io.File;
+
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter;
import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory;
@@ -215,13 +217,13 @@ public class JavacTest {
@Test
public void testSourceWithDefault() {
- project.setNewProperty("ant.build.javac.source", "1.4");
+ project.setNewProperty(MagicNames.BUILD_JAVAC_SOURCE, "1.4");
assertEquals("1.4", javac.getSource());
}
@Test
public void testSourceOverridesDefault() {
- project.setNewProperty("ant.build.javac.source", "1.4");
+ project.setNewProperty(MagicNames.BUILD_JAVAC_SOURCE, "1.4");
javac.setSource("1.5");
assertEquals("1.5", javac.getSource());
}
@@ -233,13 +235,13 @@ public class JavacTest {
@Test
public void testTargetWithDefault() {
- project.setNewProperty("ant.build.javac.target", "1.4");
+ project.setNewProperty(MagicNames.BUILD_JAVAC_TARGET, "1.4");
assertEquals("1.4", javac.getTarget());
}
@Test
public void testTargetOverridesDefault() {
- project.setNewProperty("ant.build.javac.target", "1.4");
+ project.setNewProperty(MagicNames.BUILD_JAVAC_TARGET, "1.4");
javac.setTarget("1.5");
assertEquals("1.5", javac.getTarget());
}
diff --git a/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java b/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java
index a96a96b3b..e9c47ab7b 100644
--- a/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java
@@ -49,8 +49,8 @@ public class CommandlineJavaTest {
@Before
public void setUp() {
project = new Project();
- if (System.getProperty("root") != null) {
- project.setBasedir(System.getProperty("root"));
+ if (System.getProperty(MagicNames.TEST_ROOT_DIRECTORY) != null) {
+ project.setBasedir(System.getProperty(MagicNames.TEST_ROOT_DIRECTORY));
}
project.setProperty("build.sysclasspath", "ignore");
cloneVm = System.getProperty("ant.build.clonevm");
@@ -74,7 +74,7 @@ public class CommandlineJavaTest {
*/
@Test
public void testGetCommandline() throws CloneNotSupportedException {
- assertNotNull("Ant home not set", System.getProperty("ant.home"));
+ assertNotNull("Ant home not set", System.getProperty(MagicNames.ANT_HOME));
c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest");
c.setClassname("junit.textui.TestRunner");
c.createVmArgument().setValue("-Djava.compiler=NONE");
diff --git a/src/tests/junit/org/apache/tools/ant/types/PathTest.java b/src/tests/junit/org/apache/tools/ant/types/PathTest.java
index 062fe316f..22587efe4 100644
--- a/src/tests/junit/org/apache/tools/ant/types/PathTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/PathTest.java
@@ -22,6 +22,7 @@ import java.io.File;
import java.util.Locale;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.condition.Os;
import org.junit.Before;
@@ -52,8 +53,8 @@ public class PathTest {
@Before
public void setUp() {
project = new Project();
- if (System.getProperty("root") != null) {
- project.setBasedir(System.getProperty("root"));
+ if (System.getProperty(MagicNames.TEST_ROOT_DIRECTORY) != null) {
+ project.setBasedir(System.getProperty(MagicNames.TEST_ROOT_DIRECTORY));
}
p = new Path(project);
}
diff --git a/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java b/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java
index b96143fa4..81296de20 100644
--- a/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java
@@ -28,6 +28,7 @@ import javax.xml.transform.TransformerException;
import javax.xml.transform.sax.SAXSource;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.JAXPUtils;
import org.junit.Before;
@@ -68,8 +69,8 @@ public class XMLCatalogTest {
@Before
public void setUp() {
project = new Project();
- if (System.getProperty("root") != null) {
- project.setBasedir(System.getProperty("root"));
+ if (System.getProperty(MagicNames.TEST_ROOT_DIRECTORY) != null) {
+ project.setBasedir(System.getProperty(MagicNames.TEST_ROOT_DIRECTORY));
}
// This causes XMLCatalog to print out detailed logging
// messages for debugging
diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
index 361855c2d..c09369a8d 100644
--- a/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
@@ -20,6 +20,7 @@ package org.apache.tools.ant.types.resources;
import java.io.File;
import java.io.IOException;
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.junit.Before;
import org.junit.Test;
@@ -36,8 +37,9 @@ public class FileResourceTest {
@Before
public void setUp() throws IOException {
- root = (System.getProperty("root") == null) ? new File(".").getCanonicalFile()
- : new File(System.getProperty("root"));
+ root = (System.getProperty(MagicNames.TEST_ROOT_DIRECTORY) == null)
+ ? new File(".").getCanonicalFile()
+ : new File(System.getProperty(MagicNames.TEST_ROOT_DIRECTORY));
}
@Test
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
index 3b388ea35..2837fa0b5 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
@@ -27,6 +27,7 @@ import java.util.Iterator;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;
@@ -147,7 +148,8 @@ public class ModifiedSelectorTest {
@Test
public void testCustomClasses() {
- assertNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home"));
+ assertNotNull("Ant home not set",
+ selectorRule.getProject().getProperty(MagicNames.ANT_HOME));
BFT bft = new BFT();
bft.setUp();
// don't catch the JUnit exceptions
@@ -554,7 +556,8 @@ public class ModifiedSelectorTest {
@Test
public void testResourceSelectorScenarioSimple() {
- assertNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home"));
+ assertNotNull("Ant home not set",
+ selectorRule.getProject().getProperty(MagicNames.ANT_HOME));
BFT bft = new BFT();
bft.doTarget("modifiedselectortest-scenario-resourceSimple");
bft.doTarget("modifiedselectortest-scenario-clean");
@@ -774,19 +777,22 @@ public class ModifiedSelectorTest {
@Test
public void testScenarioCoreSelectorDefaults() {
- assertNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home"));
+ assertNotNull("Ant home not set",
+ selectorRule.getProject().getProperty(MagicNames.ANT_HOME));
doScenarioTest("modifiedselectortest-scenario-coreselector-defaults", "cache.properties");
}
@Test
public void testScenarioCoreSelectorSettings() {
- assertNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home"));
+ assertNotNull("Ant home not set",
+ selectorRule.getProject().getProperty(MagicNames.ANT_HOME));
doScenarioTest("modifiedselectortest-scenario-coreselector-settings", "core.cache.properties");
}
@Test
public void testScenarioCustomSelectorSettings() {
- assertNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home"));
+ assertNotNull("Ant home not set",
+ selectorRule.getProject().getProperty(MagicNames.ANT_HOME));
doScenarioTest("modifiedselectortest-scenario-customselector-settings", "core.cache.properties");
}
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/OwnedBySelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/OwnedBySelectorTest.java
index be0d71f6f..1ea26c7c4 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/OwnedBySelectorTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/OwnedBySelectorTest.java
@@ -45,7 +45,7 @@ public class OwnedBySelectorTest {
private final String SELF = System.getProperty("user.name");
- private final String ROOT = "root";
+ private final String ROOT_USER = "root";
private OwnedBySelector s;
@@ -73,7 +73,7 @@ public class OwnedBySelectorTest {
Path symbolicLink = Files.createSymbolicLink(target.toPath(), TEST_FILE.toPath());
UserPrincipal root = Files.getOwner(symbolicLink);
- assertEquals(ROOT, root.getName());
+ assertEquals(ROOT_USER, root.getName());
UserPrincipal user = Files.getOwner(symbolicLink, LinkOption.NOFOLLOW_LINKS);
assertEquals(SELF, user.getName());
diff --git a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
index 2a9a83e0b..241dab76c 100644
--- a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
@@ -23,6 +23,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.taskdefs.condition.Os;
import org.junit.After;
import org.junit.Before;
@@ -50,7 +51,7 @@ public class FileUtilsTest {
public ExpectedException thrown = ExpectedException.none();
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
- private static final String ROOT = System.getProperty("root");
+ private static final String ROOT = System.getProperty(MagicNames.TEST_ROOT_DIRECTORY);
private File removeThis;
private String root;
diff --git a/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java b/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
index 7aec6b66a..649584c83 100644
--- a/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
+import org.apache.tools.ant.MagicNames;
import org.junit.Before;
import org.junit.Test;
@@ -35,7 +36,7 @@ import static org.junit.Assert.assertThat;
public class LayoutPreservingPropertiesTest {
- private static final String ROOT = System.getProperty("root");
+ private static final String ROOT = System.getProperty(MagicNames.TEST_ROOT_DIRECTORY);
private LayoutPreservingProperties lpf;
diff --git a/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java b/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java
index 332af76ad..fdb78abb7 100644
--- a/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java
@@ -17,6 +17,7 @@
*/
package org.apache.tools.ant.util;
+import org.apache.tools.ant.MagicNames;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
@@ -33,7 +34,7 @@ import static org.junit.Assert.assertEquals;
*/
public class ReaderInputStreamTest {
- private static final String ROOT = System.getProperty("root");
+ private static final String ROOT = System.getProperty(MagicNames.TEST_ROOT_DIRECTORY);
@Test
public void testSimple() throws Exception {