3

プロパティ ファイルをロードし、そこから 1 つのプロパティを読み取る Ant スクリプトを作成する必要があります。値 (複数行) は次のようなものです。

path/to/file1a;path/to/file1b,
path/to/file2a;path/to/file2b,
..
..

すべての行を繰り返し処理し、次のようなシェル コマンドを実行する必要があります。

myCommand -param1 path/to/file1a -param2 path/to/file1b  #Command inside a single iteration

ループする方法を理解できました:

<for list="${ValueFromPropertyFile}" param="a">  
    <sequential>
        <exec executable="myCommand">
            <arg value="-param1" />
            <arg value="----  split(@{a}, ";")[0]  ----" />
            <arg value="-param2" />
            <arg value="----  split(@{a}, ";")[1]  ----" />
        </exec>
    </sequential>
</for>

私の意見では、これは非常に単純な作業です。検索してみましたが、成功しませんでした。

誰かがこれを手伝ってくれるか、関連するドキュメントを教えてくれれば幸いです。

どうもありがとう、

プラティック

4

1 に答える 1

2

あなたの仮定に関するいくつかの問題:

  1. 入力ファイルの形式は標準の Java プロパティ ファイルではないため、ANTの標準のloadproperties タスクを使用してロードすることはできません。
  2. ANT はプログラミング言語ではありません。引用した「for」タスクはコア ANT の一部ではありません (サードパーティの ant-contrib.jar が必要です)

したがって、埋め込みスクリプトを使用して問題を解決することをお勧めします。

プロジェクトは自己文書化されています:

$ ant -p
Buildfile: /home/mark/tmp/build.xml

    This is a demo project answering the following stackoverflow question:
    http://stackoverflow.com/questions/14625896

    First install 3rd party dependencies and generate the test files

        ant bootstrap generate-test-files

    Then run the build

        ant

    Expect the following output

        parse-data-file:
            [exec] build/myCommand -param1 path/to/file1a -param2 path/to/file1b
            [exec] build/myCommand -param1 path/to/file2a -param2 path/to/file2b

build.xml

<project name="demo" default="parse-data-file">

    <description>
    This is a demo project answering the following stackoverflow question:
    http://stackoverflow.com/questions/14625896

    First install 3rd party dependencies and generate the test files

        ant bootstrap generate-test-files

    Then run the build

        ant

    Expect the following output

        parse-data-file:
            [exec] build/myCommand -param1 path/to/file1a -param2 path/to/file1b
            [exec] build/myCommand -param1 path/to/file2a -param2 path/to/file2b

    </description>

    <target name="bootstrap" description="Install 3rd party dependencies">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/groovy-all.jar" src="http://search.maven.org/remotecontent?filepath=org/codehaus/groovy/groovy-all/2.1.0/groovy-all-2.1.0.jar"/>
    </target>

    <target name="generate-test-files" description="Generate the input data and sample script">
        <echo file="build/input.txt">path/to/file1a;path/to/file1b,
path/to/file2a;path/to/file2b,</echo>

        <echo file="build/myCommand"> #!/bin/bash
echo $0 $*</echo>

        <chmod file="build/myCommand" perm="755"/>
    </target>

    <target name="parse-data-file" description="Parse data file">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>

        <groovy>
            new File("build/input.txt").eachLine { line ->
                def fields = line.split(/[;,]/)

                ant.exec(executable:"build/myCommand") {
                    arg(value:"-param1")
                    arg(value:fields[0])
                    arg(value:"-param2")
                    arg(value:fields[1])
                }
            }
        </groovy>
    </target>

    <target name="clean" description="Cleanup build files">
        <delete dir="build"/>
    </target>

</project>
于 2013-01-31T21:52:33.273 に答える