Browse Source

Add a property that contains the version of Ant.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269131 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
ac6f3addd3
2 changed files with 28 additions and 21 deletions
  1. +1
    -0
      docs/manual/using.html
  2. +27
    -21
      src/main/org/apache/tools/ant/Main.java

+ 1
- 0
docs/manual/using.html View File

@@ -208,6 +208,7 @@ name of the operating system.</p>
basedir the absolute path of the project's basedir (as set
with the basedir attribute of &lt;project&gt;).
ant.file the absolute path of the buildfile.
ant.version the version of Ant
ant.project.name the name of the project that is currently executing;
it is set in the name attribute of &lt;project&gt;.
ant.java.version the JVM version Ant detected; currently it can hold


+ 27
- 21
src/main/org/apache/tools/ant/Main.java View File

@@ -385,6 +385,7 @@ public class Main {

project.fireBuildStarted();
project.init();
project.setUserProperty("ant.version", getAntVersion());

// set user-define properties
Enumeration e = definedProps.keys();
@@ -394,7 +395,7 @@ public class Main {
project.setUserProperty(arg, value);
}

project.setUserProperty( "ant.file" , buildFile.getAbsolutePath() );
project.setUserProperty("ant.file" , buildFile.getAbsolutePath() );

// first use the ProjectHelper to create the project object
// from the given build file.
@@ -513,27 +514,32 @@ public class Main {
System.out.println(getAntVersion());
}

public static String getAntVersion() throws BuildException {
try {
Properties props = new Properties();
InputStream in =
Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt");
props.load(in);
in.close();

String lSep = System.getProperty("line.separator");
StringBuffer msg = new StringBuffer();
msg.append("Ant version ");
msg.append(props.getProperty("VERSION"));
msg.append(" compiled on ");
msg.append(props.getProperty("DATE"));
return msg.toString();
} catch (IOException ioe) {
throw new BuildException("Could not load the version information:"
+ ioe.getMessage());
} catch (NullPointerException npe) {
throw new BuildException("Could not load the version information.");
private static String antVersion = null;

public synchronized static String getAntVersion() throws BuildException {
if (antVersion == null) {
try {
Properties props = new Properties();
InputStream in =
Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt");
props.load(in);
in.close();
String lSep = System.getProperty("line.separator");
StringBuffer msg = new StringBuffer();
msg.append("Ant version ");
msg.append(props.getProperty("VERSION"));
msg.append(" compiled on ");
msg.append(props.getProperty("DATE"));
antVersion = msg.toString();
} catch (IOException ioe) {
throw new BuildException("Could not load the version information:"
+ ioe.getMessage());
} catch (NullPointerException npe) {
throw new BuildException("Could not load the version information.");
}
}
return antVersion;
}

/**


Loading…
Cancel
Save