Skip to content

Commit f6dd097

Browse files
committed
[MASSEMBLY-768] Switched to using ConcurrentJarCreator, which preserves order inside zip
1 parent bb30b10 commit f6dd097

File tree

4 files changed

+37
-54
lines changed

4 files changed

+37
-54
lines changed

src/main/java/org/codehaus/plexus/archiver/ear/EarArchiver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.codehaus.plexus.archiver.ArchiverException;
2323
import org.codehaus.plexus.archiver.jar.JarArchiver;
2424
import org.codehaus.plexus.archiver.util.ResourceUtils;
25+
import org.codehaus.plexus.archiver.zip.ConcurrentJarCreator;
2526

2627
import java.io.File;
2728
import java.io.IOException;
@@ -79,7 +80,7 @@ public void addArchives( File directoryName, String[] includes, String[] exclude
7980
addDirectory( directoryName, "/", includes, excludes );
8081
}
8182

82-
protected void initZipOutputStream( ParallelScatterZipCreator zOut )
83+
protected void initZipOutputStream( ConcurrentJarCreator zOut )
8384
throws ArchiverException, IOException
8485
{
8586
// If no webxml file is specified, it's an error.
@@ -94,7 +95,7 @@ protected void initZipOutputStream( ParallelScatterZipCreator zOut )
9495
/**
9596
* Overridden from ZipArchiver class to deal with application.xml
9697
*/
97-
protected void zipFile( ArchiveEntry entry, ParallelScatterZipCreator zOut, String vPath, int mode )
98+
protected void zipFile( ArchiveEntry entry, ConcurrentJarCreator zOut, String vPath, int mode )
9899
throws IOException, ArchiverException
99100
{
100101
// If the file being added is META-INF/application.xml, we

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

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,23 @@
1717
* limitations under the License.
1818
*/
1919

20-
import org.apache.commons.compress.archivers.zip.ParallelScatterZipCreator;
20+
import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream;
21+
import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream;
22+
23+
import java.io.*;
24+
import java.util.*;
25+
26+
import javax.annotation.WillClose;
27+
2128
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
2229
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
2330
import org.codehaus.plexus.archiver.ArchiverException;
31+
import org.codehaus.plexus.archiver.zip.ConcurrentJarCreator;
2432
import org.codehaus.plexus.archiver.zip.ZipArchiver;
2533
import org.codehaus.plexus.logging.Logger;
2634
import org.codehaus.plexus.logging.console.ConsoleLogger;
2735
import org.codehaus.plexus.util.IOUtil;
2836

29-
import javax.annotation.WillClose;
30-
import java.io.ByteArrayInputStream;
31-
import java.io.ByteArrayOutputStream;
32-
import java.io.File;
33-
import java.io.FileInputStream;
34-
import java.io.IOException;
35-
import java.io.InputStream;
36-
import java.io.OutputStreamWriter;
37-
import java.io.PrintWriter;
38-
import java.util.ArrayList;
39-
import java.util.Collections;
40-
import java.util.Comparator;
41-
import java.util.Enumeration;
42-
import java.util.HashSet;
43-
import java.util.Iterator;
44-
import java.util.List;
45-
import java.util.Set;
46-
import java.util.SortedMap;
47-
import java.util.StringTokenizer;
48-
import java.util.TreeMap;
49-
import java.util.Vector;
50-
51-
import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream;
52-
import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream;
53-
5437
/**
5538
* Base class for tasks that build archives in JAR file format.
5639
*
@@ -286,7 +269,7 @@ public void addConfiguredIndexJars( File indexJar )
286269
indexJars.add( indexJar.getAbsolutePath() );
287270
}
288271

289-
protected void initZipOutputStream( ParallelScatterZipCreator zOut )
272+
protected void initZipOutputStream( ConcurrentJarCreator zOut )
290273
throws ArchiverException, IOException
291274
{
292275
if ( !skipWriting )
@@ -336,7 +319,7 @@ private Manifest createManifest()
336319
return finalManifest;
337320
}
338321

339-
private void writeManifest( ParallelScatterZipCreator zOut, Manifest manifest )
322+
private void writeManifest( ConcurrentJarCreator zOut, Manifest manifest )
340323
throws IOException, ArchiverException
341324
{
342325
for ( Enumeration e = manifest.getWarnings(); e.hasMoreElements(); )
@@ -354,7 +337,7 @@ private void writeManifest( ParallelScatterZipCreator zOut, Manifest manifest )
354337
super.initZipOutputStream( zOut );
355338
}
356339

357-
protected void finalizeZipOutputStream( ParallelScatterZipCreator zOut )
340+
protected void finalizeZipOutputStream( ConcurrentJarCreator zOut )
358341
throws IOException, ArchiverException
359342
{
360343
if ( index )
@@ -375,7 +358,7 @@ protected void finalizeZipOutputStream( ParallelScatterZipCreator zOut )
375358
* @throws org.codehaus.plexus.archiver.ArchiverException
376359
* .
377360
*/
378-
private void createIndexList( ParallelScatterZipCreator zOut )
361+
private void createIndexList( ConcurrentJarCreator zOut )
379362
throws IOException, ArchiverException
380363
{
381364
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -457,7 +440,7 @@ private void createIndexList( ParallelScatterZipCreator zOut )
457440
/**
458441
* Overridden from Zip class to deal with manifests and index lists.
459442
*/
460-
protected void zipFile( @WillClose InputStream is, ParallelScatterZipCreator zOut, String vPath, long lastModified, File fromArchive,
443+
protected void zipFile( @WillClose InputStream is, ConcurrentJarCreator zOut, String vPath, long lastModified, File fromArchive,
461444
int mode, String symlinkDestination )
462445
throws IOException, ArchiverException
463446
{
@@ -550,7 +533,7 @@ protected boolean createEmptyZip( File zipFile )
550533
{
551534
zipArchiveOutputStream.setMethod(ZipArchiveOutputStream.STORED);
552535
}
553-
ParallelScatterZipCreator ps = new ParallelScatterZipCreator();
536+
ConcurrentJarCreator ps = new ConcurrentJarCreator(Runtime.getRuntime().availableProcessors());
554537
initZipOutputStream( ps );
555538
finalizeZipOutputStream( ps );
556539
}

src/main/java/org/codehaus/plexus/archiver/war/WarArchiver.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
*
1818
*/
1919

20-
import org.apache.commons.compress.archivers.zip.ParallelScatterZipCreator;
2120
import org.codehaus.plexus.archiver.ArchiveEntry;
2221
import org.codehaus.plexus.archiver.ArchiverException;
2322
import org.codehaus.plexus.archiver.jar.JarArchiver;
2423
import org.codehaus.plexus.archiver.util.ResourceUtils;
24+
import org.codehaus.plexus.archiver.zip.ConcurrentJarCreator;
2525

2626
import java.io.File;
2727
import java.io.IOException;
@@ -152,9 +152,9 @@ public void addWebinf( File directoryName, String[] includes, String[] excludes
152152
/**
153153
* override of parent; validates configuration
154154
* before initializing the output stream.
155-
* @param zOut
156-
*/
157-
protected void initZipOutputStream( ParallelScatterZipCreator zOut )
155+
* @param zOut
156+
*/
157+
protected void initZipOutputStream( ConcurrentJarCreator zOut )
158158
throws ArchiverException, IOException
159159
{
160160
// If no webxml file is specified, it's an error.
@@ -168,7 +168,7 @@ protected void initZipOutputStream( ParallelScatterZipCreator zOut )
168168
/**
169169
* Overridden from ZipArchiver class to deal with web.xml
170170
*/
171-
protected void zipFile( ArchiveEntry entry, ParallelScatterZipCreator zOut, String vPath )
171+
protected void zipFile( ArchiveEntry entry, ConcurrentJarCreator zOut, String vPath )
172172
throws IOException, ArchiverException
173173
{
174174
// If the file being added is WEB-INF/web.xml, we warn if it's

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public abstract class AbstractZipArchiver
130130

131131
private boolean success;
132132

133-
private ParallelScatterZipCreator zOut;
133+
private ConcurrentJarCreator zOut;
134134

135135
protected ZipArchiveOutputStream zipArchiveOutputStream;
136136

@@ -225,7 +225,7 @@ protected void execute()
225225
finalizeZipOutputStream( zOut );
226226
}
227227

228-
protected void finalizeZipOutputStream( ParallelScatterZipCreator zOut )
228+
protected void finalizeZipOutputStream( ConcurrentJarCreator zOut )
229229
throws IOException, ArchiverException
230230
{
231231
}
@@ -313,7 +313,7 @@ private void createArchiveMain()
313313
zipArchiveOutputStream.setMethod(
314314
doCompress ? ZipArchiveOutputStream.DEFLATED : ZipArchiveOutputStream.STORED );
315315

316-
zOut = new ParallelScatterZipCreator();
316+
zOut = new ConcurrentJarCreator(Runtime.getRuntime().availableProcessors());
317317
}
318318
initZipOutputStream( zOut );
319319

@@ -339,7 +339,7 @@ private void createArchiveMain()
339339
* @param zOut the stream to write to
340340
*/
341341
@SuppressWarnings( { "JavaDoc" } )
342-
protected final void addResources( ResourceIterator resources, ParallelScatterZipCreator zOut )
342+
protected final void addResources( ResourceIterator resources, ConcurrentJarCreator zOut )
343343
throws IOException, ArchiverException
344344
{
345345
while ( resources.hasNext() )
@@ -379,7 +379,7 @@ protected final void addResources( ResourceIterator resources, ParallelScatterZi
379379
* be impossible and is not really supported.
380380
*/
381381
@SuppressWarnings( { "JavaDoc" } )
382-
private void addParentDirs(ArchiveEntry archiveEntry, File baseDir, String entry, ParallelScatterZipCreator zOut)
382+
private void addParentDirs(ArchiveEntry archiveEntry, File baseDir, String entry, ConcurrentJarCreator zOut)
383383
throws IOException
384384
{
385385
if ( !doFilesonly && getIncludeEmptyDirs() )
@@ -417,7 +417,7 @@ private void addParentDirs(ArchiveEntry archiveEntry, File baseDir, String entry
417417
* @param symlinkDestination
418418
*/
419419
@SuppressWarnings( { "JavaDoc" } )
420-
protected void zipFile( @WillClose InputStream in, ParallelScatterZipCreator zOut, String vPath, long lastModified,
420+
protected void zipFile( @WillClose InputStream in, ConcurrentJarCreator zOut, String vPath, long lastModified,
421421
File fromArchive, int mode, String symlinkDestination )
422422
throws IOException, ArchiverException
423423
{
@@ -472,13 +472,12 @@ private boolean isZipHeader( byte[] header )
472472
* Method that gets called when adding from java.io.File instances.
473473
* <p/>
474474
* <p>This implementation delegates to the six-arg version.</p>
475-
*
476-
* @param entry the file to add to the archive
475+
* @param entry the file to add to the archive
477476
* @param zOut the stream to write to
478-
* @param vPath the name this entry shall have in the archive
479-
*/
477+
* @param vPath the name this entry shall have in the archive
478+
*/
480479
@SuppressWarnings( { "JavaDoc" } )
481-
protected void zipFile( ArchiveEntry entry, ParallelScatterZipCreator zOut, String vPath )
480+
protected void zipFile( ArchiveEntry entry, ConcurrentJarCreator zOut, String vPath )
482481
throws IOException, ArchiverException
483482
{
484483
final PlexusIoResource resource = entry.getResource();
@@ -518,7 +517,7 @@ private void setTime( java.util.zip.ZipEntry zipEntry, long lastModified )
518517
*/
519518
}
520519

521-
protected void zipDir( PlexusIoResource dir, ParallelScatterZipCreator zOut, String vPath, int mode,
520+
protected void zipDir( PlexusIoResource dir, ConcurrentJarCreator zOut, String vPath, int mode,
522521
String encodingToUse )
523522
throws IOException
524523
{
@@ -683,9 +682,9 @@ public void reset()
683682
/**
684683
* method for subclasses to override
685684
*
686-
* @param zOut The output stream
687-
*/
688-
protected void initZipOutputStream( ParallelScatterZipCreator zOut )
685+
* @param zOut The output stream
686+
*/
687+
protected void initZipOutputStream( ConcurrentJarCreator zOut )
689688
throws ArchiverException, IOException
690689
{
691690
}

0 commit comments

Comments
 (0)