0

如果我能做这样的事情那就太棒了:

<macrodef name="process-target">
    <attribute name="target" default="?enclosing.target.name?" />
    ...
</macrodef>


<target name="myTarget>
    <process-target/>
</target>
4

2 回答 2

2

需要使用脚本来访问目标名称如下:

<project name="demo" default="run1">

    <macrodef name="process-target">
        <sequential>
            <script language="javascript">
            project.setProperty("enclosing.target.name", self.getOwningTarget());
            </script>
            <echo message="${enclosing.target.name}"/>
        </sequential>
    </macrodef>

    <target name="run1">
        <process-target/>
    </target>

    <target name="run2">
        <process-target/>
    </target>

</project>
于 2013-04-07T20:25:27.480 回答
0

我把它放在这里是因为我想在核心蚂蚁中有一个可选属性。

<macrodef name="process-target">
    <attribute name="target" default="_not_set_" />
    <sequential>
        <property name="_target_" value="@{target}" />
        <script language="javascript">
            if(project.getProperty("_target_") == "_not_set_") {
                project.setProperty("_target_", self.getOwningTarget());
            }
        </script>
        <echo message="${_target_}"/>
    </sequential>
</macrodef>
于 2013-04-08T23:16:59.550 回答