蚂蚁能产生包括类似Maven的有效POM全部进口统一的脚本? [英] Can ant generate a unified script including all imports similar to maven's effective pom?

查看:138
本文介绍了蚂蚁能产生包括类似Maven的有效POM全部进口统一的脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有哪些进口导入其他脚本导致了地方的定义可能发生的网络其它脚本的Ant脚本。

I have an ant script that imports other scripts which import additional scripts leading to web of places where definitions can happen.

可以在所有的定义和输出文件很像Maven的蚂蚁拉求助:有效-POM

Can ant pull in all the definitions and output a file much like maven's help:effective-pom?

我想用我的版本添加为一个输出文件,使调试比较容易。

I'd like to add this as an output file with my build to make debugging somewhat easier.

推荐答案

您可以创建另一个目标,这将创建一个类型的文件。例如,它可以是这样的:

You can create another target which will create that kind of file. For example it can look like this:

主要的build.xml其中做了一些工作,也可以产生有效的构建:

main build.xml which do some work and also can generate effective build:

<project name="testxml" default="build">

    <import file="build1.xml" />
    <import file="build2.xml" />

    <target name="build">
        <echo>build project</echo>
    </target>

    <target name="effective.build">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpath="C:\Program Files (x86)\groovy-2.1.4\embeddable\groovy-all-2.1.4.jar" />
        <groovy>
            def regex = ~/import file="(.*)"/
            def buildXmlContent = new File('build.xml').text
            new File('build.xml').eachLine {
                line -> regex.matcher(line).find() {
                    def file = new File(it[1])
                    if (file.exists()) {
                        def replacement = file.getText().replaceAll(/&lt;project.*/, '').replaceAll(/&lt;\/project.*/, '')
                        buildXmlContent = buildXmlContent.replaceFirst(/&lt;import.*/, replacement)
                    }
                }
            }
            new File('build.effective.xml') &lt;&lt; buildXmlContent
        </groovy>
    </target>

</project>

两对的build.xml创建测试的:

Two build.xml's created for tests:

<project name="testxml2" default="build">
    <target name="clean">
        <echo>clean project</echo>
    </target>
</project>

<project name="testxml1" default="build">
    <target name="test">
        <echo>test project</echo>
    </target>
</project>

如果您运行蚂蚁effective.build 你会得到新的 build.effective.xml 这个文件的内容

If you will run ant effective.build you will get new build.effective.xml file with this content:

<project name="testxml" default="build">


    <target name="test">
        <echo>test project</echo>
    </target>


    <target name="clean">
        <echo>clean project</echo>
    </target>


    <target name="build">
        <echo>build project</echo>
    </target>

    <target name="effective.build">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpath="C:\Program Files (x86)\groovy-2.1.4\embeddable\groovy-all-2.1.4.jar" />
        <groovy>
            import java.util.regex.Pattern

            def regex = ~/import file="(.*)"/
            def buildXmlContent = new File('build.xml').text
            new File('build.xml').eachLine {
                line -> regex.matcher(line).find() {
                    def file = new File(it[1])
                    if (file.exists()) {
                        def replacement = file.getText().replaceAll(/&lt;project.*/, '').replaceAll(/&lt;\/project.*/, '')
                        buildXmlContent = buildXmlContent.replaceFirst(/&lt;import.*/, replacement)
                    }
                }
            }
            new File('build.effective.xml') &lt;&lt; buildXmlContent
        </groovy>
    </target>

</project>

我选择常规(因为我了解它实际上)用于此目的,但你可以在其他langage创建它。您也可以编译这个时髦code到Ant任务,并以此为新的任务,例如&LT; effectiveant OUTFILE =build.effective.xml&GT; 。我的例子是不完美的,但它显示了解决方案之一。

I chose groovy (because I learn it actually) for this purpose but you can create it in another langage. You can also compile this groovy code to ant task and use it as new task, for example <effectiveant outfile="build.effective.xml">. My example isn't perfect but it shows one of the solutions.

这篇关于蚂蚁能产生包括类似Maven的有效POM全部进口统一的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