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 2017/04/20 21:05:47 UTC

maven-surefire git commit: [SUREFIRE-1265] reuseForks=false fails on jdk-9-ea builds [Forced Update!]

Repository: maven-surefire
Updated Branches:
  refs/heads/SUREFIRE-1265 c31dc99b7 -> cba4adb1b (forced update)


[SUREFIRE-1265] reuseForks=false fails on jdk-9-ea builds


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/cba4adb1
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/cba4adb1
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/cba4adb1

Branch: refs/heads/SUREFIRE-1265
Commit: cba4adb1b93002c5b4bb2d2f22f461cc53bd8738
Parents: 9c0025e
Author: Tibor17 <ti...@lycos.com>
Authored: Thu Apr 20 21:07:55 2017 +0200
Committer: Tibor17 <ti...@lycos.com>
Committed: Thu Apr 20 23:05:38 2017 +0200

----------------------------------------------------------------------
 .../surefire/util/internal/SystemUtils.java     | 99 ++++++++++++++++++++
 .../java/org/apache/maven/JUnit4SuiteTest.java  |  4 +-
 .../surefire/util/internal/SystemUtilsTest.java | 98 +++++++++++++++++++
 .../apache/maven/surefire/booter/Classpath.java |  6 +-
 .../surefire/booter/ClasspathConfiguration.java |  2 +-
 .../surefire/its/jiras/Surefire1265Java9IT.java | 57 +++++++++++
 .../src/test/resources/surefire-1265/pom.xml    | 49 ++++++++++
 .../surefire-1265/src/test/java/J9Test.java     | 15 +++
 8 files changed, 326 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cba4adb1/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/SystemUtils.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/SystemUtils.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/SystemUtils.java
