Author: bodewig
Date: Wed Jun 4 03:58:23 2008
New Revision: 663061
URL: http://svn.apache.org/viewvc?rev=663061&view=rev
Log:
Add a magic property that lists the targets that have been specified in order
to run the current project. Based on patch by Colm Smyth (just like rev663051
was). PR 44980
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/docs/manual/using.html
ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java
ant/core/trunk/src/main/org/apache/tools/ant/Project.java
ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java
ant/core/trunk/src/tests/antunit/core/magic-names-test.xml
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=663061&r1=663060&r2=663061&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Wed Jun 4 03:58:23 2008
@@ -74,6 +74,10 @@
* a new property ant.project.default-target holds the value of the
current <project>'s default attribute.
+ * a new property ant.project.invoked-targets holds a comma separated
+ list of the targets that have been specified on the command line
+ (the IDE, an <ant> task ...) when invoking the current project.
+
Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================
Modified: ant/core/trunk/docs/manual/using.html
URL:
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/using.html?rev=663061&r1=663060&r2=663061&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/using.html (original)
+++ ant/core/trunk/docs/manual/using.html Wed Jun 4 03:58:23 2008
@@ -311,6 +311,11 @@
the name of the currently executing project's
default target; it is set via the default
attribute of <project>.
+ant.project.invoked-targets
+ a comma separated list of the targets that have
+ been specified on the command line (the IDE,
+ an <ant> task ...) when invoking the current
+ project.
ant.java.version the JVM version Ant detected; currently it can hold
the values "1.2", "1.3",
"1.4" and "1.5".
</pre>
Modified: ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java?rev=663061&r1=663060&r2=663061&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java Wed Jun 4
03:58:23 2008
@@ -212,5 +212,14 @@
public static final String PROJECT_DEFAULT_TARGET
= "ant.project.default-target";
+ /**
+ * Name of the property holding a comma separated list of targets
+ * that have been invoked (from the command line).
+ *
+ * Value: [EMAIL PROTECTED]
+ * @since Ant 1.8.0
+ */
+ public static final String PROJECT_INVOKED_TARGETS
+ = "ant.project.invoked-targets";
}
Modified: ant/core/trunk/src/main/org/apache/tools/ant/Project.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Project.java?rev=663061&r1=663060&r2=663061&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Project.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Project.java Wed Jun 4
03:58:23 2008
@@ -45,6 +45,7 @@
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceFactory;
import org.apache.tools.ant.types.resources.FileResource;
+import org.apache.tools.ant.util.CollectionUtils;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.apache.tools.ant.util.StringUtils;
@@ -694,7 +695,7 @@
* no default target.
*/
public void setDefault(String defaultTarget) {
- setUserProperty(MagicNames.PROJECT_DEFAULT_TARGET, defaultTarget);
+ setUserProperty(MagicNames.PROJECT_DEFAULT_TARGET, defaultTarget);
this.defaultTarget = defaultTarget;
}
@@ -1174,6 +1175,8 @@
* @exception BuildException if the build failed.
*/
public void executeTargets(Vector names) throws BuildException {
+ setUserProperty(MagicNames.PROJECT_INVOKED_TARGETS,
+ CollectionUtils.flattenToString(names));
getExecutor().executeTargets(this,
(String[]) (names.toArray(new String[names.size()])));
}
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java?rev=663061&r1=663060&r2=663061&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java Wed
Jun 4 03:58:23 2008
@@ -17,6 +17,7 @@
*/
package org.apache.tools.ant.util;
+import java.util.Collection;
import java.util.Vector;
import java.util.Iterator;
import java.util.Dictionary;
@@ -93,6 +94,26 @@
}
/**
+ * Creates a comma separated list of all values held in the given
+ * collection.
+ *
+ * @since Ant 1.8.0
+ */
+ public static String flattenToString(Collection c) {
+ Iterator iter = c.iterator();
+ boolean first = true;
+ StringBuffer sb = new StringBuffer();
+ while (iter.hasNext()) {
+ if (!first) {
+ sb.append(",");
+ }
+ sb.append(String.valueOf(iter.next()));
+ first = false;
+ }
+ return sb.toString();
+ }
+
+ /**
* Dictionary does not know the putAll method. Please use Map.putAll().
* @param m1 the to directory.
* @param m2 the from directory.
Modified: ant/core/trunk/src/tests/antunit/core/magic-names-test.xml
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/core/magic-names-test.xml?rev=663061&r1=663060&r2=663061&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/core/magic-names-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/core/magic-names-test.xml Wed Jun 4
03:58:23 2008
@@ -21,6 +21,9 @@
<target name="default target"/>
+ <target name="setUp"
+ description="only here to force a second target into
testInvokedTargets' list"/>
+
<target name="testProjectName">
<au:assertPropertyEquals
name="ant.project.name" value="magicnames-test"/>
@@ -31,4 +34,18 @@
name="ant.project.default-target" value="default target"/>
</target>
+ <target name="testInvokedTargets">
+ <au:assertPropertyEquals
+ name="ant.project.invoked-targets" value="setUp,testInvokedTargets"/>
+ </target>
+
+ <target name="nested">
+ <au:assertPropertyEquals
+ name="ant.project.invoked-targets" value="nested"/>
+ </target>
+
+ <target name="testInvokedTargetsWithNestedAntcall">
+ <antcall target="nested"/>
+ </target>
+
</project>