是否有一种访问ANT任务的结果文件集的通用方法?

是否有一种访问ANT任务的结果文件集的通用方法?,ant,fileset,Ant,Fileset,我正在尝试编写一个集成任务的替代程序,以便它支持使用和7za.exe的密码。我们的想法是用一个drop-in替换任务 困难在于,支持多种方式来声明要包含/排除哪些文件,例如: 包括 includefile 排除 excludesfile defaultexcludes 和嵌套的声明 有没有办法在exec任务中使用这些文件集指令的结果?未记录的属性${toString:filesetid}包含所有文件,默认分隔符为“;”要转换分隔符的使用,结果属性将包含选择分隔符的文件,f.e.: <f

我正在尝试编写一个集成
任务的替代程序,以便它支持使用
7za.exe
的密码。我们的想法是用一个drop-in替换
任务

困难在于,
支持多种方式来声明要包含/排除哪些文件,例如:

  • 包括
  • includefile
  • 排除
  • excludesfile
  • defaultexcludes
  • 和嵌套的
    声明

有没有办法在exec任务中使用这些
文件集
指令的结果?

未记录的属性
${toString:filesetid}
包含所有文件,默认分隔符为“;”
要转换分隔符的使用,结果属性将包含选择分隔符的文件,f.e.:

<fileset dir="C:/diff1" includes="**/*.html" id="diff">
 <different targetdir="C:/diff2"
   ignoreFileTimes="true"/>
</fileset>

<!-- one file one line -->
<pathconvert refid="diff" pathsep="${line.separator}" property="htmldiff"/>

<!-- blank as separator -->
<pathconvert refid="diff" pathsep=" " property="htmldiff"/>  

<echo file="C:/diff1/htmldiff.txt">${htmldiff}</echo>

${htmldiff}
在带有arg行的exec中使用空格作为分隔符似乎是合适的。

基于此,我能够想出一个类似于集成
任务的解决方案。使用
和单引号可以实现以下目的:

<macrodef name="sevenzip" description="Command line interface for 7zip">
    <attribute name="level"  default="5"/> <!-- will be ignored for now, just to make it compatible with normal ZIP task -->
    <attribute name="basedir"/>
    <attribute name="excludes" default=""/>
    <attribute name="includes" default="**/**"/>
    <attribute name="destfile"/>
    <attribute name="password" default=""/>

    <sequential>
        <description>7-Zip integration</description>
        <local name="passArg" />
        <if>
            <equals arg1="@{password}" arg2=""/>
            <then>
                <property name="passArg" value="" />
            </then>
            <else>
                <!-- p<SECRET> = set password of archive -->
                <property name="passArg" value='"-p@{password}"' />
            </else>
        </if>

        <fileset id="mask" dir="@{basedir}">
            <include name="@{includes}" />
            <exclude name="@{excludes}" />
        </fileset>

        <local name="mask" />
        <pathconvert property="mask" refid="mask" pathsep="' '" />
        <!-- the single quotes help to wrap file names containing spaces -->

        <exec executable="${7zip.cmd}" failonerror="true">
            <!-- command -->
            <arg value="a"/>                <!-- a : add files to archive -->
            <!-- arg value="u"/ -->             <!-- u : update files to archive -->

            <!-- switches -->
            <arg value="-bd"/>              <!-- -bd : disable percentage indicator -->
            <arg value="-tzip"/>            <!-- -t<type> : set type of archive -->             

            <arg value="${passArg}"/>       

            <arg value="--"/>               <!-- : Stop switches parsing -->

            <!-- archive file -->
            <arg value="@{destfile}"/>

            <!-- file names / wildcards -->
            <arg line="'${mask}'"/>
            <!-- 
                the single quotes are the outter wrapper for the single quotes
                from pathconvert, the line attribute add the result to the arguments
                but NOT as a single escaped string
            -->

        </exec>
    </sequential>
</macrodef>

7-Zip集成

谢谢你的回答。我的解决方案就是这样的。