donaldp 02/01/18 23:41:48
Modified: proposal/myrmidon build.xml
proposal/myrmidon/src/make sample.ant
Added: proposal/myrmidon/src/java/org/apache/antlib/archive
BUnzip2.java BZip2.java GUnzip.java GZip.java
Pack.java Unpack.java
proposal/myrmidon/src/manifest archive-ant-descriptor.xml
Removed: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs
BUnzip2.java BZip2.java GUnzip.java GZip.java
Pack.java Unpack.java
Log:
Move g/b zip stuff into new library
Revision Changes Path
1.40 +7 -0 jakarta-ant/proposal/myrmidon/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/build.xml,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- build.xml 19 Jan 2002 07:26:21 -0000 1.39
+++ build.xml 19 Jan 2002 07:41:47 -0000 1.40
@@ -350,6 +350,13 @@
</zipfileset>
</jar>
+ <jar jarfile="${build.lib}/archive.atl" basedir="${build.classes}">
+ <include name="org/apache/antlib/archive/**" />
+ <zipfileset dir="${manifest.dir}"
fullpath="META-INF/ant-descriptor.xml">
+ <include name="archive-ant-descriptor.xml"/>
+ </zipfileset>
+ </jar>
+
<jar jarfile="${build.lib}/cvslib.atl" basedir="${build.classes}">
<include name="org/apache/antlib/cvslib/**" />
<zipfileset dir="${manifest.dir}"
fullpath="META-INF/ant-descriptor.xml">
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/archive/BUnzip2.java
Index: BUnzip2.java
===================================================================
/*
* 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.antlib.archive;
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 <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
*/
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 );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/archive/BZip2.java
Index: BZip2.java
===================================================================
/*
* 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.antlib.archive;
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 <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
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 );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/archive/GUnzip.java
Index: GUnzip.java
===================================================================
/*
* 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.antlib.archive;
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 <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
*/
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 );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/archive/GZip.java
Index: GZip.java
===================================================================
/*
* 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.antlib.archive;
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 <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @author Jon S. Stevens <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public class GZip
extends Pack
{
protected OutputStream getPackingStream( final OutputStream output )
throws TaskException, IOException
{
return new GZIPOutputStream( output );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/archive/Pack.java
Index: Pack.java
===================================================================
/*
* 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.antlib.archive;
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 <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
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;
}
}
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/archive/Unpack.java
Index: Unpack.java
===================================================================
/*
* 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.antlib.archive;
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 <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
*/
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 src = getSrc();
final File dest = getDest();
if( src.lastModified() > dest.lastModified() )
{
final String message = "Expanding " + src.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;
}
}
1.23 +21 -0 jakarta-ant/proposal/myrmidon/src/make/sample.ant
Index: sample.ant
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/make/sample.ant,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- sample.ant 15 Jan 2002 09:13:13 -0000 1.22
+++ sample.ant 19 Jan 2002 07:41:48 -0000 1.23
@@ -169,5 +169,26 @@
<log message-ref="refme2"/>
</target>
+ <target name="gzip-test">
+ <property name="zip" value="../../dist/bin/sample.gz" />
+ <property name="unzip" value="../../dist/bin/sample.txt" />
+
+ <gzip src="sample.ant" zipfile="${zip}"/>
+ <log message="Gzipped file!"/>
+
+ <gunzip src="${zip}" dest="${unzip}"/>
+ <log message="Ungzipped file!"/>
+ </target>
+
+ <target name="bzip2-test">
+ <property name="zip" value="../../dist/bin/sample.gz" />
+ <property name="unzip" value="../../dist/bin/sample.txt" />
+
+ <bzip2 src="sample.ant" zipfile="${zip}"/>
+ <log message="Gzipped file!"/>
+
+ <bunzip2 src="${zip}" dest="${unzip}"/>
+ <log message="Ungzipped file!"/>
+ </target>
</project>
1.1
jakarta-ant/proposal/myrmidon/src/manifest/archive-ant-descriptor.xml
Index: archive-ant-descriptor.xml
===================================================================
<ant-lib>
<types>
<task name="bunzip2" classname="org.apache.antlib.archive.BUnzip2" />
<task name="bzip2" classname="org.apache.antlib.archive.BZip2" />
<task name="gunzip" classname="org.apache.antlib.archive.GUnzip" />
<task name="gzip" classname="org.apache.antlib.archive.GZip" />
</types>
</ant-lib>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>