Return-Path: Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 83660 invoked by uid 500); 24 May 2000 14:35:25 -0000 Delivered-To: apmail-jakarta-ant-cvs@apache.org Received: (qmail 83656 invoked by uid 1112); 24 May 2000 14:35:24 -0000 Date: 24 May 2000 14:35:24 -0000 Message-ID: <20000524143524.83655.qmail@locus.apache.org> From: arnout@locus.apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs GUnzip.java Untar.java defaults.properties arnout 00/05/24 07:35:24 Modified: docs index.html src/main/org/apache/tools/ant/taskdefs defaults.properties Added: src/main/org/apache/tools/ant/taskdefs GUnzip.java Untar.java Log: Two new tasks, untar & gunzip, to complement the tar & gzip. Submitted by: Stefan Bodewig Revision Changes Path 1.20 +75 -0 jakarta-ant/docs/index.html Index: index.html =================================================================== RCS file: /home/cvs/jakarta-ant/docs/index.html,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- index.html 2000/05/20 11:07:10 1.19 +++ index.html 2000/05/24 14:35:20 1.20 @@ -453,6 +453,7 @@
  • Expand
  • Filter
  • Get
  • +
  • GUnzip
  • GZip
  • FixCRLF
  • Jar
  • @@ -468,6 +469,7 @@
  • Tar
  • Taskdef
  • Tstamp
  • +
  • Untar
  • Zip

  • @@ -943,6 +945,50 @@
      <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

    GZips a file.

    @@ -2001,6 +2047,35 @@

    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

    1.11 +2 -0 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties Index: defaults.properties =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- defaults.properties 2000/03/23 03:40:32 1.10 +++ defaults.properties 2000/05/24 14:35:22 1.11 @@ -15,6 +15,7 @@ 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 @@ 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 1.1 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/GUnzip.java Index: GUnzip.java =================================================================== /* * 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); } } } } 1.1 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Untar.java Index: Untar.java =================================================================== /* * 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; } }