Skip to content

Commit 6c49e39

Browse files
o Updated to stop supressing exceptions incorrectly.
Closes #33
1 parent 663a889 commit 6c49e39

17 files changed

+168
-79
lines changed

src/main/java/org/codehaus/plexus/archiver/AbstractUnArchiver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ else if ( isDirectory )
313313
out = new FileOutputStream( f );
314314

315315
IOUtil.copy( compressedInputStream, out );
316+
out.close();
317+
out = null;
316318
}
317319
finally
318320
{

src/main/java/org/codehaus/plexus/archiver/bzip2/BZip2Compressor.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
2121
import org.codehaus.plexus.archiver.ArchiverException;
2222
import org.codehaus.plexus.archiver.util.Compressor;
23-
import org.codehaus.plexus.util.IOUtil;
2423

2524
import java.io.IOException;
2625

@@ -56,7 +55,17 @@ public void compress()
5655

5756
public void close()
5857
{
59-
IOUtil.close( zOut );
60-
zOut = null;
58+
try
59+
{
60+
if ( this.zOut != null )
61+
{
62+
this.zOut.close();
63+
zOut = null;
64+
}
65+
}
66+
catch ( final IOException e )
67+
{
68+
throw new ArchiverException( "Failure closing target.", e );
69+
}
6170
}
6271
}

src/main/java/org/codehaus/plexus/archiver/gzip/GZipCompressor.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.codehaus.plexus.archiver.ArchiverException;
2121
import org.codehaus.plexus.archiver.util.Compressor;
2222
import org.codehaus.plexus.archiver.util.Streams;
23-
import org.codehaus.plexus.util.IOUtil;
2423

2524
import java.io.FileOutputStream;
2625
import java.io.IOException;
@@ -55,7 +54,17 @@ public void compress()
5554

5655
public void close()
5756
{
58-
IOUtil.close( zOut );
59-
zOut = null;
57+
try
58+
{
59+
if ( this.zOut != null )
60+
{
61+
this.zOut.close();
62+
zOut = null;
63+
}
64+
}
65+
catch ( final IOException e )
66+
{
67+
throw new ArchiverException( "Failure closing target.", e );
68+
}
6069
}
6170
}

