Skip to content

Commit 3f48dce

Browse files
committed
[PLXCOMP-238] Failure when compress=false and files <= 4 bytes
1 parent a4964f3 commit 3f48dce

File tree

7 files changed

+24
-11
lines changed

7 files changed

+24
-11
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ protected InputStream getInputStream( File file )
4646

4747

4848
@Override protected PlexusIoResourceAttributes getAttributes(File file) throws IOException {
49-
final BasicFileAttributes posixFileAttributes = Java7AttributeUtils.getFileAttributes( file );
50-
PlexusIoResourceAttributes attrs = new Java7FileAttributes(file, posixFileAttributes, new HashMap<Integer, String>(), new HashMap<Integer, String>());
51-
return attrs;
49+
return new Java7FileAttributes(file, new HashMap<Integer, String>(), new HashMap<Integer, String>());
5250
}
5351

5452
protected String getDefaultExtension()

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ protected InputStream getInputStream( File file )
4545
}
4646

4747
@Override protected PlexusIoResourceAttributes getAttributes(File file) throws IOException {
48-
final BasicFileAttributes posixFileAttributes = Java7AttributeUtils.getFileAttributes( file );
49-
PlexusIoResourceAttributes attrs = new Java7FileAttributes(file, posixFileAttributes, new HashMap<Integer, String>(), new HashMap<Integer, String>());
50-
return attrs;
48+
return new Java7FileAttributes(file, new HashMap<Integer, String>(), new HashMap<Integer, String>());
5149
}
5250
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,16 @@ protected final void addParentDirs( File baseDir, String entry, ZipArchiveOutput
444444
}
445445
}
446446

447-
private void readWithZipStats(InputStream in, byte[] header, ZipArchiveEntry ze, ByteArrayOutputStream bos) throws IOException {
447+
private void readWithZipStats( InputStream in, byte[] header, int headerRead, ZipArchiveEntry ze,
448+
ByteArrayOutputStream bos ) throws IOException {
448449
byte[] buffer = new byte[8 * 1024];
449450

450451
CRC32 cal2 = new CRC32();
451452

452453
long size = 0;
453454

454-
for (byte aHeader : header) {
455-
cal2.update(aHeader);
455+
for (int i = 0; i < headerRead; i++){
456+
cal2.update(header[i]);
456457
size++;
457458
}
458459

@@ -544,7 +545,7 @@ protected void zipFile( InputStream in, ZipArchiveOutputStream zOut, String vPat
544545
if (in.markSupported())
545546
{
546547
in.mark( Integer.MAX_VALUE );
547-
readWithZipStats(in, header, ze, null);
548+
readWithZipStats(in, header, read, ze, null);
548549
in.reset();
549550
zOut.putArchiveEntry( ze);
550551
if (read > 0) zOut.write(header, 0, read);
@@ -553,8 +554,9 @@ protected void zipFile( InputStream in, ZipArchiveOutputStream zOut, String vPat
553554
else
554555
{
555556
// Store data into a byte[]
557+
// todo: explain how on earth this code works with zip streams > 128KB ???
556558
ByteArrayOutputStream bos = new ByteArrayOutputStream(128 * 1024);
557-
readWithZipStats(in, header, ze, bos);
559+
readWithZipStats(in, header,read, ze, bos);
558560
zOut.putArchiveEntry(ze);
559561
if (read > 0) zOut.write(header, 0, read);
560562
bos.writeTo( zOut);

src/test/java/org/codehaus/plexus/archiver/jar/JarArchiverTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.IOException;
77

88
import junit.framework.TestCase;
9+
import org.codehaus.plexus.archiver.FileSet;
910

1011
public class JarArchiverTest
1112
extends TestCase
@@ -30,4 +31,16 @@ public void testCreateManifestOnlyJar()
3031
archiver.createArchive();
3132
}
3233

34+
public void testNonCompressed()
35+
throws IOException, ManifestException, ArchiverException
36+
{
37+
File jarFile = new File("target/output/jarArchiveNonCompressed.jar" );
38+
39+
JarArchiver archiver = new JarArchiver();
40+
archiver.setDestFile( jarFile );
41+
archiver.setCompress( false );
42+
archiver.addDirectory( new File( "src/test/resources/mjar179" ) );
43+
archiver.createArchive();
44+
}
45+
3346
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
messageKey=Hello world !

src/test/resources/mjar179/Messages_en.properties

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
messageKey=Bonjour le monde !

0 commit comments

Comments
 (0)