My build.xml有134个目标,其中大部分是隐藏的(hidden="true")。有没有办法从命令行列出所有目标?目标定义有时被拆分为多行,我通常使用双引号作为属性。我在Debian上运行这个,并为排序目标和/或显示描述而受到赞扬。:-)
示例:
<target name="example1" hidden="false" />
<target name="example3" hidden="true" />
<target
description="Ipsum lorem"
hidden="true"
name='example3'
>
<phingcall target="example1" />
</target>
我们不能用Phing做到这一点,但我们可以在Phing中。可能有一种更干净、更好的方法,但这是有效的——假设所有其他属性都用双引号包装(即仅通过上面的示例#3)
<target name="list_all" hidden="false">
<property name="command" value="
cat ${phing.file.foo}
| perl -pe 's|^s*||g'
| perl -0pe 's|n([^<])| 1|gs'
| grep '<target'
| perl -pe "s|name='([^']*)'|name="1"|g"
| perl -pe 's|^<target(s?)||'
| perl -pe 's|(.*)([ ]?)depends="([^"]*)"([ ]?)(.*)|1 2|g'
| perl -pe 's|(.*)([ ]?)hidden="([^"]*)"([ ]?)(.*)|1 2|g'
| perl -pe 's|.*description="([^"]*).*name="([^"]*).*|name="2" description="1"|g'
| perl -pe 's|name="([^"]*)"|1|g'
| perl -pe 's|description="([^"]*)"|[1]|g'
| sort
| uniq
" override="true" />
<exec command="${command}" passthru="true" />
</target>
这些线是干什么的?
1) 输出build.xml的内容。在这里,我对我的"global"build.xml感兴趣,它被命名为"foo";
2) 从每一行中删除所有前导空格;
3) 删除每个打开标签内的换行符;
4) 以"<target"开头的行的筛选器;
5) 将name属性上的单引号更改为双引号;
6,7,8)删除前导"<target",以及依赖和隐藏属性;
9) 在每行的"name"之后移动"description";
10) 删除"name="及其引号;
11) 将"description="及其引号替换为方括号;和
12、13)排序&删除重复的(如果有的话)
样本输出:
example1
example2
example3 [Ipsum lorem]
你不能用phing本身。如果目标设置为"隐藏",则代码会跳过显示。