diff --git a/src/main/org/apache/tools/ant/MagicNames.java b/src/main/org/apache/tools/ant/MagicNames.java index 8d62f326d..5e85b885d 100644 --- a/src/main/org/apache/tools/ant/MagicNames.java +++ b/src/main/org/apache/tools/ant/MagicNames.java @@ -23,7 +23,16 @@ package org.apache.tools.ant; * * @since Ant 1.6 */ -public class MagicNames { +public final class MagicNames { + /** + * Ant version property. {@value} + */ + public static final String ANT_VERSION = "ant.version"; + + private MagicNames() { + } + + /** * The name of the script repository used by the script repo task * Value {@value} @@ -62,5 +71,27 @@ public class MagicNames { public static final String TYPEDEFS_PROPERTIES_RESOURCE = "/org/apache/tools/ant/types/defaults.properties"; + /** + * Reference to the current Ant executor + * Value: {@value} + */ + public static final String ANT_EXECUTOR_REFERENCE = "ant.executor"; + + /** + * Property defining the classname of an executor. + * Value: {@value} + */ + public static final String ANT_EXECUTOR_CLASSNAME = "ant.executor.class"; + /** + * property name for basedir of the project + * Value: {@value} + */ + public static final String PROJECT_BASEDIR = "basedir"; + /** + * property for ant file name + * Value: {@value} + */ + public static final String ANT_FILE = "ant.file"; + } diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index 5221e291d..0071a32b2 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -46,7 +46,7 @@ import org.apache.tools.ant.util.FileUtils; */ public class Main implements AntMain { - /** The default build file name. */ + /** The default build file name. {@value} */ public static final String DEFAULT_BUILD_FILENAME = "build.xml"; /** Our current message output status. Follows Project.MSG_XXX. */ @@ -628,7 +628,7 @@ public class Main implements AntMain { } project.init(); - project.setUserProperty("ant.version", getAntVersion()); + project.setUserProperty(MagicNames.ANT_VERSION, getAntVersion()); // set user-define properties Enumeration e = definedProps.keys(); @@ -638,7 +638,7 @@ public class Main implements AntMain { project.setUserProperty(arg, value); } - project.setUserProperty("ant.file", + project.setUserProperty(MagicNames.ANT_FILE, buildFile.getAbsolutePath()); project.setKeepGoingMode(keepGoingMode); diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 88db1a058..6de28ed91 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -184,6 +184,7 @@ public class Project { * Flag which catches Listeners which try to use System.out or System.err . */ private boolean loggingMessage = false; + public static final String ANT_JAVA_VERSION = "ant.java.version"; /** * Set the input handler. @@ -794,7 +795,7 @@ public class Project { */ public void setJavaVersionProperty() throws BuildException { String javaVersion = JavaEnvUtils.getJavaVersion(); - setPropertyInternal("ant.java.version", javaVersion); + setPropertyInternal(ANT_JAVA_VERSION, javaVersion); // sanity check if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_0)) { @@ -1038,7 +1039,7 @@ public class Project { * @param e the Executor to use. */ public void setExecutor(Executor e) { - addReference("ant.executor", e); + addReference(MagicNames.ANT_EXECUTOR_REFERENCE, e); } /** @@ -1046,9 +1047,9 @@ public class Project { * @return an Executor instance. */ public Executor getExecutor() { - Object o = getReference("ant.executor"); + Object o = getReference(MagicNames.ANT_EXECUTOR_REFERENCE); if (o == null) { - String classname = getProperty("ant.executor.class"); + String classname = getProperty(MagicNames.ANT_EXECUTOR_CLASSNAME); if (classname == null) { classname = DefaultExecutor.class.getName(); } diff --git a/src/main/org/apache/tools/ant/taskdefs/Ant.java b/src/main/org/apache/tools/ant/taskdefs/Ant.java index c3f30603b..c6d52a9d0 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Ant.java +++ b/src/main/org/apache/tools/ant/taskdefs/Ant.java @@ -36,6 +36,8 @@ import org.apache.tools.ant.ProjectComponent; import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.Target; import org.apache.tools.ant.Task; +import org.apache.tools.ant.MagicNames; +import org.apache.tools.ant.Main; import org.apache.tools.ant.types.PropertySet; import org.apache.tools.ant.util.FileUtils; @@ -119,8 +121,6 @@ public class Ant extends Task { } - - /** * If true, pass all properties to the new Ant project. * Defaults to true. @@ -297,7 +297,7 @@ public class Ant extends Task { newProject.setBaseDir(dir); if (savedDir != null) { // has been set explicitly - newProject.setInheritedProperty("basedir" , + newProject.setInheritedProperty(MagicNames.PROJECT_BASEDIR , dir.getAbsolutePath()); } } else { @@ -307,7 +307,7 @@ public class Ant extends Task { overrideProperties(); if (antFile == null) { - antFile = "build.xml"; + antFile = Main.DEFAULT_BUILD_FILENAME; } File file = FILE_UTILS.resolveFile(dir, antFile); @@ -316,9 +316,9 @@ public class Ant extends Task { log("calling target(s) " + ((locals.size() > 0) ? locals.toString() : "[default]") + " in build file " + antFile, Project.MSG_VERBOSE); - newProject.setUserProperty("ant.file" , antFile); + newProject.setUserProperty(MagicNames.ANT_FILE , antFile); - String thisAntFile = getProject().getProperty("ant.file"); + String thisAntFile = getProject().getProperty(MagicNames.ANT_FILE); // Are we trying to call the target in which we are defined (or // the build file if this is a top level task)? if (thisAntFile != null @@ -350,8 +350,8 @@ public class Ant extends Task { } } - if (newProject.getProperty("ant.file") - .equals(getProject().getProperty("ant.file")) + if (newProject.getProperty(MagicNames.ANT_FILE) + .equals(getProject().getProperty(MagicNames.ANT_FILE)) && getOwningTarget() != null) { String owningTargetName = getOwningTarget().getName(); @@ -558,7 +558,7 @@ public class Ant extends Task { Enumeration e = props.keys(); while (e.hasMoreElements()) { String key = e.nextElement().toString(); - if ("basedir".equals(key) || "ant.file".equals(key)) { + if (MagicNames.PROJECT_BASEDIR.equals(key) || MagicNames.ANT_FILE.equals(key)) { // basedir and ant.file get special treatment in execute() continue; }