Ant XML自定义文件夹名称
我不熟悉Ant和XML,我需要一些问题方面的帮助 我想创建一个根文件夹,其名称类似 [数字][时间戳][一些字符串]\u等 我将向您展示我的第一段代码,其中我只是从文件中读取值Ant XML自定义文件夹名称,xml,ant,ant-contrib,Xml,Ant,Ant Contrib,我不熟悉Ant和XML,我需要一些问题方面的帮助 我想创建一个根文件夹,其名称类似 [数字][时间戳][一些字符串]\u等 我将向您展示我的第一段代码,其中我只是从文件中读取值 <target name="create"> <loadfile srcfile="new.txt" property="fisier" /> <for param="line" list="${fisier}" delimiter="${line.separator}">
<target name="create">
<loadfile srcfile="new.txt" property="fisier" />
<for param="line" list="${fisier}" delimiter="${line.separator}">
<sequential>
<echo>@{line}</echo>
<propertyregex property="item"
input="${line}"
regexp="regexpToMatchSubstring"
select="\1"
casesensitive="false" />
</sequential>
</for>
</target>
@{line}
从我读取的值中,我需要用regexp减去一个字符串。我有一些像id=2344的东西,我只需要数字,意思是等号右边的字符串。如何实现这一点?使用通用编程语言实现这种需求要简单得多。您的示例演示了如何要求ant contrib库提供“for”ant任务 下面是一个替代实现,使用: 运行如下
build:
[groovy] 2222
[groovy] 2223
[groovy] 2224
data.txt
编译文件
新文件(“data.txt”).eachLine{line->
def num=line=~/.*=(\d+)/
println num[0][1]
}
注:
- 包括安装groovy任务所需的jar的附加目标。使构建更具可移植性
├── build.xml
└── data.txt
build:
[groovy] 2222
[groovy] 2223
[groovy] 2224
id=2222
id=2223
id=2224
<project name="demo" default="build">
<available classname="org.codehaus.groovy.ant.Groovy" property="groovy.installed"/>
<target name="install-groovy" unless="groovy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/groovy.jar" src="http://search.maven.org/remotecontent?filepath=org/codehaus/groovy/groovy-all/2.3.6/groovy-all-2.3.6.jar"/>
<fail message="Groovy installed run the build again"/>
</target>
<target name="build" depends="install-groovy">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
<groovy>
new File("data.txt").eachLine { line ->
def num = line =~ /.*=(\d+)/
println num[0][1]
}
</groovy>
</target>
</project>