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 2018/12/09 11:40:01 UTC

[maven-surefire] 03/03: [SUREFIRE-1608] dump error paths with the same root cause in Boot Manifest-JAR only once without stacktrace

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

commit 9c443740b26caebe9be20925906778f489cd3b33
Author: Tibor17 <ti...@apache.org>
AuthorDate: Fri Dec 7 01:23:34 2018 +0100

    [SUREFIRE-1608] dump error paths with the same root cause in Boot Manifest-JAR only once without stacktrace
---
 .../booterclient/JarManifestForkConfiguration.java | 53 +++++++++++++++++-----
 .../JarManifestForkConfigurationTest.java          | 26 ++++++-----
 2 files changed, 56 insertions(+), 23 deletions(-)

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 79db5c6..62fa4c1 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
@@ -45,6 +45,7 @@ import java.util.jar.Manifest;
 
 import static java.nio.file.Files.isDirectory;
 import static org.apache.maven.plugin.surefire.SurefireHelper.escapeToPlatformPath;
+import static org.apache.maven.surefire.util.internal.StringUtils.NL;
 
 /**
  * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
@@ -113,15 +114,20 @@ public final class JarManifestForkConfiguration
 
             Manifest man = new Manifest();
 
+            boolean dumpError = true;
+
             // we can't use StringUtils.join here since we need to add a '/' to
             // the end of directory entries - otherwise the jvm will ignore them.
             StringBuilder cp = new StringBuilder();
             for ( Iterator<String> it = classPath.iterator(); it.hasNext(); )
             {
                 Path classPathElement = Paths.get( it.next() );
-                String uri = toClasspathElementUri( parent, classPathElement, dumpLogDirectory );
-                cp.append( uri );
-                if ( isDirectory( classPathElement ) && !uri.endsWith( "/" ) )
+                ClasspathElementUri classpathElementUri =
+                        toClasspathElementUri( parent, classPathElement, dumpLogDirectory, dumpError );
+                // too many errors in dump file with the same root cause may slow down the Boot Manifest-JAR startup
+                dumpError &= !classpathElementUri.absolute;
+                cp.append( classpathElementUri.uri );
+                if ( isDirectory( classPathElement ) && !classpathElementUri.uri.endsWith( "/" ) )
                 {
                     cp.append( '/' );
                 }
@@ -158,9 +164,10 @@ public final class JarManifestForkConfiguration
                 .toASCIIString();
     }
 
-    static String toClasspathElementUri( @Nonnull Path parent,
+    static ClasspathElementUri toClasspathElementUri( @Nonnull Path parent,
                                          @Nonnull Path classPathElement,
-                                         @Nonnull File dumpLogDirectory )
+                                         @Nonnull File dumpLogDirectory,
+                                         boolean dumpError )
             throws IOException
     {
         try
@@ -168,16 +175,22 @@ public final class JarManifestForkConfiguration
             String relativeUriPath = relativize( parent, classPathElement )
                     .replace( '\\', '/' );
 
-            return new URI( null, relativeUriPath, null )
-                    .toASCIIString();
+            return new ClasspathElementUri( new URI( null, relativeUriPath, null ) );
         }
         catch ( IllegalArgumentException e )
         {
-            String error = "Boot Manifest-JAR contains absolute paths in classpath " + classPathElement;
-            InPluginProcessDumpSingleton.getSingleton()
-                    .dumpException( e, error, dumpLogDirectory );
+            if ( dumpError )
+            {
+                String error = "Boot Manifest-JAR contains absolute paths in classpath '"
+                        + classPathElement
+                        + "'"
+                        + NL
+                        + "Hint: <argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>";
+                InPluginProcessDumpSingleton.getSingleton()
+                        .dumpStreamText( error, dumpLogDirectory );
+            }
 
-            return toAbsoluteUri( classPathElement );
+            return new ClasspathElementUri( toAbsoluteUri( classPathElement ) );
         }
         catch ( URISyntaxException e )
         {
@@ -188,4 +201,22 @@ public final class JarManifestForkConfiguration
                     + parent, e );
         }
     }
+
+    static final class ClasspathElementUri
+    {
+        final String uri;
+        final boolean absolute;
+
+        ClasspathElementUri( String uri )
+        {
+            this.uri = uri;
+            absolute = true;
+        }
+
+        ClasspathElementUri( URI uri )
+        {
+            this.uri = uri.toASCIIString();
+            absolute = false;
+        }
+    }
 }
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfigurationTest.java
index 18b205a..5e71238 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfigurationTest.java
@@ -24,6 +24,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.nio.file.Path;
 
+import org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.ClasspathElementUri;
 import org.apache.maven.plugin.surefire.booterclient.output.InPluginProcessDumpSingleton;
 
 import static org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.relativize;
@@ -38,6 +39,7 @@ import org.junit.runner.RunWith;
 
 import static org.fest.util.Files.delete;
 import static org.fest.util.Files.newTemporaryFolder;
+import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.same;
 import static org.powermock.api.mockito.PowerMockito.mock;
 import static org.powermock.api.mockito.PowerMockito.mockStatic;
@@ -84,9 +86,9 @@ public class JarManifestForkConfigurationTest
         when( classPathElement.toString() ).thenReturn( "/home/me/.m2/repository/grp/art/1.0/art-1.0.jar" );
         when( relativize( parent, classPathElement ) )
                 .thenReturn( "../../../.m2/repository/grp/art/1.0/art-1.0.jar" );
-        when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ) ) )
+        when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ), anyBoolean() ) )
                 .thenCallRealMethod();
-        assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory ) )
+        assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory, true ).uri )
                 .isEqualTo( "../../../.m2/repository/grp/art/1.0/art-1.0.jar" );
     }
 
@@ -101,9 +103,9 @@ public class JarManifestForkConfigurationTest
         when( classPathElement.toString() ).thenReturn( "/the Maven repo/grp/art/1.0/art-1.0.jar" );
         when( relativize( parent, classPathElement ) )
                 .thenReturn( "../../../../../the Maven repo/grp/art/1.0/art-1.0.jar" );
-        when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ) ) )
+        when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ), anyBoolean() ) )
                 .thenCallRealMethod();
-        assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory ) )
+        assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory, true ).uri )
                 .isEqualTo( "../../../../../the%20Maven%20repo/grp/art/1.0/art-1.0.jar" );
     }
 
@@ -118,9 +120,9 @@ public class JarManifestForkConfigurationTest
         when( classPathElement.toString() ).thenReturn( "C:\\Users\\me\\.m2\\repository\\grp\\art\\1.0\\art-1.0.jar" );
         when( relativize( parent, classPathElement ) )
                 .thenReturn( "..\\..\\..\\Users\\me\\.m2\\repository\\grp\\art\\1.0\\art-1.0.jar" );
-        when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ) ) )
+        when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ), anyBoolean() ) )
                 .thenCallRealMethod();
-        assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory ) )
+        assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory, true ).uri )
                 .isEqualTo( "../../../Users/me/.m2/repository/grp/art/1.0/art-1.0.jar" );
     }
 
@@ -135,9 +137,9 @@ public class JarManifestForkConfigurationTest
         when( classPathElement.toString() ).thenReturn( "C:\\Test User\\me\\.m2\\repository\\grp\\art\\1.0\\art-1.0.jar" );
         when( relativize( parent, classPathElement ) )
                 .thenReturn( "..\\..\\..\\Test User\\me\\.m2\\repository\\grp\\art\\1.0\\art-1.0.jar" );
-        when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ) ) )
+        when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ), anyBoolean() ) )
                 .thenCallRealMethod();
-        assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory ) )
+        assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory, true ).uri )
                 .isEqualTo( "../../../Test%20User/me/.m2/repository/grp/art/1.0/art-1.0.jar" );
     }
 
@@ -164,11 +166,11 @@ public class JarManifestForkConfigurationTest
                 } );
         when( relativize( same( parent ), same( classPathElement ) ) )
                 .thenThrow( new IllegalArgumentException() );
-        when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ) ) )
+        when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ), anyBoolean() ) )
                 .thenCallRealMethod();
         when( toAbsoluteUri( same( classPathElement ) ) )
                 .thenCallRealMethod();
-        assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory ) )
+        assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory, true ).uri )
                 .isEqualTo( "file:///X:/Users/me/.m2/repository/grp/art/1.0/art-1.0.jar" );
     }
 
@@ -213,9 +215,9 @@ public class JarManifestForkConfigurationTest
         Path testDir = new File( TMP, "@3 test with white spaces" )
                 .toPath();
 
-        String testDirUriPath = toClasspathElementUri( parentDir, testDir, dumpDirectory );
+        ClasspathElementUri testDirUriPath = toClasspathElementUri( parentDir, testDir, dumpDirectory, true );
 
-        assertThat( testDirUriPath )
+        assertThat( testDirUriPath.uri )
                 .isEqualTo( "../@3%20test%20with%20white%20spaces" );
     }
 }