5

私は一連のビルド ファイルを持っており、そのうちのいくつかは他のファイルを呼び出しており、最初にそれらをインポートしています。最終ビルドには、特定のターゲット (「copyother」など) がある場合とない場合があります。そのターゲットが行末ビルド スクリプト内で定義されている場合は、メイン ビルド ファイルから呼び出したいと思います。どうすればいいですか?

呼び出しスクリプトの一部:

<!-- Import project-specific libraries and classpath -->
<property name="build.dir" value="${projectDir}/build"/>
<import file="${build.dir}/build_libs.xml"/>

...

<!-- "copyother" is a foreign target, imported in build_libs.xml per project -->
<target name="pre-package" depends="    clean,
                                        init,
                                        compile-src,
                                        copy-src-resources,
                                        copy-app-resources,
                                        copyother,
                                        compile-tests,
                                        run-junit-tests"/>

すべてのプロジェクトで「copyother」ターゲットを定義する必要はありません。条件付きアリ呼び出しを行うにはどうすればよいですか?

4

3 に答える 3

1

完全性と同じです。別のアプローチは、ターゲットをチェックするためのターゲットを持つことです。

このアプローチについては、http ://ant.1045680.n5.nabble.com/Checking-if-a-Target-Exists-td4960861.html (vimil の投稿) で説明しています。チェックは scriptdef を使用して行われます。他の回答者(Jeanne Boyarsky)と大差ありませんが、スクリプトは簡単に追加できます。

<scriptdef name="hastarget" language="javascript">
    <attribute name="targetname"/>
    <attribute name="property"/>
    <![CDATA[
       var targetname = attributes.get("property");
       if(project.getTargets().containsKey(targetname)) {
            project.setProperty(attributes.get("property"), "true");
       }
     ]]>
</scriptdef>

<target name="check-and-call-exports">
    <hastarget targetname="exports" property="is-export-defined"/>
    <if>
        <isset property="is-export-defined"/>
        <then>
            <antcall target="exports"   if="is-export-defined"/>
        </then>
    </if>
</target>

<target name="target-that-may-run-exports-if-available" depends="check-and-call-exports">
于 2013-12-02T10:48:09.113 に答える
0

typefound1.7 で ANT に追加された条件の使用を検討する必要があります。たとえば、次のように antcontrib の if タスクで使用できますが、その仕組みにより、タスク定義ではなくマクロ定義をチェックする必要があります。

<if>
   <typefound name="some-macrodef"/>
<then>
   <some-macrodef/>
   </then>
</if>

これにより、「some-macro-or-taskdef」という名前のマクロ定義を持つ ant ファイルが呼び出され、それを持たない他の ant ファイルはエラーになりません。

于 2011-07-29T02:37:01.840 に答える