0

私はantを使用して、ターゲットがカンマで区切られた2つのパラメータを、セミコロンで区切られた類似のパラメータのペアの長いリストで抽出する必要があるという要件があります。現在、私は次のようなことをしています:

<?xml version="1.0"?>

<project name="" basedir="." default="test" xmlns:ac="antlib:net.sf.antcontrib">
<target name="test" >
<echo message="Hey There I am using What's App" />
<ac:for list="asdfg,dasfdf;vxxexqxx,hyyypyly;dksfgsgdgf,abaifuacu" delimiter=";" param="val">
<ac:sequential>
<ac:propertyregex property="param1"
            input="@{val}"
            regexp="([^\.]*)\,.*"
            select="\1"
            casesensitive="true" />
<ac:propertyregex property="param2"
            input="@{val}"
            regexp=".*,([^\.]*)"
            select="\1"
            casesensitive="true" />
<echo message = "val = ${param1}"/>
<echo message = "value = ${param2}"/>
</ac:sequential>
</ac:for>
</target>
</project>

しかし、私は次のように出力を得ています:

Buildfile: /tmp/Manish/build.xml

test:
 [echo] Hey There I am using What's App
 [echo] val = asdfg
 [echo] value = dasfdf
 [echo] val = asdfg
 [echo] value = dasfdf
 [echo] val = asdfg
 [echo] value = dasfdf

したがって、これは 3 回 (正しい) ループされますが、for ループ パラメーターで渡された最初の値のみによって行われます。私が犯している明らかな間違いはありますか?

ありがとう、マニッシュ・ジョシ

4

5 に答える 5

2

for の代わりに foreach を使用してみて、propertyregex を別のターゲットに配置してください。これは私のantスクリプトの例です。基本的に同じことを行います。

<target name="loadTestStatic" depends="setTargetEnv,setPassword">
    <loadfile property="controlFile" srcFile="${projectDir}/test/config/static/controlFile.txt"/>

    <foreach list="${controlFile}" delimiter="${line.separator}" param="descriptor" target="loadConfig"/>
</target>

<target name="loadConfig">
    <if>
        <matches string="${descriptor}" pattern="^camTool:"/>
        <then>
            <propertyregex property="camToolFile"
                           input="${descriptor}"
                           regexp="camTool:(.*)"
                           select="\1"
                           casesensitive="false" />
            <echo message="Got cam tool file ${camToolFile}"/>
            <camTool file="${camToolFile}"/>
        </then>
        <else>
            <!-- todo: add CM Tool, SQL as required -->
            <echo message="Unexpected config ${descriptor} ignored"/>
        </else>
    </if>
</target>
于 2014-03-12T14:52:55.993 に答える
0
<target name="myTarget">
        <ac:propertyregex property="param1"
                input="${myValue}"
                regexp="([^\.]*)\,.*"
                select="\1"
                casesensitive="true" />
        <ac:propertyregex property="param2"
                input="${myValue}"
                regexp=".*,([^\.]*)"
                select="\1"
                casesensitive="true" />
        <echo message = "val = ${param1}"/>
        <echo message = "value = ${param2}"/>
    </target>

    <ac:for list="asdfg,dasfdf;vxxexqxx,hyyypyly;dksfgsgdgf,abaifuacu" delimiter=";" param="val">
    <ac:sequential>
        <antcall target="myTarget">
            <param name="myValue" value="@{val}" />
        </antcall>  
    </ac:sequential>
    </ac:for>
于 2015-06-19T13:33:19.703 に答える
0

または、Ant アドオンFlaka、 feを使用します。

<project xmlns:fl="antlib:it.haefelinger.flaka">

<!-- with cvs property -->
<property name="foobar" value="asdfg,dasfdf;vxxexqxx,hyyypyly;dksfgsgdgf,abaifuacu"/>
 <fl:for var="item" in="split('${foobar}', ';')">
  <fl:let>
   param1 ::= split(item, ',')[0]
   param2 ::= split(item, ',')[1]
  </fl:let>
  <echo>
   $${param1} => ${param1}
   $${param2} => ${param2}
  </echo>
 </fl:for>

 <!-- with list inline -->
 <fl:for var="item" in="split('asdfg,dasfdf;vxxexqxx,hyyypyly;dksfgsgdgf,abaifuacu', ';')">
  <fl:let>
   param1 ::= split(item, ',')[0]
   param2 ::= split(item, ',')[1]
  </fl:let>
  <echo>
   $${param1} => ${param1}
   $${param2} => ${param2}
  </echo>
 </fl:for>

</project>

param1 ::= split(item, ',')[0] の double '::' は既存のプロパティ (コマンドライン引数として -Dkey=value で定義されたユーザー プロパティも含む) をオーバーライドすることを意味し、':=' はプロパティを作成することに注意してください。ただし、プロパティが既に存在する場合は上書きされません。

于 2013-11-05T12:03:48.227 に答える
-1

Ant のプロパティは不変です。プロパティの設定を解除するには、ant-contribの変数 taskを使用する必要があります(推奨されませんが)。

<ac:for list="asdfg,dasfdf;vxxexqxx,hyyypyly;dksfgsgdgf,abaifuacu" delimiter=";" param="val">
<ac:sequential>
<ac:propertyregex property="param1"
            input="@{val}"
            regexp="([^\.]*)\,.*"
            select="\1"
            casesensitive="true" />
<ac:propertyregex property="param2"
            input="@{val}"
            regexp=".*,([^\.]*)"
            select="\1"
            casesensitive="true" />
<echo message = "val = ${param1}"/>
<echo message = "value = ${param2}"/>
<ac:var name="param1" unset="true"/>
<ac:var name="param2" unset="true"/>
</ac:sequential>
</ac:for>
于 2013-10-01T14:05:05.510 に答える