繁体   English   中英

Ant不可变属性为可变

[英]Ant immutable properties to mutable

我有个问题。 我使用antrun插件为maven做下一步:我有文件夹和子文件夹(我不知道所谓的子文件夹及其编号),我正在为这个子文件夹存档及其名称(子文件夹名称 - “1 “,存档名称 - ”1.acp“)。

               <tasks>
                  <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${settings.localRepository}/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar" />
                  <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${settings.localRepository}/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar" />
                  <for param="file">
                      <path>
                          <dirset dir="src/main/bootstrap" includes="/*" />
                      </path>
                      <sequential>
                          <basename property="dir" file="@{file}" />
                          <zip destfile="${project.build.outputDirectory}/alfresco/extension/agilent/${dir}.acp" basedir="@{file}" />
                      </sequential>
                  </for>
              </tasks>

但属性目录是不可改变的! 并且所有存档都有名称“1.acp”。 如何使这个属性变得可变或以另一种方式做到这一点?

您可以使用1.8 Ant的本地任务

在你的情况下:

<sequential>
  <local name="dir"/>
  <basename property="dir" file="@{file}"/>
  <zip
    destfile="${project.build.outputDirectory}/alfresco/extension/agilent/${dir}.acp" 
    basedir="${dir}"
  />
</sequential>

您可以使用ant contrib中的var任务

该属性未unset ,允许您重置值(例如从上面的链接):

    <property name="x" value="6"/>
    <echo>${x}</echo>   <!-- will print 6 -->
    <var name="x" unset="true"/>
    <property name="x" value="12"/>
    <echo>${x}</echo>   <!-- will print 12 -->

所以你必须修复它:

 <sequential>
   <var name="dir" unset="true"/>
   <basename property="dir" file="@{file}" />
   <zip destfile="${project.build.outputDirectory}/alfresco/extension/agilent/${dir}.acp" basedir="@{file}" />
 </sequential>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM