【发布时间】:2013-10-01 11:23:13
【问题描述】:
我有一个使用 ant 的要求,即目标应提取以逗号分隔的两个参数,并在一个以分号分隔的类似参数对的长列表中提取。目前我正在做这样的事情:
<?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 循环参数中传递的第一个值。我犯了什么明显的错误吗?
谢谢, 马尼什·乔希
【问题讨论】:
-
您错过了关于 ant 的一个重要方面:它不是一种脚本语言。属性不是变量——它们是不可变的。您的要求与您的工具不匹配。 ant中没有参数。
-
ant中有参数。这就是 macrodef 的用途。这总是让我感到好笑,现在很少有人关注 macrodef 并尝试使用导致过于复杂和不可维护的 ant 脚本的目标来做所有事情。
标签: regex ant ant-contrib