私は、定義が発生する可能性のある場所のウェブにつながる追加のスクリプトをインポートする他のスクリプトをインポートするantスクリプトを持っています。
ant はすべての定義を取り込み、maven のようにファイルを出力できますhelp:effective-pom
か?
これをビルドの出力ファイルとして追加して、デバッグを少し簡単にしたいと思います。
私は、定義が発生する可能性のある場所のウェブにつながる追加のスクリプトをインポートする他のスクリプトをインポートするantスクリプトを持っています。
ant はすべての定義を取り込み、maven のようにファイルを出力できますhelp:effective-pom
か?
これをビルドの出力ファイルとして追加して、デバッグを少し簡単にしたいと思います。
その種類のファイルを作成する別のターゲットを作成できます。たとえば、次のようになります。
main build.xml はいくつかの作業を行い、効果的なビルドを生成することもできます:
<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(/<project.*/, '').replaceAll(/<\/project.*/, '')
buildXmlContent = buildXmlContent.replaceFirst(/<import.*/, replacement)
}
}
}
new File('build.effective.xml') << buildXmlContent
</groovy>
</target>
</project>
テスト用に作成された 2 つの build.xml:
<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>
実行ant effective.build
すると、次の内容の新しいbuild.effective.xml
ファイルが取得されます。
<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(/<project.*/, '').replaceAll(/<\/project.*/, '')
buildXmlContent = buildXmlContent.replaceFirst(/<import.*/, replacement)
}
}
}
new File('build.effective.xml') << buildXmlContent
</groovy>
</target>
</project>
この目的のために groovy を選択しました (実際に学習したため) が、別の言語で作成することもできます。この groovy コードを ant タスクにコンパイルして、新しいタスクとして使用することもできます<effectiveant outfile="build.effective.xml">
。私の例は完璧ではありませんが、解決策の 1 つを示しています。