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/02 08:10:48 UTC

[maven-surefire] branch master updated: [SUREFIRE-1605] NoClassDefFoundError (RunNotifier) with JDK 11

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 19f872d  [SUREFIRE-1605] NoClassDefFoundError (RunNotifier) with JDK 11
19f872d is described below

commit 19f872d514acb46522274a41fb1c8c62faf0eb0f
Author: Tibor17 <ti...@apache.org>
AuthorDate: Sun Dec 2 00:27:12 2018 +0100

    [SUREFIRE-1605] NoClassDefFoundError (RunNotifier) with JDK 11
---
 .../maven/plugin/surefire/AbstractSurefireMojo.java | 21 +++++++++++++++++++--
 .../surefire/AbstractSurefireMojoJava7PlusTest.java | 13 ++++++++++++-
 pom.xml                                             |  2 +-
 3 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index b6ae1bb..6f973b8 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -89,6 +89,7 @@ import java.io.File;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -1709,8 +1710,16 @@ public abstract class AbstractSurefireMojo
             String providerName = provider.getProviderName();
             if ( canExecuteProviderWithModularPath( platform ) && !isInprocess )
             {
+                String jvmExecutable = platform.getJdkExecAttributesForTests().getJvmExecutable();
+                String javaHome = Paths.get( jvmExecutable )
+                        .toAbsolutePath()
+                        .normalize()
+                        .getParent()
+                        .getParent()
+                        .toString();
+
                 return newStartupConfigWithModularPath( classLoaderConfiguration, providerArtifacts, providerName,
-                        getModuleDescriptor(), scanResult );
+                        getModuleDescriptor(), scanResult, javaHome );
             }
             else
             {
@@ -1801,7 +1810,8 @@ public abstract class AbstractSurefireMojo
 
     private StartupConfiguration newStartupConfigWithModularPath(
             @Nonnull ClassLoaderConfiguration classLoaderConfiguration, @Nonnull Set<Artifact> providerArtifacts,
-            @Nonnull String providerName, @Nonnull File moduleDescriptor, @Nonnull DefaultScanResult scanResult )
+            @Nonnull String providerName, @Nonnull File moduleDescriptor, @Nonnull DefaultScanResult scanResult,
+            @Nonnull String javaHome )
             throws IOException
     {
         TestClassPath testClasspathWrapper = generateTestClasspath();
@@ -1816,9 +1826,16 @@ public abstract class AbstractSurefireMojo
         }
 
         ResolvePathsRequest<String> req = ResolvePathsRequest.ofStrings( testClasspath.getClassPath() )
+                .setJdkHome( javaHome )
                 .setMainModuleDescriptor( moduleDescriptor.getAbsolutePath() );
 
         ResolvePathsResult<String> result = getLocationManager().resolvePaths( req );
+        for ( Entry<String, Exception> entry : result.getPathExceptions().entrySet() )
+        {
+            getConsoleLogger()
+                    .warning( "Exception for '" + entry.getKey() + "' (probably JDK version < 9).",
+                            entry.getValue() );
+        }
 
         testClasspath = new Classpath( result.getClasspathElements() );
         Classpath testModulepath = new Classpath( result.getModulepathElements().keySet() );
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java
index 6903995..d2ef230 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java
@@ -50,6 +50,7 @@ import java.util.Set;
 
 import static java.util.Arrays.asList;
 import static java.util.Collections.singleton;
+import static java.util.Collections.singletonMap;
 import static org.apache.maven.artifact.versioning.VersionRange.createFromVersion;
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.anyString;
@@ -135,6 +136,7 @@ public class AbstractSurefireMojoJava7PlusTest
         ResolvePathsRequest<String> req = mock( ResolvePathsRequest.class );
         mockStatic( ResolvePathsRequest.class );
         when( ResolvePathsRequest.ofStrings( eq( testClasspath.toClasspath().getClassPath() ) ) ).thenReturn( req );
+        when( req.setJdkHome( anyString() ) ).thenReturn( req );
         when( req.setMainModuleDescriptor( eq( moduleInfo.getAbsolutePath() ) ) ).thenReturn( req );
 
         @SuppressWarnings( "unchecked" )
@@ -144,6 +146,7 @@ public class AbstractSurefireMojoJava7PlusTest
         mod.put( "modular.jar", null );
         mod.put( "classes", null );
         when( res.getModulepathElements() ).thenReturn( mod );
+        when( res.getPathExceptions() ).thenReturn( singletonMap( "java 1.8", new Exception( "low version" ) ) );
         when( locationManager.resolvePaths( eq( req ) ) ).thenReturn( res );
 
         Logger logger = mock( Logger.class );
@@ -152,7 +155,8 @@ public class AbstractSurefireMojoJava7PlusTest
         when( mojo.getConsoleLogger() ).thenReturn( new PluginConsoleLogger( logger ) );
 
         StartupConfiguration conf = invokeMethod( mojo, "newStartupConfigWithModularPath",
-                classLoaderConfiguration, providerClasspath, "org.asf.Provider", moduleInfo, scanResult );
+                classLoaderConfiguration, providerClasspath, "org.asf.Provider", moduleInfo, scanResult,
+                "" );
 
         verify( mojo, times( 1 ) ).effectiveIsEnableAssertions();
         verify( mojo, times( 1 ) ).isChildDelegation();
@@ -166,6 +170,13 @@ public class AbstractSurefireMojoJava7PlusTest
         verify( res, times( 1 ) ).getClasspathElements();
         verify( res, times( 1 ) ).getModulepathElements();
         verify( locationManager, times( 1 ) ).resolvePaths( eq( req ) );
+        ArgumentCaptor<String> argument1 = ArgumentCaptor.forClass( String.class );
+        ArgumentCaptor<Exception> argument2 = ArgumentCaptor.forClass( Exception.class );
+        verify( logger, times( 1 ) ).warn( argument1.capture(), argument2.capture() );
+        assertThat( argument1.getValue() )
+                .isEqualTo( "Exception for 'java 1.8' (probably JDK version < 9)." );
+        assertThat( argument2.getValue().getMessage() )
+                .isEqualTo( "low version" );
         ArgumentCaptor<String> argument = ArgumentCaptor.forClass( String.class );
         verify( logger, times( 6 ) ).debug( argument.capture() );
         assertThat( argument.getAllValues() )
diff --git a/pom.xml b/pom.xml
index 09bce00..7aed0f9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -239,7 +239,7 @@
       <dependency>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-java</artifactId>
-        <version>0.9.11</version>
+        <version>1.0.1</version>
       </dependency>
       <dependency>
         <groupId>org.junit.platform</groupId>