new file mode 100644
index 0000000..7881b5d
--- /dev/null
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/SystemUtils.java
@@ -0,0 +1,99 @@
+package org.apache.maven.surefire.util.internal;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.util.ReflectionUtils;
+
+import java.lang.reflect.Method;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static java.lang.Integer.parseInt;
+import static java.lang.Math.pow;
+
+/**
+ * JDK 9 support.
+ *
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @since 2.20.1
+ */
+public final class SystemUtils
+{
+    private static final Pattern JAVA_SPEC_VERSION_PATTERN = Pattern.compile( "(\\d+)(\\.?)(\\d*).*" );
+    private static final double JAVA_SPEC_VERSION = javaSpecVersion();
+
+    public SystemUtils()
+    {
+        throw new IllegalStateException( "no instantiable constructor" );
+    }
+
+    public static ClassLoader platformClassLoader()
+    {
+        if ( JAVA_SPEC_VERSION < 9 )
+        {
+            return null;
+        }
+
+        return reflectClassLoader( ClassLoader.class, "getPlatformClassLoader" );
+    }
+
+    public static double javaSpecVersion()
+    {
+        return extractJavaSpecVersion( System.getProperty( "java.specification.version" ) );
+    }
+
+    static ClassLoader reflectClassLoader( Class<?> target, String getterMethodName )
+    {
+        try
+        {
+            Method getter = ReflectionUtils.getMethod( target, getterMethodName );
+            return (ClassLoader) ReflectionUtils.invokeMethodWithArray( null, getter );
+        }
+        catch ( RuntimeException e )
+        {
+            return null;
+        }
+    }
+
+    static double extractJavaSpecVersion( String property )
+    {
+        Matcher versionRegexMatcher = JAVA_SPEC_VERSION_PATTERN.matcher( property );
+        int groups = versionRegexMatcher.groupCount();
+        if ( !versionRegexMatcher.matches() )
+        {
+            throw new IllegalStateException( "Java Spec Version does not match the pattern "
+                                                     + JAVA_SPEC_VERSION_PATTERN
+            );
+        }
+
+        if ( groups >= 3 )
+        {
+            String majorVersion = versionRegexMatcher.group( 1 );
+            String minorVersion = versionRegexMatcher.group( 3 );
+            int major = parseInt( majorVersion );
+            double minor = minorVersion.isEmpty() ? 0 : parseInt( minorVersion ) / pow( 10, minorVersion.length() );
+            return major + minor;
+        }
+        else
+        {
+            return parseInt( versionRegexMatcher.group( 0 ) );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cba4adb1/surefire-api/src/test/java/org/apache/maven/JUnit4SuiteTest.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/test/java/org/apache/maven/JUnit4SuiteTest.java b/surefire-api/src/test/java/org/apache/maven/JUnit4SuiteTest.java
index c43a3a6..22378bf 100644
--- a/surefire-api/src/test/java/org/apache/maven/JUnit4SuiteTest.java
+++ b/surefire-api/src/test/java/org/apache/maven/JUnit4SuiteTest.java
@@ -40,6 +40,7 @@ import org.apache.maven.surefire.util.UrlUtilsTest;
 import org.apache.maven.surefire.util.internal.ByteBufferTest;
 import org.apache.maven.surefire.util.internal.ConcurrencyUtilsTest;
 import org.apache.maven.surefire.util.internal.StringUtilsTest;
+import org.apache.maven.surefire.util.internal.SystemUtilsTest;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 
@@ -68,7 +69,8 @@ import org.junit.runners.Suite;
     TestsToRunTest.class,
     UrlUtilsTest.class,
     SpecificTestClassFilterTest.class,
-    FundamentalFilterTest.class
+    FundamentalFilterTest.class,
+    SystemUtilsTest.class
 } )
 @RunWith( Suite.class )
 public class JUnit4SuiteTest

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cba4adb1/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/SystemUtilsTest.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/SystemUtilsTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/SystemUtilsTest.java
new file mode 100644
index 0000000..bbd9b3c
--- /dev/null
+++ b/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/SystemUtilsTest.java
@@ -0,0 +1,98 @@
+package org.apache.maven.surefire.util.internal;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+/**
+ * Test of {@link SystemUtils}.
+ *
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @since 2.20.1
+ */
+public class SystemUtilsTest
+{
+    @Test
+    public void shouldBeJava9()
+    {
+        String simpleVersion = "9";
+        double version = SystemUtils.extractJavaSpecVersion( simpleVersion );
+        assertThat( version ).isEqualTo( 9d );
+    }
+
+    @Test
+    public void shouldBeJava8()
+    {
+        String simpleVersion = "1.8";
+        double version = SystemUtils.extractJavaSpecVersion( simpleVersion );
+        assertThat( version ).isEqualTo( 1.8d );
+    }
+
+    @Test
+    public void shouldBeJavaMajorAndMinor()
+    {
+        String simpleVersion = "12.345.6";
+        double version = SystemUtils.extractJavaSpecVersion( simpleVersion );
+        assertThat( version ).isEqualTo( 12.345d );
+    }
+
+    @Test
+    public void shouldBeCurrentJavaVersion()
+    {
+        Double parsedVersion = SystemUtils.javaSpecVersion();
+        String expectedVersion = System.getProperty( "java.specification.version" );
+        assertThat( parsedVersion.toString() ).isEqualTo( expectedVersion );
+    }
+
+    @Test
+    public void shouldBePlatformClassLoader()
+    {
+        ClassLoader cl = SystemUtils.platformClassLoader();
+        if ( SystemUtils.javaSpecVersion() < 9 )
+        {
+            assertThat( cl ).isNull();
+        }
+        else
+        {
+            assertThat( cl ).isNotNull();
+        }
+    }
+
+    @Test
+    public void shouldNotFindClassLoader()
+    {
+        ClassLoader cl = SystemUtils.reflectClassLoader( getClass(), "_getPlatformClassLoader_" );
+        assertThat( cl ).isNull();
+    }
+
+    @Test
+    public void shouldFindClassLoader()
+    {
+        ClassLoader cl = SystemUtils.reflectClassLoader( getClass(), "getPlatformClassLoader" );
+        assertThat( cl ).isSameAs( ClassLoader.getSystemClassLoader() );
+    }
+
+    public static ClassLoader getPlatformClassLoader()
+    {
+        return ClassLoader.getSystemClassLoader();
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cba4adb1/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
index 346e075..84ed9eb 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
@@ -19,6 +19,8 @@ package org.apache.maven.surefire.booter;
  * under the License.
  */
 
+import org.apache.maven.surefire.util.internal.SystemUtils;
+
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -156,12 +158,12 @@ public class Classpath implements Iterable<String>
         return unmodifiableElements.equals( classpath.unmodifiableElements );
     }
 
-    public ClassLoader createClassLoader( ClassLoader parent, boolean childDelegation, boolean enableAssertions,
-                                          String roleName )
+    public ClassLoader createClassLoader( boolean childDelegation, boolean enableAssertions, String roleName )
         throws SurefireExecutionException
     {
         try
         {
+            ClassLoader parent = SystemUtils.platformClassLoader();
             IsolatedClassLoader classLoader = new IsolatedClassLoader( parent, childDelegation, roleName );
             for ( String classPathElement : unmodifiableElements )
             {

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cba4adb1/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
index 3389a37..7425e3d 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
@@ -82,7 +82,7 @@ public class ClasspathConfiguration
         throws SurefireExecutionException
     {
         return Classpath.join( inprocClasspath, classpathUrls )
-            .createClassLoader( null, childDelegation, enableAssertions, "test" );
+            .createClassLoader( childDelegation, enableAssertions, "test" );
     }
 
     public Classpath getProviderClasspath()

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cba4adb1/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1265Java9IT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1265Java9IT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1265Java9IT.java
new file mode 100644
index 0000000..88c0daa
--- /dev/null
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1265Java9IT.java
@@ -0,0 +1,57 @@
+package org.apache.maven.surefire.its.jiras;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.apache.maven.surefire.its.fixture.SurefireLauncher;
+import org.junit.Test;
+
+import static org.junit.Assume.assumeTrue;
+
+/**
+ * IsolatedClassLoader should take platform ClassLoader as a parent ClassLoader if running on the top of JDK9.
+ * The IsolatedClassLoader should not fail like this:
+ *
+ * [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project
+ * maven-surefire-plugin-example: Execution default-test of goal
+ * org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed:
+ * java.lang.NoClassDefFoundError: java/sql/SQLException: java.sql.SQLException -> [Help 1]
+ *
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @see {@linkplain https://issues.apache.org/jira/browse/SUREFIRE-1265}
+ * @since 2.20.1
+ */
+public class Surefire1265Java9IT
+        extends SurefireJUnit4IntegrationTestCase
+{
+    @Test
+    public void shouldRunInPluginJava9()
+    {
+        assumeTrue( System.getProperty( "java.specification.version" ).compareTo( "1.8" ) > 0 );
+        unpack()
+                .executeTest()
+                .verifyErrorFree( 2 );
+    }
+
+    private SurefireLauncher unpack()
+    {
+        return unpack( "/surefire-1265" );
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cba4adb1/surefire-integration-tests/src/test/resources/surefire-1265/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-1265/pom.xml b/surefire-integration-tests/src/test/resources/surefire-1265/pom.xml
new file mode 100644
index 0000000..a702f30
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-1265/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.maven.surefire</groupId>
+        <artifactId>it-parent</artifactId>
+        <version>1.0</version>
+    </parent>
+
+    <groupId>org.apache.maven.plugins.surefire</groupId>
+    <artifactId>surefire-1265</artifactId>
+    <version>1.0</version>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.source>9</maven.compiler.source>
+        <maven.compiler.target>9</maven.compiler.target>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cba4adb1/surefire-integration-tests/src/test/resources/surefire-1265/src/test/java/J9Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-1265/src/test/java/J9Test.java b/surefire-integration-tests/src/test/resources/surefire-1265/src/test/java/J9Test.java
new file mode 100644
index 0000000..3d41aea
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-1265/src/test/java/J9Test.java
@@ -0,0 +1,15 @@
+import org.junit.Test;
+
+public class J9Test
+{
+    @Test
+    public void test_sql_mod() throws java.sql.SQLException
+    {
+        System.out.println( System.getProperty( "java.specification.version" ) );
+    }
+
+    @Test
+    public void test_corba_mod() /*throws org.omg.CORBA.BAD_INV_ORDER*/
+    {
+    }
+}