alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Ant example source code file (unzip.xml)

This example Ant source code file (unzip.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Ant tags/keywords

bugzilla, bugzilla, report, report, unicodebig, unicodebig

The unzip.xml source code

<?xml version="1.0"?>

<project name="xxx-test" basedir="." default="test1">

  <target name="cleanup">
    <delete file="asf-logo.gif" />
    <delete file="unziptest.zip"/>
    <delete dir="unziptestin"/>
    <delete dir="unziptestout"/>
  </target>

  <target name="test1">
    <unzip/>
  </target>

  <target name="test2">
    <unzip src=""/>
  </target>

  <target name="test3">
    <unzip dest=""/>
  </target>

  <target name="testZipTask">
    <ant antfile="zip.xml" target="feather" />
    <unzip src="asf-logo.gif.zip" dest="." />
    <ant antfile="zip.xml" target="cleanup" />
  </target>

  <target name="testUncompressedZipTask">
    <ant antfile="zip.xml" target="uncompressed-feather" />
    <unzip src="asf-logo.gif.zip" dest="." />
    <ant antfile="zip.xml" target="cleanup" />
  </target>

  <target name="realTest">
    <unzip src="expected/asf-logo.gif.zip" dest="." />
  </target>

  <target name="prepareTestZip">
    <mkdir dir="unziptestin/1"/>
    <mkdir dir="unziptestin/2"/>
    <touch file="unziptestin/1/foo"/>
    <touch file="unziptestin/2/bar"/>
    <zip destfile="unziptest.zip" basedir="unziptestin"/>
  </target>

  <target name="testPatternSetExcludeOnly" depends="prepareTestZip">
    <unzip dest="unziptestout" src="unziptest.zip">
      <patternset>
        <exclude name="1/**"/>
      </patternset>
    </unzip>
  </target>

  <target name="testPatternSetIncludeOnly" depends="prepareTestZip">
    <unzip dest="unziptestout" src="unziptest.zip">
      <patternset>
        <include name="2/**"/>
      </patternset>
    </unzip>
  </target>

  <target name="testPatternSetIncludeAndExclude" depends="prepareTestZip">
    <unzip dest="unziptestout" src="unziptest.zip">
      <patternset>
        <include name="2/**"/>
        <exclude name="2/**"/>
      </patternset>
    </unzip>
  </target>

  <target name="testTwoPatternSets" depends="prepareTestZip">
    <unzip dest="unziptestout" src="unziptest.zip">
      <patternset>
        <include name="2/**"/>
      </patternset>
      <patternset>
        <include name="3/**"/>
      </patternset>
    </unzip>
  </target>

  <target name="testTwoPatternSetsWithExcludes" depends="prepareTestZip">
    <unzip dest="unziptestout" src="unziptest.zip">
      <patternset>
        <include name="2/**"/>
      </patternset>
      <patternset>
        <exclude name="1/**"/>
        <exclude name="2/**"/>
      </patternset>
    </unzip>
  </target>

  <target name="selfExtractingArchive">
    <mkdir dir="unziptestout"/>
    <unzip dest="unziptestout" src="zip/test.exe"/>
  </target>

  <!-- Bugzilla Report 20969 -->
  <target name="testPatternSetSlashOnly" depends="prepareTestZip">
    <unzip dest="unziptestout" src="unziptest.zip">
      <patternset>
        <include name="2/"/>
      </patternset>
    </unzip>
  </target>

  <!-- Bugzilla Report 10504 -->
  <target name="encodingTest">
    <mkdir dir="unziptestin"/>
    <touch file="unziptestin/foo"/>
    <zip zipfile="unziptest.zip" basedir="unziptestin" encoding="UnicodeBig"/>
    <mkdir dir="unziptestout"/>
    <unzip src="unziptest.zip" dest="unziptestout" encoding="UnicodeBig"/>
  </target>

  <!-- Bugzilla Report 21996 -->
  <target name="testFlattenMapper" depends="prepareTestZip">
    <unzip dest="unziptestout" src="unziptest.zip">
      <patternset>
        <include name="1/**"/>
      </patternset>
      <mapper type="flatten"/>
    </unzip>
  </target>

  <!-- Bugzilla Report 21996 -->
  <target name="testGlobMapper" depends="prepareTestZip">
    <unzip dest="unziptestout" src="unziptest.zip">
      <patternset>
        <include name="1/**"/>
      </patternset>
      <mapper type="glob" from="*" to="*.txt"/>
    </unzip>
  </target>

  <target name="testTwoMappers" depends="prepareTestZip">
    <unzip dest="unziptestout" src="unziptest.zip">
      <patternset>
        <include name="1/**"/>
      </patternset>
      <mapper type="glob" from="*" to="*.txt"/>
      <mapper type="flatten"/>      
    </unzip>
  </target>

  <target name="testResourceCollection">
    <unzip dest="unziptestout">
      <patternset>
        <include name="junit/**"/>
      </patternset>
      <restrict>
        <path path="${java.class.path}"/>
        <type type="file" xmlns="antlib:org.apache.tools.ant.types.resources.selectors"/>
      </restrict>
    </unzip>
  </target>

  <target name="testDocumentationClaimsOnCopy" depends="prepareTestZip">
    <copy todir="unziptestout" preservelastmodified="true"> 
      <zipfileset src="unziptest.zip">
        <patternset>
          <include name="2/"/>
        </patternset>
      </zipfileset>
    </copy>
  </target>
</project>

Other Ant examples (source code examples)

Here is a short list of links related to this Ant unzip.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.