From b73a6c6b827631e22dd1c671351d9bf2c6233d14 Mon Sep 17 00:00:00 2001 From: Jacobus Martinus Kruithof Date: Sat, 25 Mar 2006 21:27:51 +0000 Subject: [PATCH] Improved use of MagicNames for ant internal properties git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@388834 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/Diagnostics.java | 4 ++-- src/main/org/apache/tools/ant/MagicNames.java | 11 +++++++++++ src/main/org/apache/tools/ant/Project.java | 9 +++++---- src/main/org/apache/tools/ant/launch/Launcher.java | 11 +++++++---- src/main/org/apache/tools/ant/taskdefs/Exec.java | 12 +++++++----- src/main/org/apache/tools/ant/taskdefs/Execute.java | 11 ++++++----- .../optional/extension/JarLibManifestTask.java | 5 +++-- .../apache/tools/ant/taskdefs/ExecuteJavaTest.java | 5 +++-- .../apache/tools/ant/types/CommandlineJavaTest.java | 6 ++++-- 9 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/main/org/apache/tools/ant/Diagnostics.java b/src/main/org/apache/tools/ant/Diagnostics.java index b46bd26b7..2fd17d1cb 100644 --- a/src/main/org/apache/tools/ant/Diagnostics.java +++ b/src/main/org/apache/tools/ant/Diagnostics.java @@ -107,7 +107,7 @@ public final class Diagnostics { * null if an error occurs. */ public static File[] listLibraries() { - String home = System.getProperty(Launcher.ANTHOME_PROPERTY); + String home = System.getProperty(MagicNames.ANT_HOME); if (home == null) { return null; } @@ -334,7 +334,7 @@ public final class Diagnostics { * @param out the stream to print the content to */ private static void doReportAntHomeLibraries(PrintStream out) { - out.println("ant.home: " + System.getProperty("ant.home")); + out.println(MagicNames.ANT_HOME + ": " + System.getProperty(MagicNames.ANT_HOME)); File[] libs = listLibraries(); printLibraries(libs, out); } diff --git a/src/main/org/apache/tools/ant/MagicNames.java b/src/main/org/apache/tools/ant/MagicNames.java index 2858d62e6..40ca97a8c 100644 --- a/src/main/org/apache/tools/ant/MagicNames.java +++ b/src/main/org/apache/tools/ant/MagicNames.java @@ -103,6 +103,17 @@ public final class MagicNames { * Value: {@value} */ public static final String ANT_FILE = "ant.file"; + + /** + * Property used to store the java version ant is running in. + */ + public static final String ANT_JAVA_VERSION = "ant.java.version"; + + /** + * Property used to store the location of ant. + */ + public static final String ANT_HOME = "ant.home"; + /** * property for regular expression implementation. * Value: {@value} diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index b0ffc796a..04e2e0b39 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -190,9 +190,10 @@ public class Project implements ResourceFactory { /** * Property used to store the java version ant is running in. + * @deprecated */ - public static final String ANT_JAVA_VERSION = "ant.java.version"; - + public static final String ANT_JAVA_VERSION = MagicNames.ANT_JAVA_VERSION; + /** * Set the input handler. * @@ -739,7 +740,7 @@ public class Project implements ResourceFactory { + " is not a directory"); } this.baseDir = baseDir; - setPropertyInternal("basedir", this.baseDir.getPath()); + setPropertyInternal(MagicNames.PROJECT_BASEDIR, this.baseDir.getPath()); String msg = "Project base dir set to: " + this.baseDir; log(msg, MSG_VERBOSE); } @@ -807,7 +808,7 @@ public class Project implements ResourceFactory { */ public void setJavaVersionProperty() throws BuildException { String javaVersion = JavaEnvUtils.getJavaVersion(); - setPropertyInternal(ANT_JAVA_VERSION, javaVersion); + setPropertyInternal(MagicNames.ANT_JAVA_VERSION, javaVersion); // sanity check if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_0) diff --git a/src/main/org/apache/tools/ant/launch/Launcher.java b/src/main/org/apache/tools/ant/launch/Launcher.java index da4031d3b..3840f5365 100644 --- a/src/main/org/apache/tools/ant/launch/Launcher.java +++ b/src/main/org/apache/tools/ant/launch/Launcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005 The Apache Software Foundation + * Copyright 2003-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,8 @@ import java.util.List; import java.util.ArrayList; import java.util.Iterator; +import org.apache.tools.ant.MagicNames; + /** * This is a launcher for Ant. @@ -36,8 +38,9 @@ public class Launcher { /** * The Ant Home (installation) Directory property. * {@value} + * @deprecated */ - public static final String ANTHOME_PROPERTY = "ant.home"; + public static final String ANTHOME_PROPERTY = MagicNames.ANT_HOME; /** * The Ant Library Directory property. @@ -141,7 +144,7 @@ public class Launcher { */ private void run(String[] args) throws LaunchException, MalformedURLException { - String antHomeProperty = System.getProperty(ANTHOME_PROPERTY); + String antHomeProperty = System.getProperty(MagicNames.ANT_HOME); File antHome = null; File sourceJar = Locator.getClassSource(getClass()); @@ -153,7 +156,7 @@ public class Launcher { if (antHome == null || !antHome.exists()) { antHome = jarDir.getParentFile(); - System.setProperty(ANTHOME_PROPERTY, antHome.getAbsolutePath()); + System.setProperty(MagicNames.ANT_HOME, antHome.getAbsolutePath()); } if (!antHome.exists()) { diff --git a/src/main/org/apache/tools/ant/taskdefs/Exec.java b/src/main/org/apache/tools/ant/taskdefs/Exec.java index 54f7c3344..9bf7f8949 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Exec.java +++ b/src/main/org/apache/tools/ant/taskdefs/Exec.java @@ -1,5 +1,5 @@ /* - * Copyright 2000,2002,2004-2005 The Apache Software Foundation + * Copyright 2000,2002,2004-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; + import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; @@ -96,9 +98,9 @@ public class Exec extends Task { if (myos.toLowerCase().indexOf("nt") >= 0) { command = "cmd /c cd " + dir + " && " + command; } else { - String ant = getProject().getProperty("ant.home"); + String ant = getProject().getProperty(MagicNames.ANT_HOME); if (ant == null) { - throw new BuildException("Property 'ant.home' not " + throw new BuildException("Property '" + MagicNames.ANT_HOME + "' not " + "found", getLocation()); } @@ -107,9 +109,9 @@ public class Exec extends Task { } } } else { - String ant = getProject().getProperty("ant.home"); + String ant = getProject().getProperty(MagicNames.ANT_HOME); if (ant == null) { - throw new BuildException("Property 'ant.home' not found", + throw new BuildException("Property '" + MagicNames.ANT_HOME + "' not found", getLocation()); } String antRun = getProject().resolveFile(ant + "/bin/antRun").toString(); diff --git a/src/main/org/apache/tools/ant/taskdefs/Execute.java b/src/main/org/apache/tools/ant/taskdefs/Execute.java index 4d4361ddc..c59d60e3d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Execute.java +++ b/src/main/org/apache/tools/ant/taskdefs/Execute.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2005 The Apache Software Foundation + * Copyright 2000-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import java.util.Iterator; import java.util.Vector; 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.taskdefs.condition.Os; @@ -1002,10 +1003,10 @@ public class Execute { + "No project provided"); } // Locate the auxiliary script - String antHome = project.getProperty("ant.home"); + String antHome = project.getProperty(MagicNames.ANT_HOME); if (antHome == null) { throw new IOException("Cannot locate antRun script: " - + "Property 'ant.home' not found"); + + "Property '" + MagicNames.ANT_HOME + "' not found"); } String antRun = project.resolveFile(antHome + File.separator + myScript).toString(); @@ -1060,10 +1061,10 @@ public class Execute { + "No project provided"); } // Locate the auxiliary script - String antHome = project.getProperty("ant.home"); + String antHome = project.getProperty(MagicNames.ANT_HOME); if (antHome == null) { throw new IOException("Cannot locate antRun script: " - + "Property 'ant.home' not found"); + + "Property '" + MagicNames.ANT_HOME + "' not found"); } String antRun = project.resolveFile(antHome + File.separator + myScript).toString(); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java index c5b50058f..e3ca1f3b3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 The Apache Software Foundation + * Copyright 2002-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.jar.Attributes; import java.util.jar.Manifest; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; @@ -147,7 +148,7 @@ public final class JarLibManifestTask extends Task { final Attributes attributes = manifest.getMainAttributes(); attributes.put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION); - final String createdBy = "Apache Ant " + getProject().getProperty("ant.version"); + final String createdBy = "Apache Ant " + getProject().getProperty(MagicNames.ANT_VERSION); attributes.putValue(CREATED_BY, createdBy); appendExtraAttributes(attributes); diff --git a/src/testcases/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java b/src/testcases/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java index 83923e001..e8708e320 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002,2004-2005 The Apache Software Foundation + * Copyright 2002,2004-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.apache.tools.ant.taskdefs; +import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Commandline; @@ -50,7 +51,7 @@ public class ExecuteJavaTest extends TestCase { ej.setTimeout(new Long(TIME_OUT)); project = new Project(); project.setBasedir("."); - project.setProperty("ant.home", System.getProperty("ant.home")); + project.setProperty(MagicNames.ANT_HOME, System.getProperty(MagicNames.ANT_HOME)); cp = new Path(project, getTestClassPath()); ej.setClasspath(cp); } diff --git a/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java b/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java index 62eee9f16..f51b3c33d 100644 --- a/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java +++ b/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2005 The Apache Software Foundation + * Copyright 2000-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ package org.apache.tools.ant.types; import junit.framework.TestCase; + +import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.Project; import org.apache.tools.ant.util.JavaEnvUtils; @@ -78,7 +80,7 @@ public class CommandlineJavaTest extends TestCase { c.createClasspath(project).setLocation(project.resolveFile("build.xml")); c.createClasspath(project).setLocation(project.resolveFile( - System.getProperty("ant.home")+"/lib/ant.jar")); + System.getProperty(MagicNames.ANT_HOME)+"/lib/ant.jar")); s = c.getCommandline(); assertEquals("with classpath", 6, s.length); // assertEquals("with classpath", "java", s[0]);