Repository: maven-surefire Updated Branches: refs/heads/SUREFIRE-1403 e490b265b -> 961e826f1 (forced update)
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/961e826f/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 <a href="mailto:tibordig...@apache.org">Tibor Digana (tibor17)</a> * @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/961e826f/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/961e826f/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/961e826f/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/961e826f/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/961e826f/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/961e826f/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 @@ <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-settings</artifactId> - <version>2.0.6</version> <scope>test</scope> </dependency> <dependency> @@ -109,12 +108,15 @@ <maven.home>${maven.home}</maven.home> <maven.settings.file>${project.basedir}/../surefire-setup-integration-tests/target/private/it-settings.xml </maven.settings.file> + <maven.toolchains.file>${project.basedir}/../surefire-setup-integration-tests/target/private/toolchains.xml + </maven.toolchains.file> <maven.repo.local>${project.basedir}/../surefire-setup-integration-tests/target/it-repo</maven.repo.local> <maven.test.tmpdir>${project.build.directory}</maven.test.tmpdir> <user.localRepository>${settings.localRepository}</user.localRepository> <useInterpolatedSettings>${useInterpolatedSettings}</useInterpolatedSettings> <testBuildDirectory>${project.build.testOutputDirectory}</testBuildDirectory> <verifier.forkMode>${verifier.forkMode}</verifier.forkMode> + <jdk.home>${jdk.home}</jdk.home> </systemPropertyVariables> <redirectTestOutputToFile>false</redirectTestOutputToFile> </configuration> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/961e826f/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 <a href="mailto:tibordig...@apache.org">Tibor Digana (tibor17)</a> + * @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/961e826f/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 <a href="mailto:tibordig...@apache.org">Tibor Digana (tibor17)</a> + * @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/961e826f/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/961e826f/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 @@ +<?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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>it-parent</artifactId> + <version>1.0</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>java9-full-api</artifactId> + + <properties> + <maven.compiler.source>1.6</maven.compiler.source> + <maven.compiler.target>1.6</maven.compiler.target> + </properties> + + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <forkMode>once</forkMode> + </configuration> + </plugin> + <plugin> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + <configuration> + <forkMode>once</forkMode> + </configuration> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + </dependencies> + + <profiles> + <profile> + <id>use-jvm-config-paramater</id> + <activation> + <property> + <name>jdk.home</name> + </property> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <jvm>${jdk.home}/bin/java</jvm> + </configuration> + </plugin> + </plugins> + </build> + </profile> + <profile> + <id>use-toolchains</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-toolchains-plugin</artifactId> + <version>1.1</version> + <executions> + <execution> + <phase>validate</phase> + <goals> + <goal>toolchain</goal> + </goals> + </execution> + </executions> + <configuration> + <toolchains> + <jdk> + <version>9</version> + </jdk> + </toolchains> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/961e826f/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/961e826f/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/961e826f/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 @@ <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-settings</artifactId> - <version>2.0.6</version> + <version>${mavenVersion}</version> <scope>test</scope> </dependency> <dependency> @@ -106,6 +106,23 @@ </dependencies> <build> + <resources> + <resource> + <directory>src/main/resources</directory> + <targetPath>${project.build.outputDirectory}</targetPath> + <excludes> + <exclude>toolchains.xml</exclude> + </excludes> + </resource> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + <targetPath>${project.build.directory}/private</targetPath> + <includes> + <include>toolchains.xml</include> + </includes> + </resource> + </resources> <plugins> <plugin> <artifactId>maven-help-plugin</artifactId> @@ -127,11 +144,9 @@ <plugin> <artifactId>maven-invoker-plugin</artifactId> <configuration> - <extraArtifacts> - <extraArtifact>org.apache.maven.surefire:surefire-testng-utils:${project.version}</extraArtifact> - </extraArtifacts> <localRepositoryPath>${project.build.directory}/it-repo</localRepositoryPath> <extraArtifacts> + <extraArtifact>org.apache.maven.surefire:surefire-testng-utils:${project.version}</extraArtifact> <extraArtifact>org.testng:testng:4.7:jar:jdk15</extraArtifact> <extraArtifact>org.testng:testng:5.0.2:jar:jdk15</extraArtifact> <extraArtifact>org.testng:testng:5.1:jar:jdk15</extraArtifact> @@ -173,6 +188,7 @@ <extraArtifact>junit:junit:4.8.1</extraArtifact> <extraArtifact>junit:junit:4.8.2</extraArtifact> <extraArtifact>junit:junit:4.11</extraArtifact> + <extraArtifact>junit:junit:4.12</extraArtifact> <extraArtifact>junit:junit-dep:4.8</extraArtifact> <extraArtifact>junit:junit-dep:4.7</extraArtifact> <extraArtifact>junit:junit-dep:4.4</extraArtifact> @@ -184,7 +200,11 @@ <extraArtifact>org.codehaus.plexus:plexus-utils:1.5.8</extraArtifact> <extraArtifact>org.codehaus.plexus:plexus-utils:1.5.15</extraArtifact> <extraArtifact>org.mockito:mockito-core:1.8.5</extraArtifact> + <extraArtifact>org.powermock:powermock-mockito-release-full:1.6.4:jar:full</extraArtifact> <extraArtifact>org.codehaus.plexus:plexus-interpolation:1.12</extraArtifact> + <extraArtifact>org.hamcrest:hamcrest-core:1.3</extraArtifact> + <extraArtifact>org.hamcrest:hamcrest-library:1.3</extraArtifact> + <extraArtifact>org.easytesting:fest-assert:1.4</extraArtifact> </extraArtifacts> </configuration> <executions> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/961e826f/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 @@ +<?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. + --> + +<toolchains xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd"> + <toolchain> + <type>jdk</type> + <provides> + <id>jdk9</id> + <version>9</version> + <vendor>oracle</vendor> + </provides> + <configuration> + <jdkHome>${jdk.home}</jdkHome> + </configuration> + </toolchain> +</toolchains>