donaldp 02/01/27 02:34:18
Modified: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive
Untar.java Expand.java
Added: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive
Unzip.java
Log:
Made Expand archive-agnostic and the subclasses (Unzip/Untar) are the only
ones that know about the specifics of a particular archive
Revision Changes Path
1.4 +1 -9
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Untar.java
Index: Untar.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Untar.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Untar.java 27 Jan 2002 10:28:35 -0000 1.3
+++ Untar.java 27 Jan 2002 10:34:18 -0000 1.4
@@ -25,7 +25,7 @@
extends Expand
{
protected void expandArchive( final File src, final File dir )
- throws TaskException
+ throws IOException, TaskException
{
TarInputStream input = null;
FileInputStream fileInput = null;
@@ -44,18 +44,10 @@
entry.isDirectory() );
}
}
- catch( final IOException ioe )
- {
- final String message = "Error while expanding " + src.getPath();
- throw new TaskException( message, ioe );
- }
finally
{
IOUtil.shutdownStream( fileInput );
IOUtil.shutdownStream( input );
}
-
- final String message = "expand complete";
- getLogger().debug( message );
}
}
1.4 +9 -32
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Expand.java
Index: Expand.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Expand.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Expand.java 27 Jan 2002 10:28:35 -0000 1.3
+++ Expand.java 27 Jan 2002 10:34:18 -0000 1.4
@@ -8,15 +8,12 @@
package org.apache.tools.ant.taskdefs.archive;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
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.IOUtil;
import org.apache.myrmidon.api.TaskContext;
@@ -35,7 +32,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
*/
-public class Expand
+public abstract class Expand
extends MatchingTask
{
private boolean m_overwrite = true;
@@ -171,45 +168,25 @@
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
{
- // 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 )
{
final String message = "Error while expanding " + src.getPath();
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,
final InputStream input,
1.1
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Unzip.java
Index: Unzip.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.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:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @author <a href="mailto:[EMAIL PROTECTED]">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 );
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>