2011-12-19 95 views
0

我的问题是,我必须从xml文件读取复制作业的源路径,然后将该目录中的所有文件从xml文件读取到另一个目录。从绝对路径蚂蚁复制从xml读取

由于代码是话多:

<xmltask source="${projectfile}"> 
    <copy path="Project/RecentResultsInfo/ResultsDirectoryOfRecentLoadTest/text()" property="recentdir" attrValue="true"/> 
</xmltask> 
<copy todir="${targetdirectory}"> 
    <fileset dir="${recentdir}"/> 
</copy> 

运行此目标时,输出为: C:\开发\ build.xml文件:44:警告:找不到资源文件“C:\开发\ C:\ Program \ tool \ test_90 \“进行复制。

它看起来在文件集中它不承认,recentdir里面保存了一个完整的路径。从应用程序写入的xml在用路径读取的xml文件中的路径前后有一个换行符。所以蚂蚁不会识别路径,因为它们前面有一个换行符。

蚂蚁有修饰吗?

任何人都可以帮助我让蚂蚁接受这条路吗?

回答

1

现在通过使用Ant-Contrib完成它,但是无论如何这都用在了这个项目中。

<xmltask source="${projectfile}"> 
    <copy path="Project/RecentResultsInfo/ResultsDirectoryOfRecentLoadTest/text()" property="recentdirraw" attrValue="true"/> 
</xmltask> 
<!-- replace newlines and whitespace from read path --> 
<propertyregex property="recentdir" input="${recentdirraw}" regexp="^[ \t\n]+|[ \t\n]+$" replace="" casesensitive="false" /> 
<copy todir="${targetdirectory}"> 
    <fileset dir="${recentdir}"/> 
</copy> 

只需用正则表达式修改属性,通过对空白和换行符进行条带化来修剪​​文本。

1

据我所见,xmltask中的复制元素提供了trim属性。

trims leading/trailing spaces when writing to properties 

这是否行得通?