git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270944 13f79535-47bb-0310-9956-ffa450edef68master
@@ -8,15 +8,12 @@ | |||||
package org.apache.tools.ant.taskdefs.archive; | package org.apache.tools.ant.taskdefs.archive; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileInputStream; | |||||
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.zip.ZipEntry; | |||||
import java.util.zip.ZipInputStream; | |||||
import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
import org.apache.avalon.excalibur.io.IOUtil; | import org.apache.avalon.excalibur.io.IOUtil; | ||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
@@ -35,7 +32,7 @@ import org.apache.tools.ant.types.ScannerUtil; | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
* @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | * @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | ||||
*/ | */ | ||||
public class Expand | |||||
public abstract class Expand | |||||
extends MatchingTask | extends MatchingTask | ||||
{ | { | ||||
private boolean m_overwrite = true; | private boolean m_overwrite = true; | ||||
@@ -171,46 +168,26 @@ public class Expand | |||||
getLogger().info( message ); | getLogger().info( message ); | ||||
} | } | ||||
expandArchive( src, dir ); | |||||
if( getLogger().isDebugEnabled() ) | |||||
{ | |||||
final String message = "expand complete"; | |||||
getLogger().debug( message ); | |||||
} | |||||
} | |||||
protected void expandArchive( final File src, final File dir ) | |||||
throws TaskException | |||||
{ | |||||
ZipInputStream zis = null; | |||||
try | try | ||||
{ | { | ||||
// code from WarExpand | |||||
zis = new ZipInputStream( new FileInputStream( src ) ); | |||||
ZipEntry ze = null; | |||||
while( ( ze = zis.getNextEntry() ) != null ) | |||||
{ | |||||
final Date date = new Date( ze.getTime() ); | |||||
extractFile( dir, | |||||
zis, | |||||
ze.getName(), | |||||
date, | |||||
ze.isDirectory() ); | |||||
} | |||||
expandArchive( src, dir ); | |||||
} | } | ||||
catch( final IOException ioe ) | catch( final IOException ioe ) | ||||
{ | { | ||||
final String message = "Error while expanding " + src.getPath(); | final String message = "Error while expanding " + src.getPath(); | ||||
throw new TaskException( message, ioe ); | throw new TaskException( message, ioe ); | ||||
} | } | ||||
finally | |||||
if( getLogger().isDebugEnabled() ) | |||||
{ | { | ||||
IOUtil.shutdownStream( zis ); | |||||
final String message = "expand complete"; | |||||
getLogger().debug( message ); | |||||
} | } | ||||
} | } | ||||
protected abstract void expandArchive( final File src, final File dir ) | |||||
throws IOException, TaskException; | |||||
protected void extractFile( final File dir, | protected void extractFile( final File dir, | ||||
final InputStream input, | final InputStream input, | ||||
final String entryName, | final String entryName, | ||||
@@ -25,7 +25,7 @@ public class Untar | |||||
extends Expand | extends Expand | ||||
{ | { | ||||
protected void expandArchive( final File src, final File dir ) | protected void expandArchive( final File src, final File dir ) | ||||
throws TaskException | |||||
throws IOException, TaskException | |||||
{ | { | ||||
TarInputStream input = null; | TarInputStream input = null; | ||||
FileInputStream fileInput = null; | FileInputStream fileInput = null; | ||||
@@ -44,18 +44,10 @@ public class Untar | |||||
entry.isDirectory() ); | entry.isDirectory() ); | ||||
} | } | ||||
} | } | ||||
catch( final IOException ioe ) | |||||
{ | |||||
final String message = "Error while expanding " + src.getPath(); | |||||
throw new TaskException( message, ioe ); | |||||
} | |||||
finally | finally | ||||
{ | { | ||||
IOUtil.shutdownStream( fileInput ); | IOUtil.shutdownStream( fileInput ); | ||||
IOUtil.shutdownStream( input ); | IOUtil.shutdownStream( input ); | ||||
} | } | ||||
final String message = "expand complete"; | |||||
getLogger().debug( message ); | |||||
} | } | ||||
} | } |
@@ -0,0 +1,53 @@ | |||||
/* | |||||
* 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.archive; | |||||
import java.io.File; | |||||
import java.io.FileInputStream; | |||||
import java.io.IOException; | |||||
import java.util.Date; | |||||
import java.util.zip.ZipEntry; | |||||
import java.util.zip.ZipInputStream; | |||||
import org.apache.avalon.excalibur.io.IOUtil; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
/** | |||||
* Untar a file. Heavily based on the Expand task. | |||||
* | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
* @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | |||||
*/ | |||||
public class Unzip | |||||
extends Expand | |||||
{ | |||||
protected void expandArchive( final File src, final File dir ) | |||||
throws IOException, TaskException | |||||
{ | |||||
ZipInputStream zis = null; | |||||
try | |||||
{ | |||||
// code from WarExpand | |||||
zis = new ZipInputStream( new FileInputStream( src ) ); | |||||
ZipEntry ze = null; | |||||
while( ( ze = zis.getNextEntry() ) != null ) | |||||
{ | |||||
final Date date = new Date( ze.getTime() ); | |||||
extractFile( dir, | |||||
zis, | |||||
ze.getName(), | |||||
date, | |||||
ze.isDirectory() ); | |||||
} | |||||
} | |||||
finally | |||||
{ | |||||
IOUtil.shutdownStream( zis ); | |||||
} | |||||
} | |||||
} |
@@ -8,15 +8,12 @@ | |||||
package org.apache.tools.ant.taskdefs.archive; | package org.apache.tools.ant.taskdefs.archive; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileInputStream; | |||||
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.zip.ZipEntry; | |||||
import java.util.zip.ZipInputStream; | |||||
import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
import org.apache.avalon.excalibur.io.IOUtil; | import org.apache.avalon.excalibur.io.IOUtil; | ||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
@@ -35,7 +32,7 @@ import org.apache.tools.ant.types.ScannerUtil; | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
* @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | * @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | ||||
*/ | */ | ||||
public class Expand | |||||
public abstract class Expand | |||||
extends MatchingTask | extends MatchingTask | ||||
{ | { | ||||
private boolean m_overwrite = true; | private boolean m_overwrite = true; | ||||
@@ -171,46 +168,26 @@ public class Expand | |||||
getLogger().info( message ); | getLogger().info( message ); | ||||
} | } | ||||
expandArchive( src, dir ); | |||||
if( getLogger().isDebugEnabled() ) | |||||
{ | |||||
final String message = "expand complete"; | |||||
getLogger().debug( message ); | |||||
} | |||||
} | |||||
protected void expandArchive( final File src, final File dir ) | |||||
throws TaskException | |||||
{ | |||||
ZipInputStream zis = null; | |||||
try | try | ||||
{ | { | ||||
// code from WarExpand | |||||
zis = new ZipInputStream( new FileInputStream( src ) ); | |||||
ZipEntry ze = null; | |||||
while( ( ze = zis.getNextEntry() ) != null ) | |||||
{ | |||||
final Date date = new Date( ze.getTime() ); | |||||
extractFile( dir, | |||||
zis, | |||||
ze.getName(), | |||||
date, | |||||
ze.isDirectory() ); | |||||
} | |||||
expandArchive( src, dir ); | |||||
} | } | ||||
catch( final IOException ioe ) | catch( final IOException ioe ) | ||||
{ | { | ||||
final String message = "Error while expanding " + src.getPath(); | final String message = "Error while expanding " + src.getPath(); | ||||
throw new TaskException( message, ioe ); | throw new TaskException( message, ioe ); | ||||
} | } | ||||
finally | |||||
if( getLogger().isDebugEnabled() ) | |||||
{ | { | ||||
IOUtil.shutdownStream( zis ); | |||||
final String message = "expand complete"; | |||||
getLogger().debug( message ); | |||||
} | } | ||||
} | } | ||||
protected abstract void expandArchive( final File src, final File dir ) | |||||
throws IOException, TaskException; | |||||
protected void extractFile( final File dir, | protected void extractFile( final File dir, | ||||
final InputStream input, | final InputStream input, | ||||
final String entryName, | final String entryName, | ||||
@@ -25,7 +25,7 @@ public class Untar | |||||
extends Expand | extends Expand | ||||
{ | { | ||||
protected void expandArchive( final File src, final File dir ) | protected void expandArchive( final File src, final File dir ) | ||||
throws TaskException | |||||
throws IOException, TaskException | |||||
{ | { | ||||
TarInputStream input = null; | TarInputStream input = null; | ||||
FileInputStream fileInput = null; | FileInputStream fileInput = null; | ||||
@@ -44,18 +44,10 @@ public class Untar | |||||
entry.isDirectory() ); | entry.isDirectory() ); | ||||
} | } | ||||
} | } | ||||
catch( final IOException ioe ) | |||||
{ | |||||
final String message = "Error while expanding " + src.getPath(); | |||||
throw new TaskException( message, ioe ); | |||||
} | |||||
finally | finally | ||||
{ | { | ||||
IOUtil.shutdownStream( fileInput ); | IOUtil.shutdownStream( fileInput ); | ||||
IOUtil.shutdownStream( input ); | IOUtil.shutdownStream( input ); | ||||
} | } | ||||
final String message = "expand complete"; | |||||
getLogger().debug( message ); | |||||
} | } | ||||
} | } |
@@ -0,0 +1,53 @@ | |||||
/* | |||||
* 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.archive; | |||||
import java.io.File; | |||||
import java.io.FileInputStream; | |||||
import java.io.IOException; | |||||
import java.util.Date; | |||||
import java.util.zip.ZipEntry; | |||||
import java.util.zip.ZipInputStream; | |||||
import org.apache.avalon.excalibur.io.IOUtil; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
/** | |||||
* Untar a file. Heavily based on the Expand task. | |||||
* | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
* @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> | |||||
*/ | |||||
public class Unzip | |||||
extends Expand | |||||
{ | |||||
protected void expandArchive( final File src, final File dir ) | |||||
throws IOException, TaskException | |||||
{ | |||||
ZipInputStream zis = null; | |||||
try | |||||
{ | |||||
// code from WarExpand | |||||
zis = new ZipInputStream( new FileInputStream( src ) ); | |||||
ZipEntry ze = null; | |||||
while( ( ze = zis.getNextEntry() ) != null ) | |||||
{ | |||||
final Date date = new Date( ze.getTime() ); | |||||
extractFile( dir, | |||||
zis, | |||||
ze.getName(), | |||||
date, | |||||
ze.isDirectory() ); | |||||
} | |||||
} | |||||
finally | |||||
{ | |||||
IOUtil.shutdownStream( zis ); | |||||
} | |||||
} | |||||
} |