Ant Task: zip

J

Jason Cavett

I have a directory structure similar to this:

themes
- theme1
- theme2
- theme3
- ...

I want to be able to use Ant to deploy the themes. Each theme,
however, needs to be deployed as its own separate zip file. Is this
even possible using Ant. It would appear that I need some sort of
loop, but I don't see this as part of Ant (at least from my research).

Thanks for any help.
 
R

Roedy Green

I want to be able to use Ant to deploy the themes. Each theme,
however, needs to be deployed as its own separate zip file. Is this
even possible using Ant. It would appear that I need some sort of
loop, but I don't see this as part of Ant (at least from my research).

see http://mindprod.com/jgloss/ant.html
and look at the sample ant scripts that build zip files.
 
J

Jason Cavett

seehttp://mindprod.com/jgloss/ant.html
and look at the sample ant scripts that build zip files.

Ah...I forgot to mention - I have no knowledge of the theme names
ahead of time. I need to figure them out and then zip each one up
individually.

That's my real problem. I know how to zip files in Ant, just not an
arbitrary amount of files with arbitrary names.
 
J

John B. Matthews

[...]
Ah...I forgot to mention - I have no knowledge of the theme names
ahead of time. I need to figure them out and then zip each one up
individually.

That's my real problem. I know how to zip files in Ant, just not an
arbitrary amount of files with arbitrary names.

You might look at mapping file names, glob or regexp:

<http://ant.apache.org/manual/CoreTypes/mapper.html>

Absent that, Exec a suitable shell script:

for x in `ls -1` ; do zip $x.zip $x ; done

John
 
R

Roedy Green

That's my real problem. I know how to zip files in Ant, just not an
arbitrary amount of files with arbitrary names.

generate the script with a little Java program, or build the Zips with
a little Java program.
 
M

Michael Justin

Jason said:
I have a directory structure similar to this:

themes
- theme1
- theme2
- theme3
- ...

I want to be able to use Ant to deploy the themes. Each theme,
however, needs to be deployed as its own separate zip file. Is this
even possible using Ant. It would appear that I need some sort of
loop, but I don't see this as part of Ant (at least from my research).

Thanks for any help.

Ant supports iterators and macro definitions,

http://ant.apache.org/manual/CoreTasks/subant.html

Check the example which defines a macro to iterate all directories which
contain a build.xml:

<macrodef name="iterate">
<attribute name="target"/>
<sequential>
<subant target="@{target}">
<fileset dir="modules" includes="*/build.xml"/>
</subant>
</sequential>
</macrodef>

(etc. ...)

The advantage is that you can control which theme is included in the
distribution just by copying the build.xml to it.

The build.xml itself is almost empty, it just calls a common.xml build
file in a parent directory.

Hope this helps(tm)
 
J

Jason Cavett

If you just want to zip up all your sub folders, you can do something like:

<project name="fun with themes">

<target name="zip-theme">
        <basename file="${basedir}" property="theme-name" />
        <zip destfile="../${theme-name}.zip"
                basedir="${basedir}"
                />
</target>

<target name="zip-themes">
        <subant genericantfile="${ant.file}"
                        target="zip-theme">
                <dirset dir="${basedir}"
                        includes="*"
                        />
        </subant>
</target>

</project>

If you need to get fancier, just put a more specific selector on your  
dirset so that it can figure out which directories are theme directories.

HTH,

-Zig

Very cool. Thank you very much for your help. (Glad that I now know
about subant, too. Didn't realize that even existed.)
 
J

Jason Cavett

Ant supports iterators and macro definitions,

http://ant.apache.org/manual/CoreTasks/subant.html

Check the example which defines a macro to iterate all directories which
contain a build.xml:

<macrodef name="iterate">
   <attribute name="target"/>
   <sequential>
     <subant target="@{target}">
       <fileset dir="modules" includes="*/build.xml"/>
     </subant>
   </sequential>
</macrodef>

(etc. ...)

The advantage is that you can control which theme is included in the
distribution just by copying the build.xml to it.

The build.xml itself is almost empty, it just calls a common.xml build
file in a parent directory.

Hope this helps(tm)

Awesome. Thanks for pointing out subant. That does what I need it to
do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top