Browse Source

Cleanup the expand related classes a lil more

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270943 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
c6cabe48e1
4 changed files with 78 additions and 56 deletions
  1. +38
    -21
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Expand.java
  2. +1
    -7
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Untar.java
  3. +38
    -21
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/archive/Expand.java
  4. +1
    -7
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/archive/Untar.java

+ 38
- 21
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Expand.java View File

@@ -164,6 +164,24 @@ public class Expand
*/ */
protected void expandFile( final File src, final File dir ) protected void expandFile( final File src, final File dir )
throws TaskException throws TaskException
{
if( getLogger().isInfoEnabled() )
{
final String message = "Expanding: " + src + " into " + dir;
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; ZipInputStream zis = null;
try try
@@ -175,12 +193,11 @@ public class Expand
while( ( ze = zis.getNextEntry() ) != null ) while( ( ze = zis.getNextEntry() ) != null )
{ {
final Date date = new Date( ze.getTime() ); final Date date = new Date( ze.getTime() );
extractFile(
dir,
zis,
ze.getName(),
date,
ze.isDirectory() );
extractFile( dir,
zis,
ze.getName(),
date,
ze.isDirectory() );
} }
} }
catch( final IOException ioe ) catch( final IOException ioe )
@@ -192,9 +209,6 @@ public class Expand
{ {
IOUtil.shutdownStream( zis ); IOUtil.shutdownStream( zis );
} }

final String message = "expand complete";
getLogger().debug( message );
} }


protected void extractFile( final File dir, protected void extractFile( final File dir,
@@ -249,31 +263,33 @@ public class Expand
} }
} }


File f = FileUtil.resolveFile( dir, entryName );
final File file = FileUtil.resolveFile( dir, entryName );
try try
{ {
if( !m_overwrite && f.exists()
&& f.lastModified() >= date.getTime() )
if( !m_overwrite && file.exists() &&
file.lastModified() >= date.getTime() )
{ {
getLogger().debug( "Skipping " + f + " as it is up-to-date" );
final String message = "Skipping " + file + " as it is up-to-date";
getLogger().debug( message );
return; return;
} }


getLogger().debug( "expanding " + entryName + " to " + f );
getLogger().debug( "expanding " + entryName + " to " + file );

// create intermediary directories - sometimes zip don't add them // create intermediary directories - sometimes zip don't add them
File dirF = f.getParentFile();
dirF.mkdirs();
final File parent = file.getParentFile();
parent.mkdirs();


if( isDirectory ) if( isDirectory )
{ {
f.mkdirs();
file.mkdirs();
} }
else else
{ {
FileOutputStream fos = null; FileOutputStream fos = null;
try try
{ {
fos = new FileOutputStream( f );
fos = new FileOutputStream( file );
IOUtil.copy( input, fos ); IOUtil.copy( input, fos );
} }
finally finally
@@ -282,11 +298,12 @@ public class Expand
} }
} }


f.setLastModified( date.getTime() );
file.setLastModified( date.getTime() );
} }
catch( FileNotFoundException ex )
catch( final FileNotFoundException fnfe )
{ {
getLogger().warn( "Unable to expand to file " + f.getPath() );
final String message = "Unable to expand to file " + file.getPath();
getLogger().warn( message );
} }
} }
} }

+ 1
- 7
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Untar.java View File

@@ -24,15 +24,9 @@ import org.apache.myrmidon.api.TaskException;
public class Untar public class Untar
extends Expand extends Expand
{ {
protected void expandFile( final File src, final File dir )
protected void expandArchive( final File src, final File dir )
throws TaskException throws TaskException
{ {
if( getLogger().isInfoEnabled() )
{
final String message = "Expanding: " + src + " into " + dir;
getLogger().info( message );
}

TarInputStream input = null; TarInputStream input = null;
FileInputStream fileInput = null; FileInputStream fileInput = null;
try try


+ 38
- 21
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/archive/Expand.java View File

@@ -164,6 +164,24 @@ public class Expand
*/ */
protected void expandFile( final File src, final File dir ) protected void expandFile( final File src, final File dir )
throws TaskException throws TaskException
{
if( getLogger().isInfoEnabled() )
{
final String message = "Expanding: " + src + " into " + dir;
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; ZipInputStream zis = null;
try try
@@ -175,12 +193,11 @@ public class Expand
while( ( ze = zis.getNextEntry() ) != null ) while( ( ze = zis.getNextEntry() ) != null )
{ {
final Date date = new Date( ze.getTime() ); final Date date = new Date( ze.getTime() );
extractFile(
dir,
zis,
ze.getName(),
date,
ze.isDirectory() );
extractFile( dir,
zis,
ze.getName(),
date,
ze.isDirectory() );
} }
} }
catch( final IOException ioe ) catch( final IOException ioe )
@@ -192,9 +209,6 @@ public class Expand
{ {
IOUtil.shutdownStream( zis ); IOUtil.shutdownStream( zis );
} }

final String message = "expand complete";
getLogger().debug( message );
} }


protected void extractFile( final File dir, protected void extractFile( final File dir,
@@ -249,31 +263,33 @@ public class Expand
} }
} }


File f = FileUtil.resolveFile( dir, entryName );
final File file = FileUtil.resolveFile( dir, entryName );
try try
{ {
if( !m_overwrite && f.exists()
&& f.lastModified() >= date.getTime() )
if( !m_overwrite && file.exists() &&
file.lastModified() >= date.getTime() )
{ {
getLogger().debug( "Skipping " + f + " as it is up-to-date" );
final String message = "Skipping " + file + " as it is up-to-date";
getLogger().debug( message );
return; return;
} }


getLogger().debug( "expanding " + entryName + " to " + f );
getLogger().debug( "expanding " + entryName + " to " + file );

// create intermediary directories - sometimes zip don't add them // create intermediary directories - sometimes zip don't add them
File dirF = f.getParentFile();
dirF.mkdirs();
final File parent = file.getParentFile();
parent.mkdirs();


if( isDirectory ) if( isDirectory )
{ {
f.mkdirs();
file.mkdirs();
} }
else else
{ {
FileOutputStream fos = null; FileOutputStream fos = null;
try try
{ {
fos = new FileOutputStream( f );
fos = new FileOutputStream( file );
IOUtil.copy( input, fos ); IOUtil.copy( input, fos );
} }
finally finally
@@ -282,11 +298,12 @@ public class Expand
} }
} }


f.setLastModified( date.getTime() );
file.setLastModified( date.getTime() );
} }
catch( FileNotFoundException ex )
catch( final FileNotFoundException fnfe )
{ {
getLogger().warn( "Unable to expand to file " + f.getPath() );
final String message = "Unable to expand to file " + file.getPath();
getLogger().warn( message );
} }
} }
} }

+ 1
- 7
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/archive/Untar.java View File

@@ -24,15 +24,9 @@ import org.apache.myrmidon.api.TaskException;
public class Untar public class Untar
extends Expand extends Expand
{ {
protected void expandFile( final File src, final File dir )
protected void expandArchive( final File src, final File dir )
throws TaskException throws TaskException
{ {
if( getLogger().isInfoEnabled() )
{
final String message = "Expanding: " + src + " into " + dir;
getLogger().info( message );
}

TarInputStream input = null; TarInputStream input = null;
FileInputStream fileInput = null; FileInputStream fileInput = null;
try try


Loading…
Cancel
Save