From 1e6540e5975e006a0e86313b2c69ab53653ff215 Mon Sep 17 00:00:00 2001 From: Jacobus Martinus Kruithof Date: Sat, 25 Mar 2006 22:35:34 +0000 Subject: [PATCH] Adding property storing the ant core library. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@388848 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/Diagnostics.java | 15 +++++++++++++ src/main/org/apache/tools/ant/MagicNames.java | 8 +++++++ src/main/org/apache/tools/ant/Main.java | 3 +-- src/main/org/apache/tools/ant/Project.java | 21 ++++++++++++++++--- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/main/org/apache/tools/ant/Diagnostics.java b/src/main/org/apache/tools/ant/Diagnostics.java index 2fd17d1cb..4e77e60c4 100644 --- a/src/main/org/apache/tools/ant/Diagnostics.java +++ b/src/main/org/apache/tools/ant/Diagnostics.java @@ -263,6 +263,9 @@ public final class Diagnostics { ignoreThrowable(e); out.println("optional tasks : not available"); } + + header(out, "ANT PROPERTIES"); + doReportAntProperties(out); header(out, "ANT_HOME/lib jar listing"); doReportAntHomeLibraries(out); @@ -328,6 +331,18 @@ public final class Diagnostics { } } + /** + * Report the content of ANT_HOME/lib directory + * @param out the stream to print the content to + */ + private static void doReportAntProperties(PrintStream out) { + Project p = new Project(); + p.initProperties(); + out.println(MagicNames.ANT_VERSION + ": " + p.getProperty(MagicNames.ANT_VERSION)); + out.println(MagicNames.ANT_JAVA_VERSION + ": " + p.getProperty(MagicNames.ANT_JAVA_VERSION)); + out.println(MagicNames.ANT_LIB + ": " + p.getProperty(MagicNames.ANT_LIB)); + out.println(MagicNames.ANT_HOME + ": " + p.getProperty(MagicNames.ANT_HOME)); + } /** * Report the content of ANT_HOME/lib directory diff --git a/src/main/org/apache/tools/ant/MagicNames.java b/src/main/org/apache/tools/ant/MagicNames.java index 40ca97a8c..6444087bd 100644 --- a/src/main/org/apache/tools/ant/MagicNames.java +++ b/src/main/org/apache/tools/ant/MagicNames.java @@ -106,14 +106,22 @@ public final class MagicNames { /** * Property used to store the java version ant is running in. + * @since Ant 1.7 */ public static final String ANT_JAVA_VERSION = "ant.java.version"; /** * Property used to store the location of ant. + * @since Ant 1.7 */ public static final String ANT_HOME = "ant.home"; + /** + * Property used to store the location of the ant library (typically the ant.jar file.) + * @since Ant 1.7 + */ + public static final String ANT_LIB = "ant.core.lib"; + /** * property for regular expression implementation. * Value: {@value} diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index 9f4f28550..ba957c1fa 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.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. @@ -638,7 +638,6 @@ public class Main implements AntMain { project.init(); - project.setUserProperty(MagicNames.ANT_VERSION, getAntVersion()); // set user-define properties Enumeration e = definedProps.keys(); diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 04e2e0b39..6eaf68a56 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -193,7 +193,7 @@ public class Project implements ResourceFactory { * @deprecated */ public static final String ANT_JAVA_VERSION = MagicNames.ANT_JAVA_VERSION; - + /** * Set the input handler. * @@ -282,14 +282,29 @@ public class Project implements ResourceFactory { * @exception BuildException if the default task list cannot be loaded. */ public void init() throws BuildException { - setJavaVersionProperty(); + initProperties(); ComponentHelper.getComponentHelper(this).initDefaultDefinitions(); + } + /** + * Initializes the properties. + * @exception BuildException if an vital property could not be set. + * @since Ant 1.7 + */ + public void initProperties() throws BuildException { + setJavaVersionProperty(); setSystemProperties(); + setPropertyInternal(MagicNames.ANT_VERSION, Main.getAntVersion()); + setAntLib(); } - + private void setAntLib() { + File antlib = org.apache.tools.ant.launch.Locator.getClassSource(Project.class); + if (antlib != null) { + setPropertyInternal(MagicNames.ANT_LIB, antlib.getAbsolutePath()); + } + } /** * Factory method to create a class loader for loading classes from * a given path.