diff --git a/docs/index.html b/docs/index.html index 7f63c016b..bb61601c2 100644 --- a/docs/index.html +++ b/docs/index.html @@ -453,6 +453,7 @@ but excludes all "*.gif" files from the copy.

  • Expand
  • Filter
  • Get
  • +
  • GUnzip
  • GZip
  • FixCRLF
  • Jar
  • @@ -468,6 +469,7 @@ but excludes all "*.gif" files from the copy.

  • Tar
  • Taskdef
  • Tstamp
  • +
  • Untar
  • Zip

  • @@ -942,6 +944,50 @@ archive with http/ftp.

    Examples

      <get src="http://jakarta.apache.org/" dest="help/index.html" />

    gets the index page of http://jakarta.apache.org/, and stores it in the file help/index.html.

    +
    +

    GUnzip

    +

    Description

    +

    Expands a GZip file.

    + +

    If dest is a directory the name of the destination file is +the same as src (with the ".gz" extension removed if +present). If dest is ommited, the parent dir of src is +taken. The file is only expanded if the source file is newer than the +destination file, or when the destination file does not exist.

    + +

    Parameters

    + + + + + + + + + + + + + + + + +
    AttributeDescriptionRequired
    srcthe file to expand.Yes
    destthe destination file or directory.No
    +

    Examples

    +
    +

    <gunzip src="test.tar.gz"/>

    +
    +

    expands test.tar.gz to test.tar

    +
    +

    <gunzip src="test.tar.gz" dest="test2.tar"/>

    +
    +

    expands test.tar.gz to test2.tar

    +
    +

    <gunzip src="test.tar.gz" dest="subdir"/>

    +
    +

    expands test.tar.gz to subdir/test.tar (assuming +subdir is a directory).

    +

    GZip

    Description

    @@ -2002,6 +2048,35 @@ initialization target.

    Examples

      <tstamp/>

    +

    Untar

    +

    Description

    +

    Untars a tarfile.

    +

    Parameters

    + + + + + + + + + + + + + + + + +
    AttributeDescriptionRequired
    srctarfile to expand.Yes
    destdirectory where to store the expanded files.Yes
    +

    Examples

    +
    +

    +<gunzip src="tools.tar.gz"/>
    +<untar src="tools.tar" dest="${tools.home}"/> +

    +
    +

    Zip

    Description

    Creates a zipfile.

    diff --git a/src/main/org/apache/tools/ant/taskdefs/GUnzip.java b/src/main/org/apache/tools/ant/taskdefs/GUnzip.java new file mode 100644 index 000000000..df7c0cd56 --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/GUnzip.java @@ -0,0 +1,132 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.*; + +import java.io.*; +import java.util.zip.*; + +/** + * Expands a file that has been compressed with the GZIP + * algorightm. Normally used to compress non-compressed archives such + * as TAR files. + * + * @author Stefan Bodewig stefan.bodewig@megabit.net + */ + +public class GUnzip extends Task { + + private File source; + private File dest; + + public void setSrc(String src) { + source = project.resolveFile(src); + } + + public void setDest(String dest) { + this.dest = project.resolveFile(dest); + } + + public void execute() throws BuildException { + if (source == null) { + throw new BuildException("No source specified"); + } + + if (!source.exists()) { + throw new BuildException("source doesn't exist"); + } + + if (source.isDirectory()) { + throw new BuildException("Cannot expand a directory"); + } + + if (dest == null) { + dest = new File(source.getParent()); + } + + if (dest.isDirectory()) { + String sourceName = source.getName(); + int len = sourceName.length(); + if (len > 3 + && ".gz".equalsIgnoreCase(sourceName.substring(len-3))) { + dest = new File(dest, sourceName.substring(0, len-3)); + } else { + dest = new File(dest, sourceName); + } + } + + if (source.lastModified() > dest.lastModified()) { + project.log("Expanding "+ source.getAbsolutePath() + " to " + + dest.getAbsolutePath()); + + try { + FileOutputStream out = new FileOutputStream(dest); + GZIPInputStream zIn = new GZIPInputStream(new FileInputStream(source)); + byte[] buffer = new byte[8 * 1024]; + int count = 0; + do { + out.write(buffer, 0, count); + count = zIn.read(buffer, 0, buffer.length); + } while (count != -1); + zIn.close(); + out.close(); + } catch (IOException ioe) { + String msg = "Problem expanding gzip " + ioe.getMessage(); + throw new BuildException(msg, ioe); + } + } + } +} diff --git a/src/main/org/apache/tools/ant/taskdefs/Untar.java b/src/main/org/apache/tools/ant/taskdefs/Untar.java new file mode 100644 index 000000000..9b870402d --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/Untar.java @@ -0,0 +1,145 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.*; +import org.apache.tools.tar.*; +import java.io.*; +/** + * Untar a file. + * + * Heavily based on the Expand task. + * + * @author Stefan Bodewig stefan.bodewig@megabit.net + */ +public class Untar extends Task { + private String dest; // req + private String source; // req + + /** + * Do the work. + * + * @exception BuildException Thrown in unrecoverable error. + */ + public void execute() throws BuildException { + try { + if (source == null) { + throw new BuildException("No source specified"); + } + File srcF=project.resolveFile(source); + if (!srcF.exists()) { + throw new BuildException("source doesn't exist"); + } + + if (dest == null) { + throw new BuildException("No destination specified"); + } + + File dir=project.resolveFile(dest); + + project.log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO); + // code from WarExpand + TarInputStream tis = new TarInputStream(new FileInputStream(srcF)); + TarEntry te = null; + + while ((te = tis.getNextEntry()) != null) { + try { + File f = new File(dir, project.translatePath(te.getName())); + project.log("expand-file " + te.getName() , "untar", Project.MSG_VERBOSE ); + // create intermediary directories - sometimes tar don't add them + File dirF=new File(f.getParent()); + dirF.mkdirs(); + + if (te.isDirectory()) { + f.mkdirs(); + } else { + byte[] buffer = new byte[1024]; + int length = 0; + FileOutputStream fos = new FileOutputStream(f); + + while ((length = tis.read(buffer)) >= 0) { + fos.write(buffer, 0, length); + } + + fos.close(); + } + } catch( FileNotFoundException ex ) { + System.out.println("FileNotFoundException: " + te.getName() ); + } + } + } catch (IOException ioe) { + throw new BuildException(ioe); + } + } + + /** + * Set the destination directory. File will be untared into the + * destination directory. + * + * @param d Path to the directory. + */ + public void setDest(String d) { + this.dest=d; + } + + /** + * Set the path to tar-file. + * + * @param s Path to tar-file. + */ + public void setSrc(String s) { + this.source = s; + } +} diff --git a/src/main/org/apache/tools/ant/taskdefs/defaults.properties b/src/main/org/apache/tools/ant/taskdefs/defaults.properties index b2f436a8e..339460e56 100644 --- a/src/main/org/apache/tools/ant/taskdefs/defaults.properties +++ b/src/main/org/apache/tools/ant/taskdefs/defaults.properties @@ -15,6 +15,7 @@ echo=org.apache.tools.ant.taskdefs.Echo javadoc=org.apache.tools.ant.taskdefs.Javadoc zip=org.apache.tools.ant.taskdefs.Zip gzip=org.apache.tools.ant.taskdefs.GZip +gunzip=org.apache.tools.ant.taskdefs.GUnzip replace=org.apache.tools.ant.taskdefs.Replace java=org.apache.tools.ant.taskdefs.Java tstamp=org.apache.tools.ant.taskdefs.Tstamp @@ -23,6 +24,7 @@ taskdef=org.apache.tools.ant.taskdefs.Taskdef ant=org.apache.tools.ant.taskdefs.Ant exec=org.apache.tools.ant.taskdefs.Exec tar=org.apache.tools.ant.taskdefs.Tar +untar=org.apache.tools.ant.taskdefs.Untar available=org.apache.tools.ant.taskdefs.Available filter=org.apache.tools.ant.taskdefs.Filter fixcrlf=org.apache.tools.ant.taskdefs.FixCRLF