如何列出Phing中的隐藏目标

时间:2015-03-19 12:57:08

标签: regex xml command-line phing

我的build.xml有134个目标,其中大部分是隐藏的(隐藏=" true")。有没有办法从命令行列出所有目标?目标定义有时会分为多行,我通常使用双引号字符作为属性。我在Debian上运行它,并且用于排序目标和/或显示描述。 : - )

示例:

    <target name="example1" hidden="false" />

    <target name="example3" hidden="true" />

    <target
        description="Ipsum lorem"
        hidden="true"
        name='example3'
    >
        <phingcall target="example1" />
    </target>

2 个答案:

答案 0 :(得分:1)

你不能用自己的语言。如果目标设置为&#34;隐藏&#34;。

,代码只会跳过显示

答案 1 :(得分:1)

我们无法使用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的内容。在这里,我对我的全球&#39;感兴趣。 build.xml,名为&#39; foo&#39;;

2)从每一行中删除所有前导空格;

3)删除每个开始标记中的换行符;

4)过滤行开始&#34;&lt; target&#34;;

5)将name-property上的单引号更改为double;

6,7,8)删除前导&#34;&lt; target&#34;,依赖和隐藏属性;

9)移动&#39;描述&#39; 之后&#39;姓名&#39;在每一行;

10)删除&#39; name =&#39;及其引号;

11)替换&#39; description =&#39;及其带方括号的引号;和

12,13)sort&amp;删除重复项(如果有)

示例输出:

    example1
    example2
    example3 [Ipsum lorem]