Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7B89D200CF1 for ; Mon, 14 Aug 2017 03:24:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 79BEF163D0B; Mon, 14 Aug 2017 01:24:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C93F0163D09 for ; Mon, 14 Aug 2017 03:24:12 +0200 (CEST) Received: (qmail 56979 invoked by uid 500); 14 Aug 2017 01:24:11 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 56970 invoked by uid 99); 14 Aug 2017 01:24:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Aug 2017 01:24:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1C4F2E382D; Mon, 14 Aug 2017 01:24:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tibordigana@apache.org To: commits@maven.apache.org Date: Mon, 14 Aug 2017 01:24:10 -0000 Message-Id: <4371506b51be49e89507a35b8a965e06@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] maven-surefire git commit: [SUREFIRE-1403] [Jigsaw] [Java 9] add "--add-modules ALL-SYSTEM" to forked CLI argument [Forced Update!] archived-at: Mon, 14 Aug 2017 01:24:14 -0000 Repository: maven-surefire Updated Branches: refs/heads/SUREFIRE-1403 9c5238608 -> 622185be8 (forced update) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemUtils.java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemUtils.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemUtils.java index ccdb6e6..3a53ddf 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemUtils.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemUtils.java @@ -22,19 +22,29 @@ package org.apache.maven.surefire.booter; import org.apache.maven.surefire.util.ReflectionUtils; import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; import java.lang.management.ManagementFactory; import java.lang.reflect.Method; +import java.util.Properties; +import java.util.StringTokenizer; import static java.lang.Thread.currentThread; +import static org.apache.commons.io.IOUtils.closeQuietly; import static org.apache.commons.lang3.JavaVersion.JAVA_9; import static org.apache.commons.lang3.JavaVersion.JAVA_RECENT; +import static org.apache.commons.lang3.StringUtils.isNumeric; import static org.apache.commons.lang3.SystemUtils.IS_OS_FREE_BSD; import static org.apache.commons.lang3.SystemUtils.IS_OS_LINUX; import static org.apache.commons.lang3.SystemUtils.IS_OS_NET_BSD; import static org.apache.commons.lang3.SystemUtils.IS_OS_OPEN_BSD; +import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast; import static org.apache.maven.surefire.util.ReflectionUtils.invokeMethodChain; import static org.apache.maven.surefire.util.ReflectionUtils.tryLoadClass; +import static org.apache.maven.surefire.util.internal.ObjectUtils.requireNonNull; /** * JDK 9 support. @@ -44,13 +54,144 @@ import static org.apache.maven.surefire.util.ReflectionUtils.tryLoadClass; */ public final class SystemUtils { + private static final double JIGSAW_JAVA_VERSION = 9.0d; + private static final int PROC_STATUS_PID_FIRST_CHARS = 20; - public SystemUtils() + private SystemUtils() { throw new IllegalStateException( "no instantiable constructor" ); } + /** + * @param jvmExecPath e.g. /jdk/bin/java, /jdk/jre/bin/java + * @return {@code true} if {@code jvmExecPath} is path to java binary executor + */ + public static boolean endsWithJavaPath( String jvmExecPath ) + { + File javaExec = new File( jvmExecPath ).getAbsoluteFile(); + File bin = javaExec.getParentFile(); + String exec = javaExec.getName(); + return exec.startsWith( "java" ) && bin != null && bin.getName().equals( "bin" ); + } + + /** + * If {@code jvmExecutable} is /jdk/bin/java (since jdk9) or /jdk/jre/bin/java (prior to jdk9) + * then the absolute path to JDK home is returned /jdk. + *
+ * Null is returned if {@code jvmExecutable} is incorrect. + * + * @param jvmExecutable /jdk/bin/java* or /jdk/jre/bin/java* + * @return path to jdk directory; or null if wrong path or directory layout of JDK installation. + */ + public static File toJdkHomeFromJvmExec( String jvmExecutable ) + { + File bin = new File( jvmExecutable ).getAbsoluteFile().getParentFile(); + if ( "bin".equals( bin.getName() ) ) + { + File parent = bin.getParentFile(); + if ( "jre".equals( parent.getName() ) ) + { + File jdk = parent.getParentFile(); + return new File( jdk, "bin" ).isDirectory() ? jdk : null; + } + return parent; + } + return null; + } + + /** + * If system property java.home is /jdk (since jdk9) or /jdk/jre (prior to jdk9) then + * the absolute path to + * JDK home is returned /jdk. + * + * @return path to JDK + */ + public static File toJdkHomeFromJre() + { + return toJdkHomeFromJre( System.getProperty( "java.home" ) ); + } + + /** + * If {@code jreHome} is /jdk (since jdk9) or /jdk/jre (prior to jdk9) then + * the absolute path to JDK home is returned /jdk. + *
+ * JRE home directory {@code jreHome} must be taken from system property java.home. + * + * @param jreHome path to /jdk or /jdk/jre + * @return path to JDK + */ + static File toJdkHomeFromJre( String jreHome ) + { + File pathToJreOrJdk = new File( jreHome ).getAbsoluteFile(); + return "jre".equals( pathToJreOrJdk.getName() ) ? pathToJreOrJdk.getParentFile() : pathToJreOrJdk; + } + + public static Double toJdkVersionFromReleaseFile( File jdkHome ) + { + File release = new File( requireNonNull( jdkHome ).getAbsoluteFile(), "release" ); + if ( !release.isFile() ) + { + return null; + } + InputStream is = null; + try + { + Properties properties = new Properties(); + is = new FileInputStream( release ); + properties.load( is ); + String javaVersion = properties.getProperty( "JAVA_VERSION" ).replace( "\"", "" ); + StringTokenizer versions = new StringTokenizer( javaVersion, "._" ); + + if ( versions.countTokens() == 1 ) + { + javaVersion = versions.nextToken(); + } + else if ( versions.countTokens() >= 2 ) + { + String majorVersion = versions.nextToken(); + String minorVersion = versions.nextToken(); + javaVersion = isNumeric( minorVersion ) ? majorVersion + "." + minorVersion : majorVersion; + } + else + { + return null; + } + + return Double.valueOf( javaVersion ); + } + catch ( IOException e ) + { + return null; + } + finally + { + closeQuietly( is ); + } + } + + public static boolean isJava9AtLeast( String jvmExecutablePath ) + { + File externalJavaHome = toJdkHomeFromJvmExec( jvmExecutablePath ); + File thisJavaHome = toJdkHomeFromJre(); + if ( thisJavaHome.equals( externalJavaHome ) ) + { + return isBuiltInJava9AtLeast(); + } + Double releaseFileVersion = externalJavaHome == null ? null : toJdkVersionFromReleaseFile( externalJavaHome ); + return SystemUtils.isJava9AtLeast( releaseFileVersion ); + } + + static boolean isBuiltInJava9AtLeast() + { + return isJavaVersionAtLeast( JAVA_9 ); + } + + public static boolean isJava9AtLeast( Double version ) + { + return version != null && version >= JIGSAW_JAVA_VERSION; + } + public static ClassLoader platformClassLoader() { if ( JAVA_RECENT.atLeast( JAVA_9 ) ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java index 12aff99..1917cbb 100644 --- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java +++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java @@ -19,10 +19,19 @@ package org.apache.maven.surefire.booter; * under the License. */ +import org.junit.Ignore; import org.junit.Test; +import org.junit.experimental.runners.Enclosed; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import java.io.File; +import java.io.IOException; import java.lang.management.ManagementFactory; +import static java.io.File.separator; import static org.apache.commons.lang3.JavaVersion.JAVA_9; import static org.apache.commons.lang3.JavaVersion.JAVA_RECENT; import static org.apache.commons.lang3.SystemUtils.IS_OS_FREE_BSD; @@ -30,7 +39,14 @@ import static org.apache.commons.lang3.SystemUtils.IS_OS_LINUX; import static org.apache.commons.lang3.SystemUtils.IS_OS_NET_BSD; import static org.apache.commons.lang3.SystemUtils.IS_OS_OPEN_BSD; import static org.fest.assertions.Assertions.assertThat; +import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyDouble; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.verifyStatic; /** * Test of {@link SystemUtils}. @@ -38,94 +54,280 @@ import static org.junit.Assume.assumeTrue; * @author Tibor Digana (tibor17) * @since 2.20.1 */ +@RunWith( Enclosed.class ) public class SystemUtilsTest { - @Test - public void shouldBePlatformClassLoader() + public static class PlainUnitTests { - ClassLoader cl = SystemUtils.platformClassLoader(); - if ( JAVA_RECENT.atLeast( JAVA_9 ) ) + + @Test + public void shouldParseProprietaryReleaseFile() throws IOException + { + String classes = new File( "." ).getCanonicalPath() + separator + "target" + separator + "test-classes"; + + File path = new File( classes, "jdk8-IBM" + separator + "bin" + separator + "java" ); + assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isFalse(); + + path = new File( classes, "jdk8-oracle" + separator + "bin" + separator + "java" ); + assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isFalse(); + + path = new File( classes, "jdk9-oracle" + separator + "bin" + separator + "java" ); + assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isTrue(); + } + + @Test + public void incorrectJdkPath() throws IOException + { + File jre = new File( System.getProperty( "java.home" ) ); + File jdk = jre.getParentFile(); + File incorrect = jdk.getParentFile(); + assertThat( SystemUtils.isJava9AtLeast( incorrect.getAbsolutePath() ) ).isFalse(); + } + + @Test + public void shouldHaveJavaPath() + { + String javaPath = System.getProperty( "java.home" ) + separator + "bin" + separator + "java"; + assertThat( SystemUtils.endsWithJavaPath( javaPath ) ).isTrue(); + } + + @Test + public void shouldNotHaveJavaPath() + { + assertThat( SystemUtils.endsWithJavaPath( "/jdk" ) ).isFalse(); + } + + @Test + public void shouldNotExtractJdkHomeFromJavaExec() + { + File pathToJdk = SystemUtils.toJdkHomeFromJvmExec( "/jdk/binx/java" ); + assertThat( pathToJdk ).isNull(); + } + + @Test + public void shouldExtractJdkHomeFromJavaExec() + { + File pathToJdk = SystemUtils.toJdkHomeFromJvmExec( "/jdk/bin/java" ); + assertThat( pathToJdk ).isEqualTo( new File( "/jdk" ).getAbsoluteFile() ); + } + + @Test + public void shouldNotExtractJdkHomeFromJreExec() throws IOException + { + String classes = new File( "." ).getCanonicalPath() + separator + "target" + separator + "test-classes"; + File jdk = new File( classes, "jdk" ); + String pathToJreExec = jdk.getAbsolutePath() + separator + "jre" + separator + "binx" + separator + "java"; + File pathToJdk = SystemUtils.toJdkHomeFromJvmExec( pathToJreExec ); + assertThat( pathToJdk ).isNull(); + } + + @Test + public void shouldExtractJdkHomeFromJreExec() throws IOException + { + String classes = new File( "." ).getCanonicalPath() + separator + "target" + separator + "test-classes"; + File jdk = new File( classes, "jdk" ); + String pathToJreExec = jdk.getAbsolutePath() + separator + "jre" + separator + "bin" + separator + "java"; + File pathToJdk = SystemUtils.toJdkHomeFromJvmExec( pathToJreExec ); + assertThat( pathToJdk ).isEqualTo( jdk ); + } + + @Test + public void shouldExtractJdkHomeFromJre() + { + File pathToJdk = SystemUtils.toJdkHomeFromJre( "/jdk/jre" ); + assertThat( pathToJdk ).isEqualTo( new File( "/jdk" ).getAbsoluteFile() ); + } + + @Test + public void shouldExtractJdkHomeFromJdk() { - assertThat( cl ).isNotNull(); + File pathToJdk = SystemUtils.toJdkHomeFromJre( "/jdk/" ); + assertThat( pathToJdk ).isEqualTo( new File( "/jdk" ).getAbsoluteFile() ); } - else + + @Test + public void shouldExtractJdkHomeFromRealPath() { + File pathToJdk = SystemUtils.toJdkHomeFromJre(); + + if ( JAVA_RECENT.atLeast( JAVA_9 ) ) + { + File realJdkHome = new File( System.getProperty( "java.home" ) ).getAbsoluteFile(); + assertThat( realJdkHome ).isDirectory(); + assertThat( realJdkHome.getName() ).isNotEqualTo( "jre" ); + assertThat( pathToJdk ).isEqualTo( realJdkHome ); + } + else + { + File realJreHome = new File( System.getProperty( "java.home" ) ).getAbsoluteFile(); + assertThat( realJreHome ).isDirectory(); + assertThat( realJreHome.getName() ).isEqualTo( "jre" ); + File realJdkHome = realJreHome.getParentFile(); + assertThat( pathToJdk ).isEqualTo( realJdkHome ); + } + } + + @Test + public void shouldBeJavaVersion() + { + assertThat( SystemUtils.isJava9AtLeast( (Double) null ) ).isFalse(); + assertThat( SystemUtils.isJava9AtLeast( 1.8d ) ).isFalse(); + assertThat( SystemUtils.isJava9AtLeast( 9.0d ) ).isTrue(); + } + + @Test + public void shouldBePlatformClassLoader() + { + ClassLoader cl = SystemUtils.platformClassLoader(); + if ( JAVA_RECENT.atLeast( JAVA_9 ) ) + { + assertThat( cl ).isNotNull(); + } + else + { + assertThat( cl ).isNull(); + } + } + + @Test + public void shouldNotFindClassLoader() + { + ClassLoader cl = SystemUtils.reflectClassLoader( getClass(), "_getPlatformClassLoader_" ); assertThat( cl ).isNull(); } - } - @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() ); + } - @Test - public void shouldFindClassLoader() - { - ClassLoader cl = SystemUtils.reflectClassLoader( getClass(), "getPlatformClassLoader" ); - assertThat( cl ).isSameAs( ClassLoader.getSystemClassLoader() ); - } + @Test + public void shouldBePidOnJigsaw() + { + assumeTrue( JAVA_RECENT.atLeast( JAVA_9 ) ); - @Test - public void shouldBePidOnJigsaw() - { - assumeTrue( JAVA_RECENT.atLeast( JAVA_9 ) ); + Long actualPid = SystemUtils.pidOnJava9(); + String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim(); - Long actualPid = SystemUtils.pidOnJava9(); - String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim(); + assertThat( actualPid + "" ) + .isEqualTo( expectedPid ); + } - assertThat( actualPid + "" ) - .isEqualTo( expectedPid ); - } + @Test + public void shouldBePidStatusOnLinux() throws Exception + { + assumeTrue( IS_OS_LINUX ); - @Test - public void shouldBePidStatusOnLinux() throws Exception - { - assumeTrue( IS_OS_LINUX ); + Long actualPid = SystemUtils.pidStatusOnLinux(); + String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim(); - Long actualPid = SystemUtils.pidStatusOnLinux(); - String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim(); + assertThat( actualPid + "" ) + .isEqualTo( expectedPid ); + } - assertThat( actualPid + "" ) - .isEqualTo( expectedPid ); - } + @Test + public void shouldBePidStatusOnBSD() throws Exception + { + assumeTrue( IS_OS_FREE_BSD || IS_OS_NET_BSD || IS_OS_OPEN_BSD ); - @Test - public void shouldBePidStatusOnBSD() throws Exception - { - assumeTrue( IS_OS_FREE_BSD || IS_OS_NET_BSD || IS_OS_OPEN_BSD ); + Long actualPid = SystemUtils.pidStatusOnBSD(); + String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim(); - Long actualPid = SystemUtils.pidStatusOnBSD(); - String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim(); + assertThat( actualPid + "" ) + .isEqualTo( expectedPid ); + } - assertThat( actualPid + "" ) - .isEqualTo( expectedPid ); - } + @Test + public void shouldBePidOnJMX() + { + Long actualPid = SystemUtils.pidOnJMX(); + String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim(); - @Test - public void shouldBePidOnJMX() - { - Long actualPid = SystemUtils.pidOnJMX(); - String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim(); + assertThat( actualPid + "" ) + .isEqualTo( expectedPid ); + } - assertThat( actualPid + "" ) - .isEqualTo( expectedPid ); - } + @Test + public void shouldBePid() + { + Long actualPid = SystemUtils.pid(); + String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim(); - @Test - public void shouldBePid() - { - Long actualPid = SystemUtils.pid(); - String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim(); + assertThat( actualPid + "" ) + .isEqualTo( expectedPid ); + } + + public static ClassLoader getPlatformClassLoader() + { + return ClassLoader.getSystemClassLoader(); + } - assertThat( actualPid + "" ) - .isEqualTo( expectedPid ); } - public static ClassLoader getPlatformClassLoader() + @RunWith( PowerMockRunner.class ) + @PrepareForTest( SystemUtils.class ) + // todo check PowerMock is compliant with Java 9 + @Ignore( value = "use this test after issue is fixed https://github.com/powermock/powermock/issues/783") + public static class MockTest { - return ClassLoader.getSystemClassLoader(); + + @Test + public void shouldBeDifferentJdk9() throws IOException + { + testIsJava9AtLeast( new File( System.getProperty( "java.home" ) ) ); + } + + @Test + public void shouldBeSameJdk9() throws IOException + { + assumeFalse( JAVA_RECENT.atLeast( JAVA_9 ) ); + testIsJava9AtLeast( new File( System.getProperty( "java.home" ) ).getParentFile() ); + } + + private static void testIsJava9AtLeast( File pathInJdk ) throws IOException + { + File path = new File( pathInJdk, "bin" + separator + "java" ); + + mockStatic( SystemUtils.class ); + + when( SystemUtils.isJava9AtLeast( anyString() ) ) + .thenCallRealMethod(); + + when( SystemUtils.toJdkHomeFromJvmExec( anyString() ) ) + .thenCallRealMethod(); + + when( SystemUtils.toJdkHomeFromJre() ) + .thenCallRealMethod(); + + when( SystemUtils.toJdkHomeFromJre( anyString() ) ) + .thenCallRealMethod(); + + when( SystemUtils.isBuiltInJava9AtLeast() ) + .thenCallRealMethod(); + + when( SystemUtils.toJdkVersionFromReleaseFile( any( File.class ) ) ) + .thenCallRealMethod(); + + when( SystemUtils.isJava9AtLeast( anyDouble() ) ) + .thenCallRealMethod(); + + if ( JAVA_RECENT.atLeast( JAVA_9 ) ) + { + assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isTrue(); + } + else + { + assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isFalse(); + } + + verifyStatic( Mockito.times( 0 ) ); + SystemUtils.toJdkVersionFromReleaseFile( any( File.class ) ); + + verifyStatic( Mockito.times( 1 ) ); + SystemUtils.isBuiltInJava9AtLeast(); + } + } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-booter/src/test/resources/jdk/bin/java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/test/resources/jdk/bin/java b/surefire-booter/src/test/resources/jdk/bin/java new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-booter/src/test/resources/jdk/jre/bin/java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/test/resources/jdk/jre/bin/java b/surefire-booter/src/test/resources/jdk/jre/bin/java new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-booter/src/test/resources/jdk8-IBM/release ---------------------------------------------------------------------- diff --git a/surefire-booter/src/test/resources/jdk8-IBM/release b/surefire-booter/src/test/resources/jdk8-IBM/release new file mode 100644 index 0000000..f8baa30 --- /dev/null +++ b/surefire-booter/src/test/resources/jdk8-IBM/release @@ -0,0 +1 @@ +JAVA_VERSION="1.8.0" http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-booter/src/test/resources/jdk8-oracle/release ---------------------------------------------------------------------- diff --git a/surefire-booter/src/test/resources/jdk8-oracle/release b/surefire-booter/src/test/resources/jdk8-oracle/release new file mode 100644 index 0000000..567277b --- /dev/null +++ b/surefire-booter/src/test/resources/jdk8-oracle/release @@ -0,0 +1 @@ +JAVA_VERSION="1.8.0_141" http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-booter/src/test/resources/jdk9-oracle/release ---------------------------------------------------------------------- diff --git a/surefire-booter/src/test/resources/jdk9-oracle/release b/surefire-booter/src/test/resources/jdk9-oracle/release new file mode 100644 index 0000000..afcc747 --- /dev/null +++ b/surefire-booter/src/test/resources/jdk9-oracle/release @@ -0,0 +1 @@ +JAVA_VERSION="9" http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-integration-tests/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/pom.xml b/surefire-integration-tests/pom.xml index d9142de..4ea01b4 100644 --- a/surefire-integration-tests/pom.xml +++ b/surefire-integration-tests/pom.xml @@ -55,7 +55,6 @@ org.apache.maven maven-settings - 2.0.6 test @@ -109,12 +108,15 @@ ${maven.home} ${project.basedir}/../surefire-setup-integration-tests/target/private/it-settings.xml + ${project.basedir}/../surefire-setup-integration-tests/target/private/toolchains.xml + ${project.basedir}/../surefire-setup-integration-tests/target/it-repo ${project.build.directory} ${settings.localRepository} ${useInterpolatedSettings} ${project.build.testOutputDirectory} ${verifier.forkMode} + ${jdk.home} false http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractJigsawIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractJigsawIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractJigsawIT.java new file mode 100644 index 0000000..c2d0173 --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/AbstractJigsawIT.java @@ -0,0 +1,113 @@ +package org.apache.maven.surefire.its; + +/* + * 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 java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import java.util.StringTokenizer; + +import static org.apache.commons.lang3.JavaVersion.JAVA_9; +import static org.apache.commons.lang3.JavaVersion.JAVA_RECENT; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +/** + * Abstract test class for Jigsaw tests. + * + * @author Tibor Digana (tibor17) + * @since 2.20.1 + */ +public abstract class AbstractJigsawIT + extends SurefireJUnit4IntegrationTestCase +{ + protected static final String JDK_HOME_KEY = "jdk.home"; + protected static final String JDK_HOME = System.getProperty( JDK_HOME_KEY ); + private static final double JIGSAW_JAVA_VERSION = 9.0d; + + protected abstract String getProjectDirectoryName(); + + protected SurefireLauncher assumeJigsaw() throws IOException + { + assumeTrue( "There's no JDK 9 provided.", + JAVA_RECENT.atLeast( JAVA_9 ) || JDK_HOME != null && isExtJava9AtLeast() ); + // fail( JDK_HOME_KEY + " was provided with value " + JDK_HOME + " but it is not Jigsaw Java 9." ); + + SurefireLauncher launcher = unpack(); + + if ( JDK_HOME != null ) + { + launcher.setLauncherJavaHome( JDK_HOME ); + } + + return launcher; + } + + protected SurefireLauncher assumeJava9Property() throws IOException + { + assumeTrue( "There's no JDK 9 provided.", JDK_HOME != null && isExtJava9AtLeast() ); + return unpack(); + } + + private SurefireLauncher unpack() + { + return unpack( getProjectDirectoryName() ); + } + + private static boolean isExtJava9AtLeast() throws IOException + { + File release = new File( JDK_HOME, "release" ); + + if ( !release.isFile() ) + { + fail( JDK_HOME_KEY + " was provided with value " + JDK_HOME + " but file does not exist " + + JDK_HOME + File.separator + "release" + ); + } + + Properties properties = new Properties(); + try ( InputStream is = new FileInputStream( release ) ) + { + properties.load( is ); + } + String javaVersion = properties.getProperty( "JAVA_VERSION" ).replace( "\"", "" ); + StringTokenizer versions = new StringTokenizer( javaVersion, "._" ); + + if ( versions.countTokens() == 1 ) + { + javaVersion = versions.nextToken(); + } + else if ( versions.countTokens() >= 2 ) + { + javaVersion = versions.nextToken() + "." + versions.nextToken(); + } + else + { + fail( "unexpected java version format" ); + } + + return Double.valueOf( javaVersion ) >= JIGSAW_JAVA_VERSION; + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Java9FullApiIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Java9FullApiIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Java9FullApiIT.java new file mode 100644 index 0000000..b1bea12 --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Java9FullApiIT.java @@ -0,0 +1,95 @@ +package org.apache.maven.surefire.its; + +/* + * 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.OutputValidator; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; + +/** + * Running Surefire on the top of JDK 9 and should be able to load + * classes of multiple different Jigsaw modules without error. + * + * @author Tibor Digana (tibor17) + * @since 2.20.1 + */ +public class Java9FullApiIT + extends AbstractJigsawIT +{ + + @Test + public void shouldLoadMultipleJavaModules_JavaHome() throws IOException + { + OutputValidator validator = assumeJigsaw() + .setForkJvm() + .debugLogging() + .execute( "verify" ) + .verifyErrorFree( 2 ); + + validator.verifyTextInLog( "loaded class java.sql.SQLException" ) + .verifyTextInLog( "loaded class javax.xml.ws.Holder" ) + .verifyTextInLog( "loaded class javax.xml.bind.JAXBException" ) + .verifyTextInLog( "loaded class org.omg.CORBA.BAD_INV_ORDER" ) + .verifyTextInLog( "java.specification.version=9" ); + } + + @Test + public void shouldLoadMultipleJavaModules_JvmParameter() throws IOException + { + OutputValidator validator = assumeJava9Property() + .setForkJvm() + .debugLogging() + .sysProp( JDK_HOME_KEY, new File( JDK_HOME ).getCanonicalPath() ) + .execute( "verify" ) + .verifyErrorFree( 2 ); + + validator.verifyTextInLog( "loaded class java.sql.SQLException" ) + .verifyTextInLog( "loaded class javax.xml.ws.Holder" ) + .verifyTextInLog( "loaded class javax.xml.bind.JAXBException" ) + .verifyTextInLog( "loaded class org.omg.CORBA.BAD_INV_ORDER" ) + .verifyTextInLog( "java.specification.version=9" ); + } + + @Test + public void shouldLoadMultipleJavaModules_ToolchainsXML() throws IOException + { + OutputValidator validator = assumeJava9Property() + .setForkJvm() + .activateProfile( "use-toolchains" ) + .addGoal( "--toolchains" ) + .addGoal( System.getProperty( "maven.toolchains.file" ) ) + .execute( "verify" ) + .verifyErrorFree( 2 ); + + validator.verifyTextInLog( "loaded class java.sql.SQLException" ) + .verifyTextInLog( "loaded class javax.xml.ws.Holder" ) + .verifyTextInLog( "loaded class javax.xml.bind.JAXBException" ) + .verifyTextInLog( "loaded class org.omg.CORBA.BAD_INV_ORDER" ) + .verifyTextInLog( "java.specification.version=9" ); + } + + @Override + protected String getProjectDirectoryName() + { + return "java9-full-api"; + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/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 index 9e06e8e..2e92805 100644 --- 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 @@ -19,11 +19,10 @@ package org.apache.maven.surefire.its.jiras; * under the License. */ -import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; -import org.apache.maven.surefire.its.fixture.SurefireLauncher; +import org.apache.maven.surefire.its.AbstractJigsawIT; import org.junit.Test; -import static org.junit.Assume.assumeTrue; +import java.io.IOException; @SuppressWarnings( { "javadoc", "checkstyle:javadoctype" } ) /** @@ -40,19 +39,19 @@ import static org.junit.Assume.assumeTrue; * @since 2.20.1 */ public class Surefire1265Java9IT - extends SurefireJUnit4IntegrationTestCase + extends AbstractJigsawIT { @Test - public void shouldRunInPluginJava9() + public void shouldRunInPluginJava9() throws IOException { - assumeTrue( System.getProperty( "java.specification.version" ).compareTo( "1.8" ) > 0 ); - unpack() + assumeJigsaw() .executeTest() .verifyErrorFree( 2 ); } - private SurefireLauncher unpack() + @Override + protected String getProjectDirectoryName() { - return unpack( "/surefire-1265" ); + return "/surefire-1265"; } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-integration-tests/src/test/resources/java9-full-api/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/java9-full-api/pom.xml b/surefire-integration-tests/src/test/resources/java9-full-api/pom.xml new file mode 100644 index 0000000..7d9026e --- /dev/null +++ b/surefire-integration-tests/src/test/resources/java9-full-api/pom.xml @@ -0,0 +1,122 @@ + + + + + 4.0.0 + + + org.apache.maven.surefire + it-parent + 1.0 + ../pom.xml + + + java9-full-api + + + 1.6 + 1.6 + + + + + + maven-surefire-plugin + + once + + + + maven-failsafe-plugin + + + + integration-test + verify + + + + + once + + + + + + + + junit + junit + 4.12 + test + + + + + + use-jvm-config-paramater + + + jdk.home + + + + + + maven-surefire-plugin + + ${jdk.home}/bin/java + + + + + + + use-toolchains + + + + org.apache.maven.plugins + maven-toolchains-plugin + 1.1 + + + validate + + toolchain + + + + + + + 9 + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-integration-tests/src/test/resources/java9-full-api/src/test/java/J9IT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/java9-full-api/src/test/java/J9IT.java b/surefire-integration-tests/src/test/resources/java9-full-api/src/test/java/J9IT.java new file mode 100644 index 0000000..9daf55d --- /dev/null +++ b/surefire-integration-tests/src/test/resources/java9-full-api/src/test/java/J9IT.java @@ -0,0 +1,39 @@ +/* + * 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; + +public class J9IT +{ + @Test + public void testMiscellaneousAPI() throws java.sql.SQLException + { + System.out.println( "loaded class " + java.sql.SQLException.class.getName() ); + System.out.println( "loaded class " + javax.xml.ws.Holder.class.getName() ); + System.out.println( "loaded class " + javax.xml.bind.JAXBException.class.getName() ); + System.out.println( "loaded class " + org.omg.CORBA.BAD_INV_ORDER.class.getName() ); + System.out.println( "loaded class " + javax.xml.xpath.XPath.class.getName() ); + System.out.println( "java.specification.version=" + System.getProperty( "java.specification.version" ) ); + } + + @Test + public void test_corba_mod() throws org.omg.CORBA.BAD_INV_ORDER + { + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-integration-tests/src/test/resources/java9-full-api/src/test/java/J9Test.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/java9-full-api/src/test/java/J9Test.java b/surefire-integration-tests/src/test/resources/java9-full-api/src/test/java/J9Test.java new file mode 100644 index 0000000..6745d5f --- /dev/null +++ b/surefire-integration-tests/src/test/resources/java9-full-api/src/test/java/J9Test.java @@ -0,0 +1,39 @@ +/* + * 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; + +public class J9Test +{ + @Test + public void testMiscellaneousAPI() throws java.sql.SQLException + { + System.out.println( "loaded class " + java.sql.SQLException.class.getName() ); + System.out.println( "loaded class " + javax.xml.ws.Holder.class.getName() ); + System.out.println( "loaded class " + javax.xml.bind.JAXBException.class.getName() ); + System.out.println( "loaded class " + org.omg.CORBA.BAD_INV_ORDER.class.getName() ); + System.out.println( "loaded class " + javax.xml.xpath.XPath.class.getName() ); + System.out.println( "java.specification.version=" + System.getProperty( "java.specification.version" ) ); + } + + @Test + public void test_corba_mod() throws org.omg.CORBA.BAD_INV_ORDER + { + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-setup-integration-tests/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-setup-integration-tests/pom.xml b/surefire-setup-integration-tests/pom.xml index fde80ae..ff2ddbf 100644 --- a/surefire-setup-integration-tests/pom.xml +++ b/surefire-setup-integration-tests/pom.xml @@ -89,7 +89,7 @@ org.apache.maven maven-settings - 2.0.6 + ${mavenVersion} test @@ -106,6 +106,23 @@ + + + src/main/resources + ${project.build.outputDirectory} + + toolchains.xml + + + + src/main/resources + true + ${project.build.directory}/private + + toolchains.xml + + + maven-help-plugin @@ -127,11 +144,9 @@ maven-invoker-plugin - - org.apache.maven.surefire:surefire-testng-utils:${project.version} - ${project.build.directory}/it-repo + org.apache.maven.surefire:surefire-testng-utils:${project.version} org.testng:testng:4.7:jar:jdk15 org.testng:testng:5.0.2:jar:jdk15 org.testng:testng:5.1:jar:jdk15 @@ -173,6 +188,7 @@ junit:junit:4.8.1 junit:junit:4.8.2 junit:junit:4.11 + junit:junit:4.12 junit:junit-dep:4.8 junit:junit-dep:4.7 junit:junit-dep:4.4 @@ -184,7 +200,11 @@ org.codehaus.plexus:plexus-utils:1.5.8 org.codehaus.plexus:plexus-utils:1.5.15 org.mockito:mockito-core:1.8.5 + org.powermock:powermock-mockito-release-full:1.6.4:jar:full org.codehaus.plexus:plexus-interpolation:1.12 + org.hamcrest:hamcrest-core:1.3 + org.hamcrest:hamcrest-library:1.3 + org.easytesting:fest-assert:1.4 http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/622185be/surefire-setup-integration-tests/src/main/resources/toolchains.xml ---------------------------------------------------------------------- diff --git a/surefire-setup-integration-tests/src/main/resources/toolchains.xml b/surefire-setup-integration-tests/src/main/resources/toolchains.xml new file mode 100644 index 0000000..f9f1d66 --- /dev/null +++ b/surefire-setup-integration-tests/src/main/resources/toolchains.xml @@ -0,0 +1,35 @@ + + + + + + jdk + + jdk9 + 9 + oracle + + + ${jdk.home} + + +