This is an automated email from the ASF dual-hosted git repository. tibordigana pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit 46cd88c6c92f4fb0cfc75eda7ee8ce6912d0c49a Author: tibordigana <tibordig...@apache.org> AuthorDate: Sun Nov 10 00:47:26 2019 +0100 [SUREFIRE-1712] Running tests with JDK13 fails with Unsupported class file major version 57 --- .../plugin/surefire/AbstractSurefireMojo.java | 6 ++- .../ModularClasspathForkConfiguration.java | 36 ++----------- .../AbstractSurefireMojoJava7PlusTest.java | 15 ++++-- .../ModularClasspathForkConfigurationTest.java | 15 ++---- .../maven/surefire/booter/ModularClasspath.java | 10 ++-- ...urefire1712ExtractedModulenameWithoutASMIT.java | 53 ++++++++++++++++++ .../pom.xml | 63 ++++++++++++++++++++++ .../src/main/java/module-info.java | 23 ++++++++ .../src/main/java/wtf/g4s8/oot/Foo.java | 35 ++++++++++++ .../src/test/java/module-info.java | 25 +++++++++ .../src/test/java/wtf/g4s8/oot/test/FooTest.java | 35 ++++++++++++ 11 files changed, 260 insertions(+), 56 deletions(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java index 4ee933b..5683b7f 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java @@ -1901,8 +1901,10 @@ public abstract class AbstractSurefireMojo packages.add( substringBeforeLast( className, "." ) ); } - ModularClasspath modularClasspath = new ModularClasspath( moduleDescriptor, testModulepath.getClassPath(), - packages, getTestClassesDirectory() ); + getConsoleLogger().debug( "main module descriptor name: " + result.getMainModuleDescriptor().name() ); + + ModularClasspath modularClasspath = new ModularClasspath( result.getMainModuleDescriptor().name(), + testModulepath.getClassPath(), packages, getTestClassesDirectory() ); Artifact[] additionalInProcArtifacts = { getCommonArtifact(), getExtensionsArtifact(), getApiArtifact(), getLoggerApiArtifact() }; diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java index 55818a2..af38bc5 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java @@ -28,15 +28,11 @@ import org.apache.maven.surefire.booter.ModularClasspath; import org.apache.maven.surefire.booter.ModularClasspathConfiguration; import org.apache.maven.surefire.booter.StartupConfiguration; import org.apache.maven.surefire.booter.SurefireBooterForkException; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ModuleVisitor; import javax.annotation.Nonnegative; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.File; -import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.util.Collection; @@ -50,7 +46,6 @@ import static java.io.File.pathSeparatorChar; import static org.apache.maven.plugin.surefire.SurefireHelper.escapeToPlatformPath; import static org.apache.maven.shared.utils.StringUtils.replace; import static org.apache.maven.surefire.util.internal.StringUtils.NL; -import static org.objectweb.asm.Opcodes.ASM7; /** * @author <a href="mailto:tibordig...@apache.org">Tibor Digana (tibor17)</a> @@ -92,13 +87,13 @@ public class ModularClasspathForkConfiguration ModularClasspath modularClasspath = modularClasspathConfiguration.getModularClasspath(); - File descriptor = modularClasspath.getModuleDescriptor(); + String moduleName = modularClasspath.getModuleNameFromDescriptor(); List<String> modulePath = modularClasspath.getModulePath(); Collection<String> packages = modularClasspath.getPackages(); File patchFile = modularClasspath.getPatchFile(); List<String> classpath = toCompleteClasspath( config ); - File argsFile = createArgsFile( descriptor, modulePath, classpath, packages, patchFile, startClass ); + File argsFile = createArgsFile( moduleName, modulePath, classpath, packages, patchFile, startClass ); cli.createArg().setValue( "@" + escapeToPlatformPath( argsFile.getAbsolutePath() ) ); } @@ -112,7 +107,7 @@ public class ModularClasspathForkConfiguration } @Nonnull - File createArgsFile( @Nonnull File moduleDescriptor, @Nonnull List<String> modulePath, + File createArgsFile( @Nonnull String moduleName, @Nonnull List<String> modulePath, @Nonnull List<String> classPath, @Nonnull Collection<String> packages, @Nonnull File patchFile, @Nonnull String startClassName ) throws IOException @@ -169,8 +164,6 @@ public class ModularClasspathForkConfiguration .append( NL ); } - final String moduleName = toModuleName( moduleDescriptor ); - args.append( "--patch-module" ) .append( NL ) .append( moduleName ) @@ -218,27 +211,4 @@ public class ModularClasspathForkConfiguration return surefireArgs; } } - - @Nonnull - String toModuleName( @Nonnull File moduleDescriptor ) throws IOException - { - if ( !moduleDescriptor.isFile() ) - { - throw new IOException( "No such Jigsaw module-descriptor exists " + moduleDescriptor.getAbsolutePath() ); - } - - final StringBuilder sb = new StringBuilder(); - new ClassReader( new FileInputStream( moduleDescriptor ) ).accept( new ClassVisitor( ASM7 ) - { - @Override - public ModuleVisitor visitModule( String name, int access, String version ) - { - sb.setLength( 0 ); - sb.append( name ); - return super.visitModule( name, access, version ); - } - }, 0 ); - - return sb.toString(); - } } diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java index 0850e2a..1f0309b 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java @@ -30,6 +30,7 @@ import org.apache.maven.surefire.booter.ModularClasspathConfiguration; import org.apache.maven.surefire.booter.StartupConfiguration; import org.apache.maven.surefire.suite.RunResult; import org.apache.maven.surefire.util.DefaultScanResult; +import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor; import org.codehaus.plexus.languages.java.jpms.LocationManager; import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest; import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult; @@ -82,6 +83,9 @@ public class AbstractSurefireMojoJava7PlusTest @Mock private LocationManager locationManager; + @Mock + private JavaModuleDescriptor descriptor; + @Test @SuppressWarnings( "checkstyle:linelength" ) public void shouldHaveStartupConfigForModularClasspath() @@ -142,8 +146,11 @@ public class AbstractSurefireMojoJava7PlusTest when( req.setJdkHome( anyString() ) ).thenReturn( req ); when( req.setMainModuleDescriptor( eq( moduleInfo.getAbsolutePath() ) ) ).thenReturn( req ); + when( descriptor.name() ).thenReturn( "abc" ); + @SuppressWarnings( "unchecked" ) ResolvePathsResult<String> res = mock( ResolvePathsResult.class ); + when( res.getMainModuleDescriptor() ).thenReturn( descriptor ); when( res.getClasspathElements() ).thenReturn( asList( "non-modular.jar", "junit.jar", "hamcrest.jar" ) ); Map<String, ModuleNameSource> mod = new LinkedHashMap<>(); mod.put( "modular.jar", null ); @@ -203,9 +210,10 @@ public class AbstractSurefireMojoJava7PlusTest assertThat( argument2.getValue().getMessage() ) .isEqualTo( "low version" ); ArgumentCaptor<String> argument = ArgumentCaptor.forClass( String.class ); - verify( logger, times( 8 ) ).debug( argument.capture() ); + verify( logger, times( 9 ) ).debug( argument.capture() ); assertThat( argument.getAllValues() ) - .containsExactly( "test classpath: non-modular.jar junit.jar hamcrest.jar", + .containsExactly( "main module descriptor name: abc", + "test classpath: non-modular.jar junit.jar hamcrest.jar", "test modulepath: modular.jar classes", "provider classpath: surefire-provider.jar", "test(compact) classpath: non-modular.jar junit.jar hamcrest.jar", @@ -229,13 +237,12 @@ public class AbstractSurefireMojoJava7PlusTest .isEqualTo( new Classpath( singleton( "surefire-provider.jar" ) ) ); assertThat( conf.getClasspathConfiguration() ).isInstanceOf( ModularClasspathConfiguration.class ); ModularClasspathConfiguration mcc = ( ModularClasspathConfiguration ) conf.getClasspathConfiguration(); - assertThat( mcc.getModularClasspath().getModuleDescriptor() ).isEqualTo( moduleInfo ); + assertThat( mcc.getModularClasspath().getModuleNameFromDescriptor() ).isEqualTo( "abc" ); assertThat( mcc.getModularClasspath().getPackages() ).containsOnly( "org.apache" ); assertThat( mcc.getModularClasspath().getPatchFile().getAbsolutePath() ) .isEqualTo( "test-classes" ); assertThat( mcc.getModularClasspath().getModulePath() ) .containsExactly( "modular.jar", "classes" ); - assertThat( ( Object ) mcc.getTestClasspath() ).isEqualTo( new Classpath( res.getClasspathElements() ) ); } private static File mockFile( String absolutePath ) diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfigurationTest.java index 72eafb9..806f3eb 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfigurationTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfigurationTest.java @@ -29,7 +29,6 @@ import org.apache.maven.surefire.booter.ModularClasspathConfiguration; import org.apache.maven.surefire.booter.StartupConfiguration; import org.junit.Test; -import javax.annotation.Nonnull; import java.io.File; import java.util.Collection; import java.util.Collections; @@ -67,15 +66,7 @@ public class ModularClasspathForkConfigurationTest ModularClasspathForkConfiguration config = new ModularClasspathForkConfiguration( booter, tmp, "", pwd, new Properties(), "", Collections.<String, String>emptyMap(), new String[0], true, 1, true, - new Platform(), new NullConsoleLogger() ) - { - @Nonnull - @Override - String toModuleName( @Nonnull File moduleDescriptor ) - { - return "abc"; - } - }; + new Platform(), new NullConsoleLogger() ); File patchFile = new File( "target" + separatorChar + "test-classes" ); File descriptor = new File( tmp, "module-info.class" ); @@ -87,7 +78,7 @@ public class ModularClasspathForkConfigurationTest String startClassName = ForkedBooter.class.getName(); File jigsawArgsFile = - config.createArgsFile( descriptor, modulePath, classPath, packages, patchFile, startClassName ); + config.createArgsFile( "abc", modulePath, classPath, packages, patchFile, startClassName ); assertThat( jigsawArgsFile ) .isNotNull(); @@ -143,7 +134,7 @@ public class ModularClasspathForkConfigurationTest assertThat( argsFileLines.get( 12 ) ) .isEqualTo( ForkedBooter.class.getName() ); - ModularClasspath modularClasspath = new ModularClasspath( descriptor, modulePath, packages, patchFile ); + ModularClasspath modularClasspath = new ModularClasspath( "abc", modulePath, packages, patchFile ); Classpath testClasspathUrls = new Classpath( singleton( "target" + separator + "test-classes" ) ); Classpath surefireClasspathUrls = Classpath.emptyClasspath(); ModularClasspathConfiguration modularClasspathConfiguration = diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ModularClasspath.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ModularClasspath.java index 9607b27..7bf8bd0 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ModularClasspath.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ModularClasspath.java @@ -35,25 +35,25 @@ import static java.util.Collections.unmodifiableList; */ public final class ModularClasspath { - private final File moduleDescriptor; + private final String moduleNameFromDescriptor; private final List<String> modulePath; private final Collection<String> packages; private final File patchFile; - public ModularClasspath( @Nonnull File moduleDescriptor, @Nonnull List<String> modulePath, + public ModularClasspath( @Nonnull String moduleNameFromDescriptor, @Nonnull List<String> modulePath, @Nonnull Collection<String> packages, @Nonnull File patchFile ) { - this.moduleDescriptor = moduleDescriptor; + this.moduleNameFromDescriptor = moduleNameFromDescriptor; this.modulePath = modulePath; this.packages = packages; this.patchFile = patchFile; } @Nonnull - public File getModuleDescriptor() + public String getModuleNameFromDescriptor() { - return moduleDescriptor; + return moduleNameFromDescriptor; } @Nonnull diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1712ExtractedModulenameWithoutASMIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1712ExtractedModulenameWithoutASMIT.java new file mode 100644 index 0000000..92c56ad --- /dev/null +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1712ExtractedModulenameWithoutASMIT.java @@ -0,0 +1,53 @@ +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.AbstractJigsawIT; +import org.junit.Test; + +import java.io.IOException; + +/** + * See the JIRA https://issues.apache.org/jira/browse/SUREFIRE-1712 + * + * @author <a href="mailto:tibordig...@apache.org">Tibor Digana (tibor17)</a> + * @since 3.0.0-M4 + */ +public class Surefire1712ExtractedModulenameWithoutASMIT + extends AbstractJigsawIT +{ + @Test + public void test() + throws IOException + { + assumeJava9() + .debugLogging() + .executeTest() + .assertTestSuiteResults( 1, 0, 0, 0 ) + .verifyErrorFreeLog() + .verifyTextInLog( "main module descriptor name: wtf.g4s8.oot" ); + } + + @Override + protected String getProjectDirectoryName() + { + return "surefire-1712-extracted-modulename-without-asm"; + } +} diff --git a/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/pom.xml b/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/pom.xml new file mode 100644 index 0000000..f2cb6aa --- /dev/null +++ b/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/pom.xml @@ -0,0 +1,63 @@ +<?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> + + <groupId>abc</groupId> + <artifactId>xyz</artifactId> + <version>1.0</version> + + <properties> + <junit-platform.version>5.5.2</junit-platform.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <maven.compiler.release>9</maven.compiler.release> + </properties> + + <dependencies> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <version>5.5.2</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>${surefire.version}</version> + </plugin> + </plugins> + </build> +</project> diff --git a/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/src/main/java/module-info.java b/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/src/main/java/module-info.java new file mode 100644 index 0000000..a0b3588 --- /dev/null +++ b/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/src/main/java/module-info.java @@ -0,0 +1,23 @@ +/* + * 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. + */ + +module wtf.g4s8.oot +{ + exports wtf.g4s8.oot; +} diff --git a/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/src/main/java/wtf/g4s8/oot/Foo.java b/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/src/main/java/wtf/g4s8/oot/Foo.java new file mode 100644 index 0000000..1540031 --- /dev/null +++ b/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/src/main/java/wtf/g4s8/oot/Foo.java @@ -0,0 +1,35 @@ +package wtf.g4s8.oot; + +/* + * 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. + */ + +public final class Foo +{ + private final int base; + + public Foo( int base ) + { + this.base = base; + } + + public int add( final int x ) + { + return this.base + x; + } +} diff --git a/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/src/test/java/module-info.java b/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/src/test/java/module-info.java new file mode 100644 index 0000000..7bbf986 --- /dev/null +++ b/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/src/test/java/module-info.java @@ -0,0 +1,25 @@ +/* + * 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. + */ + +module wtf.g4s8.oot.test +{ + requires wtf.g4s8.oot; + requires org.junit.jupiter.api; + requires transitive org.hamcrest; +} diff --git a/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/src/test/java/wtf/g4s8/oot/test/FooTest.java b/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/src/test/java/wtf/g4s8/oot/test/FooTest.java new file mode 100644 index 0000000..d8aa49d --- /dev/null +++ b/surefire-its/src/test/resources/surefire-1712-extracted-modulename-without-asm/src/test/java/wtf/g4s8/oot/test/FooTest.java @@ -0,0 +1,35 @@ +package wtf.g4s8.oot.test; + +/* + * 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.hamcrest.Matchers; +import org.junit.jupiter.api.Test; +import wtf.g4s8.oot.Foo; + +import static org.hamcrest.MatcherAssert.assertThat; + +public class FooTest +{ + @Test + public void addTest() + { + assertThat( new Foo( 1 ).add( 1 ), Matchers.equalTo( 2 ) ); + } +}