From 706d002129865450494a0938c63deb525afd53a1 Mon Sep 17 00:00:00 2001 From: Gintas Grigelionis Date: Wed, 24 Oct 2018 22:35:02 +0200 Subject: [PATCH] More MagicNames --- .../tools/ant/helper/ProjectHelper2.java | 4 +- .../tools/ant/helper/ProjectHelperImpl.java | 5 +- src/main/org/apache/tools/ant/types/Path.java | 57 +++++++------------ .../tools/ant/taskdefs/DirnameTest.java | 4 +- .../tools/ant/taskdefs/PropertyTest.java | 3 +- .../tools/ant/util/JavaEnvUtilsTest.java | 4 +- 6 files changed, 34 insertions(+), 43 deletions(-) diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java index f65a172b4..22ebee0f8 100644 --- a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java +++ b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java @@ -820,8 +820,8 @@ public class ProjectHelper2 extends ProjectHelper { return; } // set explicitly before starting ? - if (project.getProperty("basedir") != null) { - project.setBasedir(project.getProperty("basedir")); + if (project.getProperty(MagicNames.PROJECT_BASEDIR) != null) { + project.setBasedir(project.getProperty(MagicNames.PROJECT_BASEDIR)); } else { // Default for baseDir is the location of the build file. if (baseDir == null) { diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java index 175a39a7a..e6461b6f1 100644 --- a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java +++ b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java @@ -28,6 +28,7 @@ import java.util.Locale; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.IntrospectionHelper; import org.apache.tools.ant.Location; +import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.RuntimeConfigurable; @@ -423,8 +424,8 @@ public class ProjectHelperImpl extends ProjectHelper { helperImpl.project.addReference(id, helperImpl.project); } - if (helperImpl.project.getProperty("basedir") != null) { - helperImpl.project.setBasedir(helperImpl.project.getProperty("basedir")); + if (helperImpl.project.getProperty(MagicNames.PROJECT_BASEDIR) != null) { + helperImpl.project.setBasedir(helperImpl.project.getProperty(MagicNames.PROJECT_BASEDIR)); } else { if (baseDir == null) { helperImpl.project.setBasedir(helperImpl.buildFileParent.getAbsolutePath()); diff --git a/src/main/org/apache/tools/ant/types/Path.java b/src/main/org/apache/tools/ant/types/Path.java index d2acd8c11..08f5f2248 100644 --- a/src/main/org/apache/tools/ant/types/Path.java +++ b/src/main/org/apache/tools/ant/types/Path.java @@ -595,7 +595,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection { if (JavaEnvUtils.isKaffe()) { // newer versions of Kaffe (1.1.1+) won't have this, // but this will be sorted by FileSet anyway. - File kaffeShare = new File(System.getProperty("java.home") + File kaffeShare = new File(JavaEnvUtils.getJavaHome() + File.separator + "share" + File.separator + "kaffe"); if (kaffeShare.isDirectory()) { @@ -612,57 +612,44 @@ public class Path extends DataType implements Cloneable, ResourceCollection { // TODO is this code still necessary? is there any 1.2+ port? // Pull in *.zip from packages directory FileSet msZipFiles = new FileSet(); - msZipFiles.setDir(new File(System.getProperty("java.home") - + File.separator + "Packages")); + msZipFiles.setDir(new File(JavaEnvUtils.getJavaHome() + + File.separator + "Packages")); msZipFiles.setIncludes("*.ZIP"); addFileset(msZipFiles); } else { // JDK 1.2+ seems to set java.home to the JRE directory. - addExisting(new Path(null, - System.getProperty("java.home") - + File.separator + "lib" - + File.separator + "rt.jar")); + addExisting(new Path(null, JavaEnvUtils.getJavaHome() + + File.separator + "lib" + File.separator + "rt.jar")); // Just keep the old version as well and let addExisting // sort it out. - addExisting(new Path(null, - System.getProperty("java.home") - + File.separator + "jre" - + File.separator + "lib" - + File.separator + "rt.jar")); + addExisting(new Path(null, JavaEnvUtils.getJavaHome() + + File.separator + "jre" + File.separator + "lib" + + File.separator + "rt.jar")); // Sun's and Apple's 1.4 have JCE and JSSE in separate jars. for (String secJar : Arrays.asList("jce", "jsse")) { - addExisting(new Path(null, - System.getProperty("java.home") - + File.separator + "lib" - + File.separator + secJar + ".jar")); - addExisting(new Path(null, - System.getProperty("java.home") - + File.separator + ".." - + File.separator + "Classes" - + File.separator + secJar + ".jar")); + addExisting(new Path(null, JavaEnvUtils.getJavaHome() + + File.separator + "lib" + + File.separator + secJar + ".jar")); + addExisting(new Path(null, JavaEnvUtils.getJavaHome() + + File.separator + ".." + File.separator + "Classes" + + File.separator + secJar + ".jar")); } // IBM's 1.4 has rt.jar split into 4 smaller jars and a combined // JCE/JSSE in security.jar. for (String ibmJar : Arrays.asList("core", "graphics", "security", "server", "xml")) { - addExisting(new Path(null, - System.getProperty("java.home") - + File.separator + "lib" - + File.separator + ibmJar + ".jar")); + addExisting(new Path(null, JavaEnvUtils.getJavaHome() + + File.separator + "lib" + File.separator + ibmJar + ".jar")); } // Added for MacOS X - addExisting(new Path(null, - System.getProperty("java.home") - + File.separator + ".." - + File.separator + "Classes" - + File.separator + "classes.jar")); - addExisting(new Path(null, - System.getProperty("java.home") - + File.separator + ".." - + File.separator + "Classes" - + File.separator + "ui.jar")); + addExisting(new Path(null, JavaEnvUtils.getJavaHome() + + File.separator + ".." + File.separator + "Classes" + + File.separator + "classes.jar")); + addExisting(new Path(null, JavaEnvUtils.getJavaHome() + + File.separator + ".." + File.separator + "Classes" + + File.separator + "ui.jar")); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java index 72e1a992e..585c847bd 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java @@ -23,6 +23,7 @@ import static org.junit.Assume.assumeFalse; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.taskdefs.condition.Os; import org.junit.Before; import org.junit.Rule; @@ -78,7 +79,8 @@ public class DirnameTest { @Test public void test5() { buildRule.executeTarget("test5"); - assertEquals("dirname failed", buildRule.getProject().getProperty("basedir"), + assertEquals("dirname failed", + buildRule.getProject().getProperty(MagicNames.PROJECT_BASEDIR), buildRule.getProject().getProperty("base.dir")); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java index 4115339e1..1762c2222 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java @@ -26,6 +26,7 @@ import static org.junit.Assume.assumeNoException; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.util.FileUtils; import org.junit.Before; import org.junit.Rule; @@ -83,7 +84,7 @@ public class PropertyTest { @Test public void test5() { - String baseDir = buildRule.getProject().getProperty("basedir"); + String baseDir = buildRule.getProject().getProperty(MagicNames.PROJECT_BASEDIR); String uri = FILE_UTILS.toURI(baseDir + "/property3.properties"); buildRule.getProject().setNewProperty("test5.url", uri); diff --git a/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java index a93f4f2d5..ad03ed3b2 100644 --- a/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java @@ -51,7 +51,7 @@ public class JavaEnvUtilsTest { @Test public void testGetExecutableWindows() { assumeTrue("Test only runs on windows", Os.isFamily("windows")); - String javaHome = FILE_UTILS.normalize(System.getProperty("java.home")) + String javaHome = FILE_UTILS.normalize(JavaEnvUtils.getJavaHome()) .getAbsolutePath(); String j = JavaEnvUtils.getJreExecutable("java"); @@ -89,7 +89,7 @@ public class JavaEnvUtilsTest { public void testGetExecutableMostPlatforms() { assumeFalse("Test only runs on non Netware and non Windows systems", Os.isName("netware") || Os.isFamily("windows")); - String javaHome = FILE_UTILS.normalize(System.getProperty("java.home")).getAbsolutePath(); + String javaHome = FILE_UTILS.normalize(JavaEnvUtils.getJavaHome()).getAbsolutePath(); // could still be OS/2 String extension = Os.isFamily("dos") ? ".exe" : "";