src/main/java/org/codehaus/plexus/archiver/jar/JarArchiver.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ private Manifest getManifest( File manifestFile )
204204
try
205205
{
206206
in = new FileInputStream( manifestFile );
207-
return getManifest( in );
207+
final Manifest mf = getManifest( in );
208+
in.close();
209+
in = null;
210+
return mf;
208211
}
209212
catch ( IOException e )
210213
{

src/main/java/org/codehaus/plexus/archiver/jar/JdkManifestFactory.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,33 @@ class JdkManifestFactory
3232
public static java.util.jar.Manifest getDefaultManifest()
3333
throws ArchiverException
3434
{
35+
InputStream in = null;
36+
final String defManifest = "/org/codehaus/plexus/archiver/jar/defaultManifest.mf";
3537
try
3638
{
37-
String defManifest = "/org/codehaus/plexus/archiver/jar/defaultManifest.mf";
38-
InputStream in = JdkManifestFactory.class.getResourceAsStream( defManifest );
39+
in = JdkManifestFactory.class.getResourceAsStream( defManifest );
3940
if ( in == null )
4041
{
4142
throw new ArchiverException( "Could not find default manifest: " + defManifest );
4243
}
43-
try
44-
{
45-
java.util.jar.Manifest defaultManifest = new java.util.jar.Manifest( in );
44+
java.util.jar.Manifest defaultManifest = new java.util.jar.Manifest( in );
4645

47-
defaultManifest.getMainAttributes().putValue( "Created-By",
48-
System.getProperty( "java.vm.version" ) + " ("
49-
+ System.getProperty( "java.vm.vendor" ) + ")" );
50-
return defaultManifest;
51-
}
52-
finally
53-
{
54-
IOUtil.close( in );
55-
}
46+
in.close();
47+
in = null;
48+
49+
defaultManifest.getMainAttributes().putValue( "Created-By",
50+
System.getProperty( "java.vm.version" ) + " ("
51+
+ System.getProperty( "java.vm.vendor" ) + ")" );
52+
return defaultManifest;
5653
}
5754
catch ( IOException e )
5855
{
5956
throw new ArchiverException( "Unable to read default manifest", e );
6057
}
58+
finally
59+
{
60+
IOUtil.close( in );
61+
}
6162
}
6263

6364
public static void merge( java.util.jar.Manifest target, java.util.jar.Manifest other, boolean overwriteMain )

src/main/java/org/codehaus/plexus/archiver/jar/Manifest.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.io.PrintWriter;
2626
import java.io.Reader;
2727
import java.io.StringWriter;
28-
import java.io.UnsupportedEncodingException;
2928
import java.util.ArrayList;
3029
import java.util.Collection;
3130
import java.util.Enumeration;
@@ -739,29 +738,29 @@ public Iterator<String> iterator()
739738
public static Manifest getDefaultManifest()
740739
throws ArchiverException
741740
{
741+
InputStream in = null;
742+
Reader reader = null;
743+
final String defManifest = "/org/codehaus/plexus/archiver/jar/defaultManifest.mf";
742744
try
743745
{
744-
String defManifest = "/org/codehaus/plexus/archiver/jar/defaultManifest.mf";
745-
InputStream in = Manifest.class.getResourceAsStream( defManifest );
746+
in = Manifest.class.getResourceAsStream( defManifest );
746747
if ( in == null )
747748
{
748749
throw new ArchiverException( "Could not find default manifest: " + defManifest );
749750
}
750-
try
751-
{
752-
Manifest defaultManifest = new Manifest( new InputStreamReader( in, "UTF-8" ) );
753-
defaultManifest.getMainAttributes().putValue( "Created-By", System.getProperty(
754-
"java.vm.version" ) + " (" + System.getProperty( "java.vm.vendor" ) + ")" );
755-
return defaultManifest;
756-
}
757-
catch ( UnsupportedEncodingException e )
758-
{
759-
return new Manifest( new InputStreamReader( in ) );
760-
}
761-
finally
762-
{
763-
IOUtil.close( in );
764-
}
751+
reader = new InputStreamReader( in, "UTF-8" );
752+
final Manifest defaultManifest = new Manifest( reader );
753+
defaultManifest.getMainAttributes().putValue( "Created-By", System.getProperty(
754+
"java.vm.version" ) + " (" + System.getProperty(
755+
"java.vm.vendor" ) + ")" );
756+
757+
reader.close();
758+
reader = null;
759+
760+
in.close();
761+
in = null;
762+
763+
return defaultManifest;
765764
}
766765
catch ( ManifestException e )
767766
{
@@ -771,6 +770,11 @@ public static Manifest getDefaultManifest()
771770
{
772771
throw new ArchiverException( "Unable to read default manifest", e );
773772
}
773+
finally
774+
{
775+
IOUtil.close( in );
776+
IOUtil.close( reader );
777+
}
774778
}
775779

776780
/**

src/main/java/org/codehaus/plexus/archiver/snappy/SnappyCompressor.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import org.codehaus.plexus.archiver.ArchiverException;
2121
import org.codehaus.plexus.archiver.util.Compressor;
22-
import org.codehaus.plexus.util.IOUtil;
2322
import org.iq80.snappy.SnappyOutputStream;
2423

2524
import java.io.IOException;
@@ -53,9 +52,20 @@ public void compress()
5352
}
5453
}
5554

55+
@Override
5656
public void close()
5757
{
58-
IOUtil.close( zOut );
59-
zOut = null;
58+
try
59+
{
60+
if ( this.zOut != null )
61+
{
62+
this.zOut.close();
63+
zOut = null;
64+
}
65+
}
66+
catch ( final IOException e )
67+
{
68+
throw new ArchiverException( "Failure closing target.", e );
69+
}
6070
}
6171
}

src/main/java/org/codehaus/plexus/archiver/tar/TarArchiver.java

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -131,31 +131,30 @@ protected void execute()
131131

132132
getLogger().info( "Building tar: " + tarFile.getAbsolutePath() );
133133

134-
final OutputStream os = new FileOutputStream( tarFile );
135-
tOut = new TarArchiveOutputStream( compress( compression, os ), "UTF8" );
136-
if ( longFileMode.isTruncateMode() )
137-
{
138-
tOut.setLongFileMode( TarArchiveOutputStream.LONGFILE_TRUNCATE );
139-
}
140-
else if ( longFileMode.isPosixMode() || longFileMode.isPosixWarnMode() )
141-
{
142-
tOut.setLongFileMode( TarArchiveOutputStream.LONGFILE_POSIX );
143-
// Todo: Patch 2.5.1 for this fix. Also make closeable fix on 2.5.1
144-
tOut.setBigNumberMode( TarArchiveOutputStream.BIGNUMBER_POSIX );
145-
}
146-
else if ( longFileMode.isFailMode() || longFileMode.isOmitMode() )
147-
{
148-
tOut.setLongFileMode( TarArchiveOutputStream.LONGFILE_ERROR );
149-
}
150-
else
151-
{
152-
// warn or GNU
153-
tOut.setLongFileMode( TarArchiveOutputStream.LONGFILE_GNU );
154-
}
155-
156-
longWarningGiven = false;
157134
try
158135
{
136+
tOut = new TarArchiveOutputStream( compress( compression, new FileOutputStream( tarFile ) ), "UTF8" );
137+
if ( longFileMode.isTruncateMode() )
138+
{
139+
tOut.setLongFileMode( TarArchiveOutputStream.LONGFILE_TRUNCATE );
140+
}
141+
else if ( longFileMode.isPosixMode() || longFileMode.isPosixWarnMode() )
142+
{
143+
tOut.setLongFileMode( TarArchiveOutputStream.LONGFILE_POSIX );
144+
// Todo: Patch 2.5.1 for this fix. Also make closeable fix on 2.5.1
145+
tOut.setBigNumberMode( TarArchiveOutputStream.BIGNUMBER_POSIX );
146+
}
147+
else if ( longFileMode.isFailMode() || longFileMode.isOmitMode() )
148+
{
149+
tOut.setLongFileMode( TarArchiveOutputStream.LONGFILE_ERROR );
150+
}
151+
else
152+
{
153+
// warn or GNU
154+
tOut.setLongFileMode( TarArchiveOutputStream.LONGFILE_GNU );
155+
}
156+
157+
longWarningGiven = false;
159158
while ( iter.hasNext() )
160159
{
161160
ArchiveEntry entry = iter.next();
@@ -169,6 +168,8 @@ else if ( longFileMode.isFailMode() || longFileMode.isOmitMode() )
169168

170169
tarFile( entry, tOut, name );
171170
}
171+
172+
tOut.close();
172173
}
173174
finally
174175
{
@@ -496,13 +497,19 @@ protected void cleanUp()
496497
throws IOException
497498
{
498499
super.cleanUp();
499-
IOUtil.close( tOut );
500+
if ( this.tOut != null )
501+
{
502+
this.tOut.close();
503+
}
500504
}
501505

502506
protected void close()
503507
throws IOException
504508
{
505-
IOUtil.close( tOut );
509+
if ( this.tOut != null )
510+
{
511+
this.tOut.close();
512+
}
506513
}
507514

508515
protected String getArchiveType()

src/main/java/org/codehaus/plexus/archiver/tar/TarUnArchiver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ protected void execute( File sourceFile, File destDirectory )
114114

115115
}
116116
getLogger().debug( "expand complete" );
117-
117+
tis.close();
118+
tis = null;
118119
}
119120
catch ( IOException ioe )
120121
{

src/main/java/org/codehaus/plexus/archiver/util/Compressor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,13 @@ private void compressFile( InputStream in, OutputStream zOut )
9494
protected void compress( PlexusIoResource resource, OutputStream zOut )
9595
throws IOException
9696
{
97-
InputStream in = Streams.bufferedInputStream( resource.getContents() );
97+
InputStream in = null;
9898
try
9999
{
100+
in = Streams.bufferedInputStream( resource.getContents() );
100101
compressFile( in, zOut );
102+
in.close();
103+
in = null;
101104
}
102105
finally
103106
{
@@ -118,5 +121,6 @@ public abstract void compress()
118121
*
119122
* this is public so the process of compression and closing can be dealt with separately.
120123
*/
121-
public abstract void close();
124+
public abstract void close()
125+
throws ArchiverException;
122126
}

src/main/java/org/codehaus/plexus/archiver/util/ResourceUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ public static void copyFile( PlexusIoResource in, File outFile )
8484
input = in.getContents();
8585
output = new FileOutputStream( outFile );
8686
IOUtil.copy( input, output );
87+
output.close();
88+
output = null;
89+
input.close();
90+
input = null;
8791
}
8892
finally
8993
{
@@ -103,6 +107,10 @@ public static void copyFile( InputStream input, File outFile )
103107
{
104108
output = new FileOutputStream( outFile );
105109
IOUtil.copy( input, output );
110+
output.close();
111+
output = null;
112+
input.close();
113+
input = null;
106114
}
107115
finally
108116
{

src/main/java/org/codehaus/plexus/archiver/util/Streams.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ public static void copyFully( @WillClose InputStream zIn, @WillClose OutputStrea
9595
try
9696
{
9797
copyFullyDontCloseOutput( zIn, out, gzip );
98+
out.close();
99+
out = null;
100+
}
101+
catch ( final IOException e )
102+
{
103+
throw new ArchiverException( "Failure copying.", e );
98104
}
99105
finally
100106
{
@@ -125,6 +131,8 @@ public static void copyFullyDontCloseOutput( @WillClose InputStream zIn, @WillNo
125131
count = zIn.read( buffer, 0, buffer.length );
126132
}
127133
while ( count != -1 );
134+
zIn.close();
135+
zIn = null;
128136
}
129137
catch ( IOException e )
130138
{

src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipArchiver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ protected boolean createEmptyZip( File zipFile )
669669
empty[3] = 6;
670670
// remainder zeros
671671
os.write( empty );
672+
os.close();
673+
os = null;
672674
}
673675
catch ( IOException ioe )
674676
{

0 commit comments

Comments
 (0)