You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2019/10/22 09:02:31 UTC

[maven-surefire] branch master updated: [SUREFIRE-1702] [JDK 11 Alpine Linux] JAR content is not flushed completely down to drive "Error: Invalid or corrupt jarfile target/surefire/surefirebooter13749914711390838584.jar"

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/master by this push:
     new 8a886f3  [SUREFIRE-1702] [JDK 11 Alpine Linux] JAR content is not flushed completely down to drive "Error: Invalid or corrupt jarfile target/surefire/surefirebooter13749914711390838584.jar"
8a886f3 is described below

commit 8a886f3a44e23fc2bdcebac3804064e228a88b2a
Author: tibordigana <ti...@apache.org>
AuthorDate: Tue Oct 22 10:50:57 2019 +0200

    [SUREFIRE-1702] [JDK 11 Alpine Linux] JAR content is not flushed completely down to drive "Error: Invalid or corrupt jarfile target/surefire/surefirebooter13749914711390838584.jar"
---
 maven-surefire-common/pom.xml                      | 10 +++++++++
 .../booterclient/JarManifestForkConfiguration.java | 26 +++++++++++++---------
 pom.xml                                            |  6 +++++
 3 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/maven-surefire-common/pom.xml b/maven-surefire-common/pom.xml
index 9ef6014..ca690d4 100644
--- a/maven-surefire-common/pom.xml
+++ b/maven-surefire-common/pom.xml
@@ -92,6 +92,11 @@
             <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>
             <scope>provided</scope>
@@ -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>
@@ -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>
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java
index 1a3dd4f..dda6d3e 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java
@@ -19,6 +19,9 @@ package org.apache.maven.plugin.surefire.booterclient;
  * 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;
@@ -28,9 +31,11 @@ import org.apache.maven.surefire.booter.SurefireBooterForkException;
 
 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;
@@ -40,9 +45,8 @@ import java.util.Iterator;
 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;
@@ -109,12 +113,15 @@ public final class JarManifestForkConfiguration
             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();
 
@@ -146,10 +153,9 @@ public final class JarManifestForkConfiguration
             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;
         }
diff --git a/pom.xml b/pom.xml
index 7d3e876..1cc826b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
@@ -109,6 +110,11 @@
     <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>
         <version>${commonsLang3Version}</version>
       </dependency>