Browse Source

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
master
Jacobus Martinus Kruithof 19 years ago
parent
commit
b73a6c6b82
9 changed files with 48 additions and 26 deletions
  1. +2
    -2
      src/main/org/apache/tools/ant/Diagnostics.java
  2. +11
    -0
      src/main/org/apache/tools/ant/MagicNames.java
  3. +5
    -4
      src/main/org/apache/tools/ant/Project.java
  4. +7
    -4
      src/main/org/apache/tools/ant/launch/Launcher.java
  5. +7
    -5
      src/main/org/apache/tools/ant/taskdefs/Exec.java
  6. +6
    -5
      src/main/org/apache/tools/ant/taskdefs/Execute.java
  7. +3
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java
  8. +3
    -2
      src/testcases/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java
  9. +4
    -2
      src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java

+ 2
- 2
src/main/org/apache/tools/ant/Diagnostics.java View File

@@ -107,7 +107,7 @@ public final class Diagnostics {
* <tt>null</tt> if an error occurs. * <tt>null</tt> if an error occurs.
*/ */
public static File[] listLibraries() { public static File[] listLibraries() {
String home = System.getProperty(Launcher.ANTHOME_PROPERTY);
String home = System.getProperty(MagicNames.ANT_HOME);
if (home == null) { if (home == null) {
return null; return null;
} }
@@ -334,7 +334,7 @@ public final class Diagnostics {
* @param out the stream to print the content to * @param out the stream to print the content to
*/ */
private static void doReportAntHomeLibraries(PrintStream out) { 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(); File[] libs = listLibraries();
printLibraries(libs, out); printLibraries(libs, out);
} }


+ 11
- 0
src/main/org/apache/tools/ant/MagicNames.java View File

@@ -103,6 +103,17 @@ public final class MagicNames {
* Value: {@value} * Value: {@value}
*/ */
public static final String ANT_FILE = "ant.file"; 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. * property for regular expression implementation.
* Value: {@value} * Value: {@value}


+ 5
- 4
src/main/org/apache/tools/ant/Project.java View File

@@ -190,9 +190,10 @@ public class Project implements ResourceFactory {


/** /**
* Property used to store the java version ant is running in. * 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. * Set the input handler.
* *
@@ -739,7 +740,7 @@ public class Project implements ResourceFactory {
+ " is not a directory"); + " is not a directory");
} }
this.baseDir = baseDir; this.baseDir = baseDir;
setPropertyInternal("basedir", this.baseDir.getPath());
setPropertyInternal(MagicNames.PROJECT_BASEDIR, this.baseDir.getPath());
String msg = "Project base dir set to: " + this.baseDir; String msg = "Project base dir set to: " + this.baseDir;
log(msg, MSG_VERBOSE); log(msg, MSG_VERBOSE);
} }
@@ -807,7 +808,7 @@ public class Project implements ResourceFactory {
*/ */
public void setJavaVersionProperty() throws BuildException { public void setJavaVersionProperty() throws BuildException {
String javaVersion = JavaEnvUtils.getJavaVersion(); String javaVersion = JavaEnvUtils.getJavaVersion();
setPropertyInternal(ANT_JAVA_VERSION, javaVersion);
setPropertyInternal(MagicNames.ANT_JAVA_VERSION, javaVersion);


// sanity check // sanity check
if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_0) if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_0)


+ 7
- 4
src/main/org/apache/tools/ant/launch/Launcher.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.ArrayList;
import java.util.Iterator; import java.util.Iterator;


import org.apache.tools.ant.MagicNames;



/** /**
* This is a launcher for Ant. * This is a launcher for Ant.
@@ -36,8 +38,9 @@ public class Launcher {
/** /**
* The Ant Home (installation) Directory property. * The Ant Home (installation) Directory property.
* {@value} * {@value}
* @deprecated
*/ */
public static final String ANTHOME_PROPERTY = "ant.home";
public static final String ANTHOME_PROPERTY = MagicNames.ANT_HOME;


/** /**
* The Ant Library Directory property. * The Ant Library Directory property.
@@ -141,7 +144,7 @@ public class Launcher {
*/ */
private void run(String[] args) private void run(String[] args)
throws LaunchException, MalformedURLException { throws LaunchException, MalformedURLException {
String antHomeProperty = System.getProperty(ANTHOME_PROPERTY);
String antHomeProperty = System.getProperty(MagicNames.ANT_HOME);
File antHome = null; File antHome = null;


File sourceJar = Locator.getClassSource(getClass()); File sourceJar = Locator.getClassSource(getClass());
@@ -153,7 +156,7 @@ public class Launcher {


if (antHome == null || !antHome.exists()) { if (antHome == null || !antHome.exists()) {
antHome = jarDir.getParentFile(); antHome = jarDir.getParentFile();
System.setProperty(ANTHOME_PROPERTY, antHome.getAbsolutePath());
System.setProperty(MagicNames.ANT_HOME, antHome.getAbsolutePath());
} }


if (!antHome.exists()) { if (!antHome.exists()) {


+ 7
- 5
src/main/org/apache/tools/ant/taskdefs/Exec.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.PrintWriter; import java.io.PrintWriter;

import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;


@@ -96,9 +98,9 @@ public class Exec extends Task {
if (myos.toLowerCase().indexOf("nt") >= 0) { if (myos.toLowerCase().indexOf("nt") >= 0) {
command = "cmd /c cd " + dir + " && " + command; command = "cmd /c cd " + dir + " && " + command;
} else { } else {
String ant = getProject().getProperty("ant.home");
String ant = getProject().getProperty(MagicNames.ANT_HOME);
if (ant == null) { if (ant == null) {
throw new BuildException("Property 'ant.home' not "
throw new BuildException("Property '" + MagicNames.ANT_HOME + "' not "
+ "found", getLocation()); + "found", getLocation());
} }


@@ -107,9 +109,9 @@ public class Exec extends Task {
} }
} }
} else { } else {
String ant = getProject().getProperty("ant.home");
String ant = getProject().getProperty(MagicNames.ANT_HOME);
if (ant == null) { if (ant == null) {
throw new BuildException("Property 'ant.home' not found",
throw new BuildException("Property '" + MagicNames.ANT_HOME + "' not found",
getLocation()); getLocation());
} }
String antRun = getProject().resolveFile(ant + "/bin/antRun").toString(); String antRun = getProject().resolveFile(ant + "/bin/antRun").toString();


+ 6
- 5
src/main/org/apache/tools/ant/taskdefs/Execute.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 java.util.Vector;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.taskdefs.condition.Os;
@@ -1002,10 +1003,10 @@ public class Execute {
+ "No project provided"); + "No project provided");
} }
// Locate the auxiliary script // Locate the auxiliary script
String antHome = project.getProperty("ant.home");
String antHome = project.getProperty(MagicNames.ANT_HOME);
if (antHome == null) { if (antHome == null) {
throw new IOException("Cannot locate antRun script: " 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 String antRun = project.resolveFile(antHome + File.separator
+ myScript).toString(); + myScript).toString();
@@ -1060,10 +1061,10 @@ public class Execute {
+ "No project provided"); + "No project provided");
} }
// Locate the auxiliary script // Locate the auxiliary script
String antHome = project.getProperty("ant.home");
String antHome = project.getProperty(MagicNames.ANT_HOME);
if (antHome == null) { if (antHome == null) {
throw new IOException("Cannot locate antRun script: " 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 String antRun = project.resolveFile(antHome + File.separator
+ myScript).toString(); + myScript).toString();


+ 3
- 2
src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.Attributes;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;


@@ -147,7 +148,7 @@ public final class JarLibManifestTask extends Task {
final Attributes attributes = manifest.getMainAttributes(); final Attributes attributes = manifest.getMainAttributes();


attributes.put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION); 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); attributes.putValue(CREATED_BY, createdBy);


appendExtraAttributes(attributes); appendExtraAttributes(attributes);


+ 3
- 2
src/testcases/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@


package org.apache.tools.ant.taskdefs; package org.apache.tools.ant.taskdefs;


import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Commandline;
@@ -50,7 +51,7 @@ public class ExecuteJavaTest extends TestCase {
ej.setTimeout(new Long(TIME_OUT)); ej.setTimeout(new Long(TIME_OUT));
project = new Project(); project = new Project();
project.setBasedir("."); 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()); cp = new Path(project, getTestClassPath());
ej.setClasspath(cp); ej.setClasspath(cp);
} }


+ 4
- 2
src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@
package org.apache.tools.ant.types; package org.apache.tools.ant.types;


import junit.framework.TestCase; import junit.framework.TestCase;

import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.JavaEnvUtils; 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("build.xml"));
c.createClasspath(project).setLocation(project.resolveFile( c.createClasspath(project).setLocation(project.resolveFile(
System.getProperty("ant.home")+"/lib/ant.jar"));
System.getProperty(MagicNames.ANT_HOME)+"/lib/ant.jar"));
s = c.getCommandline(); s = c.getCommandline();
assertEquals("with classpath", 6, s.length); assertEquals("with classpath", 6, s.length);
// assertEquals("with classpath", "java", s[0]); // assertEquals("with classpath", "java", s[0]);


Loading…
Cancel
Save