From f0aec0feb7c46febee6fa56b43ebab3729483754 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Sat, 19 Jan 2002 07:41:48 +0000 Subject: [PATCH] Move g/b zip stuff into new library git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270787 13f79535-47bb-0310-9956-ffa450edef68 --- proposal/myrmidon/build.xml | 7 + .../org/apache/antlib/archive}/BUnzip2.java | 2 +- .../org/apache/antlib/archive}/BZip2.java | 2 +- .../org/apache/antlib/archive}/GUnzip.java | 2 +- .../org/apache/antlib/archive}/GZip.java | 2 +- .../org/apache/antlib/archive}/Pack.java | 2 +- .../org/apache/antlib/archive}/Unpack.java | 8 +- .../org/apache/tools/ant/taskdefs/BZip2.java | 33 ---- .../org/apache/tools/ant/taskdefs/GUnzip.java | 37 ----- .../org/apache/tools/ant/taskdefs/GZip.java | 32 ---- proposal/myrmidon/src/make/sample.ant | 21 +++ .../src/manifest/archive-ant-descriptor.xml | 10 ++ .../apache/tools/ant/taskdefs/BUnzip2.java | 44 ----- .../org/apache/tools/ant/taskdefs/Pack.java | 122 -------------- .../org/apache/tools/ant/taskdefs/Unpack.java | 154 ------------------ 15 files changed, 47 insertions(+), 431 deletions(-) rename proposal/myrmidon/src/{main/org/apache/tools/ant/taskdefs => java/org/apache/antlib/archive}/BUnzip2.java (96%) rename proposal/myrmidon/src/{todo/org/apache/tools/ant/taskdefs => java/org/apache/antlib/archive}/BZip2.java (96%) rename proposal/myrmidon/src/{todo/org/apache/tools/ant/taskdefs => java/org/apache/antlib/archive}/GUnzip.java (96%) rename proposal/myrmidon/src/{todo/org/apache/tools/ant/taskdefs => java/org/apache/antlib/archive}/GZip.java (96%) rename proposal/myrmidon/src/{main/org/apache/tools/ant/taskdefs => java/org/apache/antlib/archive}/Pack.java (98%) rename proposal/myrmidon/src/{main/org/apache/tools/ant/taskdefs => java/org/apache/antlib/archive}/Unpack.java (94%) delete mode 100644 proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/BZip2.java delete mode 100644 proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/GUnzip.java delete mode 100644 proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/GZip.java create mode 100644 proposal/myrmidon/src/manifest/archive-ant-descriptor.xml delete mode 100644 proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/BUnzip2.java delete mode 100644 proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Pack.java delete mode 100644 proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Unpack.java diff --git a/proposal/myrmidon/build.xml b/proposal/myrmidon/build.xml index 7209a3d04..76c96aabc 100644 --- a/proposal/myrmidon/build.xml +++ b/proposal/myrmidon/build.xml @@ -350,6 +350,13 @@ Legal: + + + + + + + diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/BUnzip2.java b/proposal/myrmidon/src/java/org/apache/antlib/archive/BUnzip2.java similarity index 96% rename from proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/BUnzip2.java rename to proposal/myrmidon/src/java/org/apache/antlib/archive/BUnzip2.java index 27a208542..08f419b96 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/BUnzip2.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/archive/BUnzip2.java @@ -5,7 +5,7 @@ * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ -package org.apache.tools.ant.taskdefs; +package org.apache.antlib.archive; import java.io.IOException; import java.io.InputStream; diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/BZip2.java b/proposal/myrmidon/src/java/org/apache/antlib/archive/BZip2.java similarity index 96% rename from proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/BZip2.java rename to proposal/myrmidon/src/java/org/apache/antlib/archive/BZip2.java index 398926a33..7b8d4cea0 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/BZip2.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/archive/BZip2.java @@ -5,7 +5,7 @@ * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ -package org.apache.tools.ant.taskdefs; +package org.apache.antlib.archive; import java.io.IOException; import java.io.OutputStream; diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/GUnzip.java b/proposal/myrmidon/src/java/org/apache/antlib/archive/GUnzip.java similarity index 96% rename from proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/GUnzip.java rename to proposal/myrmidon/src/java/org/apache/antlib/archive/GUnzip.java index 3510d8639..cf3c5e148 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/GUnzip.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/archive/GUnzip.java @@ -5,7 +5,7 @@ * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ -package org.apache.tools.ant.taskdefs; +package org.apache.antlib.archive; import java.io.IOException; import java.io.InputStream; diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/GZip.java b/proposal/myrmidon/src/java/org/apache/antlib/archive/GZip.java similarity index 96% rename from proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/GZip.java rename to proposal/myrmidon/src/java/org/apache/antlib/archive/GZip.java index d6b09effc..516736195 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/GZip.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/archive/GZip.java @@ -5,7 +5,7 @@ * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ -package org.apache.tools.ant.taskdefs; +package org.apache.antlib.archive; import java.io.IOException; import java.io.OutputStream; diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Pack.java b/proposal/myrmidon/src/java/org/apache/antlib/archive/Pack.java similarity index 98% rename from proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Pack.java rename to proposal/myrmidon/src/java/org/apache/antlib/archive/Pack.java index 1b753509e..0c8b0e86f 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Pack.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/archive/Pack.java @@ -5,7 +5,7 @@ * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ -package org.apache.tools.ant.taskdefs; +package org.apache.antlib.archive; import java.io.File; import java.io.FileInputStream; diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Unpack.java b/proposal/myrmidon/src/java/org/apache/antlib/archive/Unpack.java similarity index 94% rename from proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Unpack.java rename to proposal/myrmidon/src/java/org/apache/antlib/archive/Unpack.java index 51db213bf..0475e51ca 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Unpack.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/archive/Unpack.java @@ -5,7 +5,7 @@ * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ -package org.apache.tools.ant.taskdefs; +package org.apache.antlib.archive; import java.io.File; import java.io.FileInputStream; @@ -45,12 +45,12 @@ public abstract class Unpack { validate(); - final File source = getSrc(); + final File src = getSrc(); final File dest = getDest(); - if( source.lastModified() > dest.lastModified() ) + if( src.lastModified() > dest.lastModified() ) { - final String message = "Expanding " + source.getAbsolutePath() + + final String message = "Expanding " + src.getAbsolutePath() + " to " + dest.getAbsolutePath(); getLogger().info( message ); diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/BZip2.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/BZip2.java deleted file mode 100644 index 398926a33..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/BZip2.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs; - -import java.io.IOException; -import java.io.OutputStream; -import org.apache.myrmidon.api.TaskException; -import org.apache.tools.bzip2.CBZip2OutputStream; - -/** - * Compresses a file with the BZip2 algorithm. Normally used to compress - * non-compressed archives such as TAR files. - * - * @author Magesh Umasankar - * @author Peter Donald - */ -public class BZip2 - extends Pack -{ - private static final byte[] HEADER = new byte[]{(byte)'B', (byte)'Z'}; - - protected OutputStream getPackingStream( OutputStream output ) - throws TaskException, IOException - { - output.write( HEADER ); - return new CBZip2OutputStream( output ); - } -} diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/GUnzip.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/GUnzip.java deleted file mode 100644 index 3510d8639..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/GUnzip.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs; - -import java.io.IOException; -import java.io.InputStream; -import java.util.zip.GZIPInputStream; -import org.apache.myrmidon.api.TaskException; - -/** - * Expands a file that has been compressed with the GZIP algorithm. Normally - * used to compress non-compressed archives such as TAR files. - * - * @author Stefan Bodewig - * @author Magesh Umasankar - */ -public class GUnzip - extends Unpack -{ - private final static String DEFAULT_EXTENSION = ".gz"; - - protected String getDefaultExtension() - { - return DEFAULT_EXTENSION; - } - - protected InputStream getUnpackingStream( InputStream input ) - throws TaskException, IOException - { - return new GZIPInputStream( input ); - } -} diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/GZip.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/GZip.java deleted file mode 100644 index d6b09effc..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/GZip.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.zip.GZIPOutputStream; -import org.apache.myrmidon.api.TaskException; - -/** - * Compresses a file with the GZIP algorithm. Normally used to compress - * non-compressed archives such as TAR files. - * - * @author James Davidson duncan@x180.com - * @author Jon S. Stevens jon@clearink.com - * @author Magesh Umasankar - * @author Peter Donald - */ -public class GZip - extends Pack -{ - protected OutputStream getPackingStream( final OutputStream output ) - throws TaskException, IOException - { - return new GZIPOutputStream( output ); - } -} diff --git a/proposal/myrmidon/src/make/sample.ant b/proposal/myrmidon/src/make/sample.ant index ebd4e4c8d..63dbde3dc 100644 --- a/proposal/myrmidon/src/make/sample.ant +++ b/proposal/myrmidon/src/make/sample.ant @@ -169,5 +169,26 @@ Legal: + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/proposal/myrmidon/src/manifest/archive-ant-descriptor.xml b/proposal/myrmidon/src/manifest/archive-ant-descriptor.xml new file mode 100644 index 000000000..3b1d7352d --- /dev/null +++ b/proposal/myrmidon/src/manifest/archive-ant-descriptor.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/BUnzip2.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/BUnzip2.java deleted file mode 100644 index 27a208542..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/BUnzip2.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs; - -import java.io.IOException; -import java.io.InputStream; -import org.apache.myrmidon.api.TaskException; -import org.apache.tools.bzip2.CBZip2InputStream; - -/** - * Expands a file that has been compressed with the BZIP2 algorithm. Normally - * used to compress non-compressed archives such as TAR files. - * - * @author Magesh Umasankar - */ -public class BUnzip2 - extends Unpack -{ - private final static String DEFAULT_EXTENSION = ".bz2"; - - protected String getDefaultExtension() - { - return DEFAULT_EXTENSION; - } - - protected InputStream getUnpackingStream( final InputStream input ) - throws TaskException, IOException - { - final int b1 = input.read(); - final int b2 = input.read(); - if( b1 != 'B' || b2 != 'Z' ) - { - final String message = "Invalid bz2 file."; - throw new TaskException( message ); - } - - return new CBZip2InputStream( input ); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Pack.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Pack.java deleted file mode 100644 index 1b753509e..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Pack.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.zip.GZIPOutputStream; -import org.apache.avalon.excalibur.io.IOUtil; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; - -/** - * Abstract Base class for pack tasks. - * - * @author Magesh Umasankar - * @author Peter Donald - */ -public abstract class Pack - extends AbstractTask -{ - private File m_src; - private File m_zipFile; - - public void setSrc( final File src ) - { - m_src = src; - } - - public void setZipfile( final File zipFile ) - { - m_zipFile = zipFile; - } - - public void execute() - throws TaskException - { - validate(); - final String message = "Building: " + m_zipFile.getAbsolutePath(); - getLogger().info( message ); - pack(); - } - - private void pack() - throws TaskException - { - OutputStream output = null; - try - { - final FileOutputStream fileOutput = new FileOutputStream( getZipFile() ); - output = getPackingStream( fileOutput ); - copy( getSrc(), output ); - } - catch( final IOException ioe ) - { - final String message = "Problem creating " + getName() + - ":" + ioe.getMessage(); - throw new TaskException( message, ioe ); - } - finally - { - IOUtil.shutdownStream( output ); - } - } - - protected abstract OutputStream getPackingStream( OutputStream output ) - throws TaskException, IOException; - - protected final void copy( final File file, final OutputStream output ) - throws IOException - { - final FileInputStream input = new FileInputStream( file ); - try - { - IOUtil.copy( input, output ); - } - finally - { - IOUtil.shutdownStream( input ); - } - } - - private void validate() - throws TaskException - { - if( null == m_zipFile ) - { - final String message = "zipfile attribute is required"; - throw new TaskException( message ); - } - - if( null == m_src ) - { - final String message = "src attribute is required"; - throw new TaskException( message ); - } - - if( m_src.isDirectory() ) - { - final String message = "Src attribute must not " + - "represent a directory!"; - throw new TaskException( message ); - } - } - - protected final File getSrc() - { - return m_src; - } - - protected final File getZipFile() - { - return m_zipFile; - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Unpack.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Unpack.java deleted file mode 100644 index 51db213bf..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Unpack.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import org.apache.avalon.excalibur.io.IOUtil; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; - -/** - * Abstract Base class for unpack tasks. - * - * @author Magesh Umasankar - * @author Peter Donald - * @author Stefan Bodewig - */ -public abstract class Unpack - extends AbstractTask -{ - private File m_dest; - private File m_src; - - public void setDest( final File dest ) - { - m_dest = dest; - } - - public void setSrc( final File src ) - { - m_src = src; - } - - public void execute() - throws TaskException - { - validate(); - - final File source = getSrc(); - final File dest = getDest(); - - if( source.lastModified() > dest.lastModified() ) - { - final String message = "Expanding " + source.getAbsolutePath() + - " to " + dest.getAbsolutePath(); - getLogger().info( message ); - - extract(); - } - } - - protected abstract String getDefaultExtension(); - - protected abstract InputStream getUnpackingStream( InputStream input ) - throws TaskException, IOException; - - private void extract() - throws TaskException - { - OutputStream output = null; - InputStream input = null; - InputStream fileInput = null; - try - { - output = new FileOutputStream( getDest() ); - fileInput = new FileInputStream( getSrc() ); - input = getUnpackingStream( fileInput ); - IOUtil.copy( input, output ); - } - catch( final IOException ioe ) - { - final String message = "Problem expanding " + getSrc() + - ":" + ioe.getMessage(); - throw new TaskException( message, ioe ); - } - finally - { - IOUtil.shutdownStream( fileInput ); - IOUtil.shutdownStream( output ); - IOUtil.shutdownStream( input ); - } - } - - private File createDestFile() - { - final String extension = getDefaultExtension(); - final String sourceName = m_src.getName(); - final int length = sourceName.length(); - final int index = length - extension.length(); - - if( null != extension && - length > extension.length() && - extension.equalsIgnoreCase( sourceName.substring( index ) ) ) - { - final String child = sourceName.substring( 0, index ); - return new File( m_dest, child ); - } - else - { - return new File( m_dest, sourceName ); - } - } - - private void validate() - throws TaskException - { - if( null == m_src ) - { - final String message = "No Src for " + getName() + " specified"; - throw new TaskException( message ); - } - - if( !m_src.exists() ) - { - final String message = "Src doesn't exist"; - throw new TaskException( message ); - } - - if( m_src.isDirectory() ) - { - final String message = "Cannot expand a directory"; - throw new TaskException( message ); - } - - if( null == m_dest ) - { - m_dest = new File( m_src.getParent() ); - } - - if( m_dest.isDirectory() ) - { - m_dest = createDestFile(); - } - } - - protected final File getDest() - { - return m_dest; - } - - protected final File getSrc() - { - return m_src; - } -}