git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@663061 13f79535-47bb-0310-9956-ffa450edef68remotes/1776816827838153613/tmp_25f451bd36ab3145e487fcb2cd5c62c571e5b602
| @@ -74,6 +74,10 @@ Other changes: | |||||
| * a new property ant.project.default-target holds the value of the | * a new property ant.project.default-target holds the value of the | ||||
| current <project>'s default attribute. | 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 | Changes from Ant 1.7.0 TO Ant 1.7.1 | ||||
| ============================================= | ============================================= | ||||
| @@ -311,6 +311,11 @@ ant.project.default-target | |||||
| the name of the currently executing project's | the name of the currently executing project's | ||||
| default target; it is set via the default | default target; it is set via the default | ||||
| attribute of <project>. | 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 | ant.java.version the JVM version Ant detected; currently it can hold | ||||
| the values "1.2", "1.3", "1.4" and "1.5". | the values "1.2", "1.3", "1.4" and "1.5". | ||||
| </pre> | </pre> | ||||
| @@ -212,5 +212,14 @@ public final class MagicNames { | |||||
| public static final String PROJECT_DEFAULT_TARGET | public static final String PROJECT_DEFAULT_TARGET | ||||
| = "ant.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: {@value} | |||||
| * @since Ant 1.8.0 | |||||
| */ | |||||
| public static final String PROJECT_INVOKED_TARGETS | |||||
| = "ant.project.invoked-targets"; | |||||
| } | } | ||||
| @@ -45,6 +45,7 @@ import org.apache.tools.ant.types.Path; | |||||
| import org.apache.tools.ant.types.Resource; | import org.apache.tools.ant.types.Resource; | ||||
| import org.apache.tools.ant.types.ResourceFactory; | import org.apache.tools.ant.types.ResourceFactory; | ||||
| import org.apache.tools.ant.types.resources.FileResource; | 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.FileUtils; | ||||
| import org.apache.tools.ant.util.JavaEnvUtils; | import org.apache.tools.ant.util.JavaEnvUtils; | ||||
| import org.apache.tools.ant.util.StringUtils; | import org.apache.tools.ant.util.StringUtils; | ||||
| @@ -694,7 +695,7 @@ public class Project implements ResourceFactory { | |||||
| * no default target. | * no default target. | ||||
| */ | */ | ||||
| public void setDefault(String defaultTarget) { | public void setDefault(String defaultTarget) { | ||||
| setUserProperty(MagicNames.PROJECT_DEFAULT_TARGET, defaultTarget); | |||||
| setUserProperty(MagicNames.PROJECT_DEFAULT_TARGET, defaultTarget); | |||||
| this.defaultTarget = defaultTarget; | this.defaultTarget = defaultTarget; | ||||
| } | } | ||||
| @@ -1174,6 +1175,8 @@ public class Project implements ResourceFactory { | |||||
| * @exception BuildException if the build failed. | * @exception BuildException if the build failed. | ||||
| */ | */ | ||||
| public void executeTargets(Vector names) throws BuildException { | public void executeTargets(Vector names) throws BuildException { | ||||
| setUserProperty(MagicNames.PROJECT_INVOKED_TARGETS, | |||||
| CollectionUtils.flattenToString(names)); | |||||
| getExecutor().executeTargets(this, | getExecutor().executeTargets(this, | ||||
| (String[]) (names.toArray(new String[names.size()]))); | (String[]) (names.toArray(new String[names.size()]))); | ||||
| } | } | ||||
| @@ -17,6 +17,7 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.util; | package org.apache.tools.ant.util; | ||||
| import java.util.Collection; | |||||
| import java.util.Vector; | import java.util.Vector; | ||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import java.util.Dictionary; | import java.util.Dictionary; | ||||
| @@ -92,6 +93,26 @@ public class CollectionUtils { | |||||
| return true; | return true; | ||||
| } | } | ||||
| /** | |||||
| * 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(). | * Dictionary does not know the putAll method. Please use Map.putAll(). | ||||
| * @param m1 the to directory. | * @param m1 the to directory. | ||||
| @@ -21,6 +21,9 @@ | |||||
| <target name="default target"/> | <target name="default target"/> | ||||
| <target name="setUp" | |||||
| description="only here to force a second target into testInvokedTargets' list"/> | |||||
| <target name="testProjectName"> | <target name="testProjectName"> | ||||
| <au:assertPropertyEquals | <au:assertPropertyEquals | ||||
| name="ant.project.name" value="magicnames-test"/> | name="ant.project.name" value="magicnames-test"/> | ||||
| @@ -31,4 +34,18 @@ | |||||
| name="ant.project.default-target" value="default target"/> | name="ant.project.default-target" value="default target"/> | ||||
| </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> | </project> | ||||