将 7z 合并到 ANT 的宏定义中

发布于 2024-10-12 17:24:44 字数 1014 浏览 8 评论 0原文

我一直在使用宏定义将一组文件复制到不同的位置和 FTP 服务器。但复制似乎很慢,所以我想使用 7z 压缩该包并将所有内容作为一个文件复制到 FTP 中。用7z可以实现吗?我的 amcrodef 工作如下:

<macrodef name="copyimages">
  <attribute name="todir"/>
  <sequential>
    <copy todir="@{todir}" overwrite="true" failonerror="false">
      <fileset dir="${build.output.dir}">
                  <include name="logs/*${build.id}*armv5*scan2.html"/>
                  <include name="logs/*${build.id}*main.ant.log"/>
        <include name="logs/*${build.id}*bom.xml"/>
        <include name="logs/compile/*${build.id}*.*"/>
        <include name="logs/cone/*${build.id}*.*"/>
        <include name="logs/post/*${build.id}*.*"/>
        <include name="logs/roms/*${build.id}*.*"/>
        <include name="**/*${build.id}_codescanner/**"/>
      </fileset>
    </copy>
  </sequential>
</macrodef>


<copyimages todir="${publish.ssdoci.dir}/${env.version}.${build.number}"/>

I have been using a macro definition to copy a set of files to different locations and FTP servers. But copying seems quite slow so I want to compress the bundle using 7z and copy all into FTP as one single file. Can it be done using 7z? My amcrodef is below which works:

<macrodef name="copyimages">
  <attribute name="todir"/>
  <sequential>
    <copy todir="@{todir}" overwrite="true" failonerror="false">
      <fileset dir="${build.output.dir}">
                  <include name="logs/*${build.id}*armv5*scan2.html"/>
                  <include name="logs/*${build.id}*main.ant.log"/>
        <include name="logs/*${build.id}*bom.xml"/>
        <include name="logs/compile/*${build.id}*.*"/>
        <include name="logs/cone/*${build.id}*.*"/>
        <include name="logs/post/*${build.id}*.*"/>
        <include name="logs/roms/*${build.id}*.*"/>
        <include name="**/*${build.id}_codescanner/**"/>
      </fileset>
    </copy>
  </sequential>
</macrodef>


<copyimages todir="${publish.ssdoci.dir}/${env.version}.${build.number}"/>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

以酷 2024-10-19 17:24:44

如果您对 7z 不感兴趣,那么您可以使用 Zip任务

您可以尝试类似的方法而不是 ...

<zip destfile ="@{destfile}">
  <fileset dir="${build.output.dir}">
    <include name="logs/*${build.id}*armv5*scan2.html"/>
    <include name="logs/*${build.id}*main.ant.log"/>
    <include name="logs/*${build.id}*bom.xml"/>
    <include name="logs/compile/*${build.id}*.*"/>
    <include name="logs/cone/*${build.id}*.*"/>
    <include name="logs/post/*${build.id}*.*"/>
    <include name="logs/roms/*${build.id}*.*"/>
    <include name="**/*${build.id}_codescanner/**"/>
  </fileset>
</zip>

<copyimages destfile="${publish.ssdoci.file}-${env.version}.${build.number}"/>

If you are not particular about 7z, then you can use the Zip Task.

You could try something like this instead of <copy></copy...

<zip destfile ="@{destfile}">
  <fileset dir="${build.output.dir}">
    <include name="logs/*${build.id}*armv5*scan2.html"/>
    <include name="logs/*${build.id}*main.ant.log"/>
    <include name="logs/*${build.id}*bom.xml"/>
    <include name="logs/compile/*${build.id}*.*"/>
    <include name="logs/cone/*${build.id}*.*"/>
    <include name="logs/post/*${build.id}*.*"/>
    <include name="logs/roms/*${build.id}*.*"/>
    <include name="**/*${build.id}_codescanner/**"/>
  </fileset>
</zip>

<copyimages destfile="${publish.ssdoci.file}-${env.version}.${build.number}"/>
梦里人 2024-10-19 17:24:44

7zip 没有任务 - 和无法使用密码存档。
因此我的解决方案是

