2009-09-15 19 views

回答

1

如果使用-projecthelp ARG運行ant:

ant -projecthelp 

你會得到在build.xml中指定的主要對象的列表(或其他生成文件在命令行中聲明)。

12

基於the issue需要修補螞蟻或使用的javascript:

<target name="test"> 
    <script language="javascript"> 
    project.setNewProperty("current_target", self.getOwningTarget()); 
    </script> 
    <echo>${current_target}</echo> 
</target> 
+0

使用'setNewProperty()'將把'$ {current_target}'看作是不可變的(Ant通常是這樣工作的)。如果您想覆蓋'$ {current_target}'的值,請改用'setProperty()'。 – Scribblemacher 2016-09-22 16:45:12

2

我的回答已面市,採用antcontrib

<macrodef name="showtargetname"> 
    <attribute name="property"/> 
    <sequential> 

     <!-- make temporary variable --> 
     <propertycopy name="__tempvar__" from="@{property}"/> 

     <!-- Using Javascript functions to convert the string --> 
     <script language="javascript"> <![CDATA[ 
     currValue = [project-name].getThreadTask(java.lang.Thread.currentThread()).getTask().getOwningTarget().getName(); 
     [project-name].setProperty("__tempvar__", currValue); 
     ]]> 
     </script> 

     <!-- copy result --> 
     <var name="@{property}" value="${__tempvar__}"/> 

     <!-- remove temp var --> 
     <var name="__tempvar__" unset="true"/> 

    </sequential> 
    </macrodef> 

用法:

<showtargetname property="mycurrenttarget"/>