使用文件名作为参数的纯ant为文件集中的每个文件调用任务(无contrib任务,无自己的任务)
问题: 如果您的文件遵循特定的命名约定(例如,包含区域设置),并且需要通过ant脚本对每个文件进行处理,那么ant中有哪些可能性 例如: 要处理的文件:使用文件名作为参数的纯ant为文件集中的每个文件调用任务(无contrib任务,无自己的任务),ant,Ant,问题: 如果您的文件遵循特定的命名约定(例如,包含区域设置),并且需要通过ant脚本对每个文件进行处理,那么ant中有哪些可能性 例如: 要处理的文件: 文件_en-US.txt 文件_en-GB.txt 应为所有文件调用一个任务,并将其文件名作为参数。文件名中包含的区域设置需要由正则表达式提取,并作为参数传递给外部工具。一旦你有了文件名,解压过程就会很简单 限制: 纯Ant(1.7),不允许任何扩展,不允许像foreach这样的自定义/contrib任务。每安装一个vanilla an
- 文件_en-US.txt
- 文件_en-GB.txt
- 纯Ant(1.7),不允许任何扩展,不允许像foreach这样的自定义/contrib任务。每安装一个vanilla ant(1.7)就需要运行一个
<property name="ivy.install.version" value="2.2.0" />
<property name="ivy.jar.dir" location="${user.home}/.ivy2/jars" />
<property name="ivy.jar.file" location="${ivy.jar.dir}/ivy-${ivy.install.version}.jar" />
<target name="-download-ivy" unless="ivy.downloaded">
<mkdir dir="${ivy.jar.dir}" />
<!-- download Ivy from web site so that it can be used even without any special installation -->
<echo message="installing ivy..." />
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}"
usetimestamp="true"
verbose="true" />
</target>
<target name="-check-ivy-downloaded">
<condition property="ivy.downloaded">
<and>
<available file="${ivy.jar.file}" />
<available file="${ivy.jar.dir}/jsch-0.1.44-1.jar" />
</and>
</condition>
</target>
<target name="-load-ivy" depends="-check-ivy-downloaded,-download-ivy" unless="ivy.loaded">
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar" />
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path" />
<property name="ivy.loaded" value="true" />
</target>
步骤4:加载ant contrib
<target name="-load-ant-contrib" depends="retrieve" unless="ant.contrib.loaded">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${ant-contrib.ant-contrib}" />
</classpath>
</taskdef>
<property name="ant.contrib.loaded" value="true" />
</target>
<target name="mytarget" depends="-load-ant-contrib">
<for param="file">
<fileset dir="somedir" includes="..." />
<sequential>
<!-- do stuff with @{file} -->
</sequential>
</for>
</target>
如果您只需要下载ant contrib,而不想使用Ivy管理其他依赖项,那么您可以跳过上面的大部分内容,只需使用a下载
ant contrib
,就像上面下载Ivy一样。它并没有完全回答我的问题,但它为我的问题提供了一个很好的解决方案/替代方案!谢谢
<target name="retrieve" description="retrieve dependancies with ivy" depends="-load-ivy">
<ivy:retrieve />
<ivy:artifactproperty name="[module].[artifact]" value="lib/[artifact]-[revision].[ext]" />
</target>
<target name="-load-ant-contrib" depends="retrieve" unless="ant.contrib.loaded">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${ant-contrib.ant-contrib}" />
</classpath>
</taskdef>
<property name="ant.contrib.loaded" value="true" />
</target>
<target name="mytarget" depends="-load-ant-contrib">
<for param="file">
<fileset dir="somedir" includes="..." />
<sequential>
<!-- do stuff with @{file} -->
</sequential>
</for>
</target>