如何列出Phing中的隐藏目标



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([^&lt;])| 1|gs'
        | grep '&lt;target'
        | perl -pe &quot;s|name='([^']*)'|name=&quot;1&quot;|g&quot;
        | perl -pe 's|^&lt;target(s?)||'
        | perl -pe 's|(.*)([ ]?)depends=&quot;([^&quot;]*)&quot;([ ]?)(.*)|1 2|g'
        | perl -pe 's|(.*)([ ]?)hidden=&quot;([^&quot;]*)&quot;([ ]?)(.*)|1 2|g'
        | perl -pe 's|.*description=&quot;([^&quot;]*).*name=&quot;([^&quot;]*).*|name=&quot;2&quot; description=&quot;1&quot;|g'
        | perl -pe 's|name=&quot;([^&quot;]*)&quot;|1|g'
        | perl -pe 's|description=&quot;([^&quot;]*)&quot;|[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本身。如果目标设置为"隐藏",则代码会跳过显示。

最新更新