diff --git a/docs/manual/using.html b/docs/manual/using.html index 9e591c839..a67c693b5 100644 --- a/docs/manual/using.html +++ b/docs/manual/using.html @@ -208,6 +208,7 @@ name of the operating system.

basedir the absolute path of the project's basedir (as set with the basedir attribute of <project>). 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 <project>. ant.java.version the JVM version Ant detected; currently it can hold diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index 7018bfe0a..00a1a7cdb 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -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; } /**