【问题标题】:ant copy from absolute path read from xml从 xml 读取的绝对路径的 ant 副本
【发布时间】:2011-12-19 10:31:32
【问题描述】:

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

因为代码不仅仅是文字:

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

运行此目标时的输出是: C:\develop\build.xml:44: 警告:找不到要复制的资源文件“C:\develop\C:\Programme\tool\test_90\”。

似乎在它无法识别的文件集中,recentdir 包含一个完整路径。来自应用程序的写入 xml 在使用路径读取的 xml 文件中的路径之前和之后都有一个换行符。所以 ant 无法识别路径,因为它前面有一个换行符。

蚂蚁有什么修剪之类的吗?

谁能帮我让蚂蚁接受这条路?

【问题讨论】:

    标签: ant


    【解决方案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>
    

    只需使用正则表达式修改属性,通过删除空格和换行符来修剪文本。

    【讨论】:

      【解决方案2】:

      据我所知,xmltask 中的 copy 元素提供了一个 trim 属性。

      trims leading/trailing spaces when writing to properties
      

      这行得通吗?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-07
        • 2012-10-25
        • 1970-01-01
        相关资源
        最近更新 更多