如果我可以做类似的事情,那将是非常棒的。
<macrodef name="process-target">
<attribute name="target" default="?enclosing.target.name?" />
...
</macrodef>
<target name="myTarget>
<process-target/>
</target>
答案 0 :(得分: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>
答案 1 :(得分: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>