我如何可以通过两个可变在一个Ant目标由劈裂逗号 [英] How can i pass two variable in one Ant target by spliting commas
问题描述
我有一个 deploy.path1 = A,B,C,D,E
和 deploy.path2 = 1,2,3,4
,我想同时使用A和1一个目标部署像下面如意味着双方应可在同一时间就好了,1,那么下一次B,2等等...
I have one deploy.path1=A,B,C,D,E
and deploy.path2=1,2,3,4
and I want to use A and 1 in one target Deploy like below eg at one time means both should be available at same time like A,1 then next time B,2 and so on...
<target name"deploy">
<echo message="${A}"/>
<echo message="${1}"/>
</target>
我怎样才能做到这一点?
How can i do this?
目前我使用
<foreach list="${deploy.loc2}" param="deploy_javapass" target="copy_patch_javapass" delimiter="," inheritall="true" inheritrefs="true"
parallel="false" trim="true"/>
任务,但以这种方式,我们可以一次只传递一个参数。
task but in this way we can pass only one parameter at one time.
推荐答案
我很少使用蚂蚁的contrib 一>任务。如果您需要复杂的逻辑,我建议嵌入一个合适的脚本语言,例如常规任务。
I rarely use the ant-contrib tasks. If you need complex logic, I'd suggest embedding a proper scripting language, for example the groovy task.
下面的例子中调用的方式部署任务,你所描述:
The following example invokes the "deploy" task in the manner you've described:
<project name="demo" default="run">
<property name="deploy.path1" value="A,B,C,D,E"/>
<property name="deploy.path2" value="1,2,3,4,5"/>
<target name="run">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy">
<classpath>
<pathelement location="/path/to/groovy/jar/groovy-all-1.8.5.jar"/>
</classpath>
</taskdef>
<groovy>
def values1 = properties."deploy.path1".split(",")
def values2 = properties."deploy.path2".split(",")
values1.eachWithIndex { value1, i ->
properties.val1 = value1
properties.val2 = values2[i]
ant.project.executeTarget('deploy')
}
</groovy>
</target>
<target name="deploy">
<echo message="path1 = ${val1}"/>
<echo message="path2 = ${val2}"/>
</target>
</project>
用常春藤来管理第三方罐子增强例如
有关新的ANT安装,我增加了一个额外的目标,以构建文件:
Enhanced example using ivy to managed 3rd party jars
For new ANT installations, I added an extra target to the build file:
$ ant install-ivy
通过下载常春藤任务jar包,这将建立常春藤。
This will setup ivy by downloading the ivy task jar.
使用常春藤一个Ant任务结束杀。但是当你使用它来管理你的各种类路径超过不负有心人。
Using ivy for one ANT task is over-kill. However it more than pays off when you use it to manage your various classpaths.
Maven的中央有一个广阔的可供下载的开源库:
Maven central has a vast range of open source libraries available for download:
<project name="demo" default="run" xmlns:ivy="antlib:org.apache.ivy.ant">
<property name="deploy.path1" value="A,B,C,D,E"/>
<property name="deploy.path2" value="1,2,3,4,5"/>
<target name="install-ivy">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar"/>
</target>
<target name="init">
<ivy:resolve/>
<ivy:cachepath pathid="build.path" conf="build"/>
</target>
<target name="run" depends="init">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<groovy>
def values1 = properties."deploy.path1".split(",")
def values2 = properties."deploy.path2".split(",")
values1.eachWithIndex { value1, i ->
properties.val1 = value1
properties.val2 = values2[i]
ant.project.executeTarget('deploy')
}
</groovy>
</target>
<target name="deploy">
<echo message="path1 = ${val1}"/>
<echo message="path2 = ${val2}"/>
</target>
</project>
的ivy.xml
ivy文件列出了构建的依赖关系:
ivy.xml:
ivy file listing the build's dependencies:
<ivy-module version="2.0">
<info organisation="myorg" module="mymodule" />
<configurations>
<conf name="build" description="Build dependencies"/>
</configurations>
<dependencies>
<dependency org="org.codehaus.groovy" name="groovy-all" rev="1.8.5" conf="build->default"/>
</dependencies>
</ivy-module>
这篇关于我如何可以通过两个可变在一个Ant目标由劈裂逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!