git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270787 13f79535-47bb-0310-9956-ffa450edef68master
@@ -350,6 +350,13 @@ Legal: | |||||
</zipfileset> | </zipfileset> | ||||
</jar> | </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}"> | <jar jarfile="${build.lib}/cvslib.atl" basedir="${build.classes}"> | ||||
<include name="org/apache/antlib/cvslib/**" /> | <include name="org/apache/antlib/cvslib/**" /> | ||||
<zipfileset dir="${manifest.dir}" fullpath="META-INF/ant-descriptor.xml"> | <zipfileset dir="${manifest.dir}" fullpath="META-INF/ant-descriptor.xml"> | ||||
@@ -5,7 +5,7 @@ | |||||
* version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
* the LICENSE.txt file. | * the LICENSE.txt file. | ||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs; | |||||
package org.apache.antlib.archive; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; |
@@ -5,7 +5,7 @@ | |||||
* version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
* the LICENSE.txt file. | * the LICENSE.txt file. | ||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs; | |||||
package org.apache.antlib.archive; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStream; | import java.io.OutputStream; |
@@ -5,7 +5,7 @@ | |||||
* version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
* the LICENSE.txt file. | * the LICENSE.txt file. | ||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs; | |||||
package org.apache.antlib.archive; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; |
@@ -5,7 +5,7 @@ | |||||
* version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
* the LICENSE.txt file. | * the LICENSE.txt file. | ||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs; | |||||
package org.apache.antlib.archive; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStream; | import java.io.OutputStream; |
@@ -5,7 +5,7 @@ | |||||
* version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
* the LICENSE.txt file. | * the LICENSE.txt file. | ||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs; | |||||
package org.apache.antlib.archive; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileInputStream; | import java.io.FileInputStream; |
@@ -5,7 +5,7 @@ | |||||
* version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
* the LICENSE.txt file. | * the LICENSE.txt file. | ||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs; | |||||
package org.apache.antlib.archive; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileInputStream; | import java.io.FileInputStream; | ||||
@@ -45,12 +45,12 @@ public abstract class Unpack | |||||
{ | { | ||||
validate(); | validate(); | ||||
final File source = getSrc(); | |||||
final File src = getSrc(); | |||||
final File dest = getDest(); | 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(); | " to " + dest.getAbsolutePath(); | ||||
getLogger().info( message ); | getLogger().info( message ); | ||||
@@ -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 <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | |||||
* @author <a href="mailto:peter@apache.org">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,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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
* @author <a href="mailto:umagesh@rediffmail.com">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,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 <a href="mailto:duncan@x180.com">duncan@x180.com</a> | |||||
* @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a> | |||||
* @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
*/ | |||||
public class GZip | |||||
extends Pack | |||||
{ | |||||
protected OutputStream getPackingStream( final OutputStream output ) | |||||
throws TaskException, IOException | |||||
{ | |||||
return new GZIPOutputStream( output ); | |||||
} | |||||
} |
@@ -169,5 +169,26 @@ Legal: | |||||
<log message-ref="refme2"/> | <log message-ref="refme2"/> | ||||
</target> | </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> | </project> |
@@ -0,0 +1,10 @@ | |||||
<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> |
@@ -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 <a href="mailto:umagesh@rediffmail.com">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,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 <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | |||||
* @author <a href="mailto:peter@apache.org">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,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 <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">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 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; | |||||
} | |||||
} |