<target name="zip" depends="dist">
    <exec executable="C:\Program Files\7-Zip\7z.exe">
        <arg value="a" />                         <!--archive-->
        <arg value="-pMyPasswordt" />             <!-- password -->
        <arg value="-r" />                        <!-- recursiv -->
        <arg value="C:\temp\2012-06-29\${programName}.zip" />  <!-- destination -->
        <arg value="${jarFile}" />                <!-- files to archive -->
    </exec>
</target>

There is no task for 7zip - and <zip> cannot archive with password.
My solution is therefore

<target name="zip" depends="dist">
    <exec executable="C:\Program Files\7-Zip\7z.exe">
        <arg value="a" />                         <!--archive-->
        <arg value="-pMyPasswordt" />             <!-- password -->
        <arg value="-r" />                        <!-- recursiv -->
        <arg value="C:\temp\2012-06-29\${programName}.zip" />  <!-- destination -->
        <arg value="${jarFile}" />                <!-- files to archive -->
    </exec>
</target>
雨落□心尘 2024-10-19 17:24:44

根据apache.org,支持 7z。
来自 osdir.com 有关于实施 sevenz 任务的工作方式与使用 zip 的方式相同

使用 maven ?

<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
  <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-compress</artifactId>
    <version>1.8</version>
  </dependency>
  <dependency>
    <groupId>org.apache.ant</groupId>
    <artifactId>ant-compress</artifactId>
    <version>1.4</version>
  </dependency>

在蚂蚁

<taskdef resource="org/apache/ant/compress/antlib.xml" classpathref="maven.plugin.classpath"/>
<sevenz destfile ="my.7z">
  <fileset dir="${build.output.dir}">
    <include name="logs/*${build.id}*armv5*scan2.html"/>
    <include name="logs/*${build.id}*main.ant.log"/>
    <include name="logs/*${build.id}*bom.xml"/>
    <include name="logs/compile/*${build.id}*.*"/>
    <include name="logs/cone/*${build.id}*.*"/>
    <include name="logs/post/*${build.id}*.*"/>
    <include name="logs/roms/*${build.id}*.*"/>
    <include name="**/*${build.id}_codescanner/**"/>
  </fileset>
</sevenz>
<un7z src="my.7z" dest="unpack" />

According to apache.org there is support for 7z.
From osdir.com there are comments on implementing sevenz task that works the same way you would use zip

Using maven ?

<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
  <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-compress</artifactId>
    <version>1.8</version>
  </dependency>
  <dependency>
    <groupId>org.apache.ant</groupId>
    <artifactId>ant-compress</artifactId>
    <version>1.4</version>
  </dependency>

In ant

<taskdef resource="org/apache/ant/compress/antlib.xml" classpathref="maven.plugin.classpath"/>
<sevenz destfile ="my.7z">
  <fileset dir="${build.output.dir}">
    <include name="logs/*${build.id}*armv5*scan2.html"/>
    <include name="logs/*${build.id}*main.ant.log"/>
    <include name="logs/*${build.id}*bom.xml"/>
    <include name="logs/compile/*${build.id}*.*"/>
    <include name="logs/cone/*${build.id}*.*"/>
    <include name="logs/post/*${build.id}*.*"/>
    <include name="logs/roms/*${build.id}*.*"/>
    <include name="**/*${build.id}_codescanner/**"/>
  </fileset>
</sevenz>
<un7z src="my.7z" dest="unpack" />
岁月静好 2024-10-19 17:24:44

我想使用 7z.exe 和“exec”是最好的选择。

语法如下:

C:\Program Files\7-Zip>7z.exe a -t7z c:\temp\test.7z c:\temp*.txt

*此命令将所有 .txt文件从 c:\temp 归档到“test.7z”

干杯!

I guess using 7z.exe with "exec" is the best option.

Here is the syntax:

C:\Program Files\7-Zip>7z.exe a -t7z c:\temp\test.7z c:\temp*.txt

*this command put all .txt file from c:\temp to archive "test.7z"

Cheers!

风透绣罗衣 2024-10-19 17:24:44

这里有一个 7z ant 任务:http://www.pharmasoft.be/7z/

不过,还没有测试它,而且该网站似乎已经有点过时了。

There is a 7z ant task available here: http://www.pharmasoft.be/7z/

Did not test it, though, and the site seems already a little dated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文