olamy commented on code in PR #3523:
URL: https://github.com/apache/maven-surefire/pull/3523#discussion_r4572803213
##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java:
##########
@@ -2101,21 +2104,35 @@ private StartupConfiguration
newStartupConfigWithModularPath(
providerClasspath =
classpathCache.setCachedClasspath(providerName, providerArtifacts);
}
- // the Maven 3 guesses about what goes on the module path, see
ModulePathJpmsArguments
+ final Set<String> testModuleNames;
final ModulePathJpmsArguments.Layout layout;
if (isMainDescriptor) {
+ // the Maven 3 guesses about what goes on the module path, see
ModulePathJpmsArguments
for (String className : scanResult.getClasses()) {
packages.add(substringBeforeLast(className, "."));
}
layout = ModulePathJpmsArguments.forMainModule(
getLocationManager(), testClasspath, javaModuleDescriptor,
javaHome, packages, getConsoleLogger());
+ testModuleNames = layout.getModuleNames();
} else {
+ if (JUNIT_PLATFORM_PROVIDER_NAME.equals(providerName)) {
+ ResolvePathsRequest<String> req =
ResolvePathsRequest.ofStrings(testClasspath.getClassPath())
+ .setIncludeAllProviders(true)
+ .setJdkHome(javaHome)
+ .setIncludeStatic(true)
+ .setModuleDescriptor(javaModuleDescriptor);
+ testModuleNames =
ModulePathJpmsArguments.moduleNamesOnModulepath(
+ getLocationManager().resolvePaths(req));
Review Comment:
This only returns modules reachable from the test module-info's `requires`.
The fork puts the whole test classpath on the module path (`--add-modules
ALL-MODULE-PATH`), so Commons can be a module there without showing up here.
For example, a test module that only requires `junit`, with vintage pulling in
Commons, would lose opens it still needs.
It also scans every jar a second time and ignores `getPathExceptions()`.
##########
maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java:
##########
@@ -467,8 +533,17 @@ public void testAllProviderInfo() {
assertThat(providerInfo.getProviderName())
.isEqualTo("org.apache.maven.surefire.junitplatform.JUnitPlatformProvider");
List<String[]> args =
providerInfo.getJpmsArguments(providerRequirements);
- assertThat(args)
- .isNotEmpty()
+ assertThat(args).isEmpty();
+
+ Artifact junitPlatformCommons = new DefaultArtifact(
+ "org.junit.platform", "junit-platform-commons",
createFromVersion("1"), "test", "jar", "", handler);
+ providerInfo =
+ mojo.newJUnitPlatformProviderInfo(new
TestClassPath(singleton(junitPlatformCommons), null, null, null));
Review Comment:
This sets up Commons as a test dependency, but `getJpmsArguments` never
reads it. Could you add tests for:
- Commons as a test dependency: opens added
- Commons only on the provider classpath: no opens
- Shadefire
##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java:
##########
@@ -2101,21 +2104,35 @@ private StartupConfiguration
newStartupConfigWithModularPath(
providerClasspath =
classpathCache.setCachedClasspath(providerName, providerArtifacts);
}
- // the Maven 3 guesses about what goes on the module path, see
ModulePathJpmsArguments
+ final Set<String> testModuleNames;
final ModulePathJpmsArguments.Layout layout;
if (isMainDescriptor) {
+ // the Maven 3 guesses about what goes on the module path, see
ModulePathJpmsArguments
for (String className : scanResult.getClasses()) {
packages.add(substringBeforeLast(className, "."));
}
layout = ModulePathJpmsArguments.forMainModule(
getLocationManager(), testClasspath, javaModuleDescriptor,
javaHome, packages, getConsoleLogger());
+ testModuleNames = layout.getModuleNames();
} else {
+ if (JUNIT_PLATFORM_PROVIDER_NAME.equals(providerName)) {
Review Comment:
This name check misses Shadefire. `JUnitPlatformProviderShadefireInfo`
inherits `getJpmsArguments` but has a different provider name, so it never gets
the opens.
##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java:
##########
@@ -3236,7 +3253,9 @@ public void addProviderProperties() throws
MojoExecutionException {
@Nonnull
@Override
public List<String[]> getJpmsArguments(@Nonnull ProviderRequirements
forkRequirements) {
- return
ModulePathJpmsArguments.junitPlatformArguments(forkRequirements);
+ return
forkRequirements.getTestModuleNames().contains("org.junit.platform.commons")
Review Comment:
Could the whole check live here instead?
```java
if
(!testClasspath.getTestDependencies().containsKey("org.junit.platform:junit-platform-commons"))
{
return emptyList();
}
return ModulePathJpmsArguments.junitPlatformArguments(forkRequirements);
```
Shadefire inherits it, and the `ProviderRequirements` change, the extra
resolve and `Layout.moduleNames` aren't needed any more (`moduleNames` is only
filled for the main-descriptor case, where the opens are never added anyway).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]