Incorporating 7z in macrodef in ANT

2.2k Views Asked by At

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}"/>
5

There are 5 best solutions below

2
Raghuram On

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}"/>
0
neo-av-in On

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!

0
Olivier Faucheux On

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>
0
Jörg On

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.

0
Greg Domjan On

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" />