Skip to content

Commit

Permalink
[SUREFIRE-1702] [JDK 11 Alpine Linux] JAR content is not flushed comp…
Browse files Browse the repository at this point in the history
…letely down to drive "Error: Invalid or corrupt jarfile target/surefire/surefirebooter13749914711390838584.jar"
  • Loading branch information
Tibor17 committed Oct 22, 2019
1 parent b97df5a commit 8a886f3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
10 changes: 10 additions & 0 deletions maven-surefire-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand Down Expand Up @@ -195,6 +200,7 @@
<include>org.apache.maven.shared:maven-common-artifact-filters</include>
<include>commons-io:commons-io</include>
<include>org.apache.commons:commons-lang3</include>
<include>org.apache.commons:commons-compress</include>
</includes>
</artifactSet>
<relocations>
Expand All @@ -210,6 +216,10 @@
<pattern>org.apache.commons.lang3</pattern>
<shadedPattern>org.apache.maven.surefire.shade.common.org.apache.commons.lang3</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons.compress</pattern>
<shadedPattern>org.apache.maven.surefire.shade.common.org.apache.commons.compress</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* under the License.
*/

import org.apache.commons.compress.archivers.zip.Zip64Mode;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.OutputStreamFlushableCommandline;
import org.apache.maven.plugin.surefire.booterclient.output.InPluginProcessDumpSingleton;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
Expand All @@ -28,9 +31,11 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
Expand All @@ -40,9 +45,8 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.zip.Deflater;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.Files.isDirectory;
Expand Down Expand Up @@ -109,12 +113,15 @@ private File createJar( @Nonnull List<String> classPath, @Nonnull String startCl
file.deleteOnExit();
}
Path parent = file.getParentFile().toPath();
FileOutputStream fos = new FileOutputStream( file );
try ( JarOutputStream jos = new JarOutputStream( fos ) )
OutputStream fos = new BufferedOutputStream( new FileOutputStream( file ), 64 * 1024 );

try ( ZipArchiveOutputStream zos = new ZipArchiveOutputStream( fos ) )
{
jos.setLevel( JarOutputStream.STORED );
JarEntry je = new JarEntry( "META-INF/MANIFEST.MF" );
jos.putNextEntry( je );
zos.setUseZip64( Zip64Mode.Never );
zos.setLevel( Deflater.NO_COMPRESSION );

ZipArchiveEntry ze = new ZipArchiveEntry( "META-INF/MANIFEST.MF" );
zos.putArchiveEntry( ze );

Manifest man = new Manifest();

Expand Down Expand Up @@ -146,10 +153,9 @@ private File createJar( @Nonnull List<String> classPath, @Nonnull String startCl
man.getMainAttributes().putValue( "Class-Path", cp.toString().trim() );
man.getMainAttributes().putValue( "Main-Class", startClassName );

man.write( jos );
man.write( zos );

jos.closeEntry();
jos.flush();
zos.closeArchiveEntry();

return file;
}
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<mavenVersion>3.0</mavenVersion>
<!-- <shadedVersion>3.0.0-M2</shadedVersion> commented out due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
<commonsLang3Version>3.8.1</commonsLang3Version>
<commonsCompress>1.19</commonsCompress>
<commonsIoVersion>2.6</commonsIoVersion>
<doxiaVersion>1.9</doxiaVersion>
<doxiaSitetoolsVersion>1.9.1</doxiaSitetoolsVersion>
Expand All @@ -107,6 +108,11 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>${commonsCompress}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down

0 comments on commit 8a886f3

Please sign in to comment.