Skip to content

Commit ada89f3

Browse files
committed
Check for JUnit 5 and 6 conflicts with junit-jupiter-engine and not with
junit-platform-engine Fixes: #2045
1 parent 2b81907 commit ada89f3

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/JUnitLaunchValidationOperation.java

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,28 @@
1717
import java.util.LinkedHashMap;
1818
import java.util.Map;
1919
import java.util.Set;
20-
import java.util.stream.Collectors;
2120

2221
import org.eclipse.core.runtime.CoreException;
2322
import org.eclipse.core.runtime.IProgressMonitor;
2423
import org.eclipse.core.runtime.Status;
2524
import org.eclipse.debug.core.ILaunchConfiguration;
2625
import org.eclipse.jdt.internal.junit.launcher.TestKindRegistry;
2726
import org.eclipse.osgi.service.resolver.BundleDescription;
27+
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
2828
import org.eclipse.osgi.util.NLS;
2929
import org.eclipse.pde.core.plugin.IPluginModelBase;
3030
import org.eclipse.pde.internal.launching.launcher.LaunchValidationOperation;
31-
import org.osgi.framework.Version;
3231

3332
public class JUnitLaunchValidationOperation extends LaunchValidationOperation {
3433

35-
private static final Set<String> JUNIT_PLATFORM_ENGINE_BUNLDES = Set.of(new String[] { //
36-
"junit-platform-engine", //$NON-NLS-1$
37-
"org.junit.platform.engine", //$NON-NLS-1$
34+
private static final String JUNIT_ORBIT_BUNDLE_PREFIX = "org.junit"; //$NON-NLS-1$
35+
private static final String JUNIT_MAVEN_BUNDLE_PREFIX = "junit"; //$NON-NLS-1$
36+
37+
private static final String ORG_JUNIT_JUPITER_ENGINE_PACKAGE = "org.junit.jupiter.engine"; //$NON-NLS-1$
38+
39+
private static final Set<String> JUNIT_JUPITER_ENGINE_BUNDLES = Set.of(new String[] { //
40+
"junit-jupiter-engine", //$NON-NLS-1$
41+
"org.junit.jupiter.engine", //$NON-NLS-1$
3842
});
3943

4044
private final Map<Object, Object[]> fErrors = new HashMap<>(2);
@@ -58,17 +62,34 @@ private void checkJunitVersion(ILaunchConfiguration configuration, Set<IPluginMo
5862
if (testKind.isNull()) {
5963
return;
6064
}
61-
Set<Version> junitPlatformBundlesVersions = junitPlatformBundleVersions(models);
6265
String testKindId = testKind.getId();
6366
switch (testKindId) {
6467
case TestKindRegistry.JUNIT3_TEST_KIND_ID, TestKindRegistry.JUNIT4_TEST_KIND_ID -> {
6568
} // nothing to check
6669
case TestKindRegistry.JUNIT5_TEST_KIND_ID -> {
67-
// JUnit 5 platform bundles have version range [1.0,2.0)
68-
junitPlatformBundlesVersions.stream().map(Version::getMajor).filter(i -> i.intValue() != 1).findFirst().ifPresent(otherVersion -> {
69-
String message = NLS.bind(PDEMessages.JUnitLaunchConfiguration_error_JUnitLaunchAndRuntimeMissmatch, 5, otherVersion);
70-
addError(message);
71-
});
70+
for (IPluginModelBase model : models) {
71+
BundleDescription description = model.getBundleDescription();
72+
String symbolicName = description.getSymbolicName();
73+
if (symbolicName.startsWith(JUNIT_MAVEN_BUNDLE_PREFIX) || symbolicName.startsWith(JUNIT_ORBIT_BUNDLE_PREFIX)) {
74+
continue;
75+
}
76+
BundleDescription[] requires = description.getResolvedRequires();
77+
for (BundleDescription required : requires) {
78+
if (JUNIT_JUPITER_ENGINE_BUNDLES.contains(required.getSymbolicName()) && required.getVersion().getMajor() == 6) {
79+
String message = NLS.bind(PDEMessages.JUnitLaunchConfiguration_error_JUnitLaunchAndRuntimeMissmatch, 5, required.getVersion().getMajor(), symbolicName);
80+
addError(message);
81+
break;
82+
}
83+
}
84+
ExportPackageDescription[] resolvedImports = description.getResolvedImports();
85+
for (ExportPackageDescription resolvedImport : resolvedImports) {
86+
if (resolvedImport.getName().startsWith(ORG_JUNIT_JUPITER_ENGINE_PACKAGE) && resolvedImport.getVersion().getMajor() == 6) {
87+
String message = NLS.bind(PDEMessages.JUnitLaunchConfiguration_error_JUnitLaunchAndRuntimeMissmatch, 5, resolvedImport.getVersion().getMajor(), symbolicName);
88+
addError(message);
89+
break;
90+
}
91+
}
92+
}
7293
}
7394
default -> throw new CoreException(Status.error("Unsupported test kind: " + testKindId)); //$NON-NLS-1$
7495
}
@@ -89,10 +110,4 @@ public Map<Object, Object[]> getInput() {
89110
map.putAll(fErrors);
90111
return map;
91112
}
92-
93-
private static Set<Version> junitPlatformBundleVersions(Set<IPluginModelBase> models) {
94-
return models.stream().map(IPluginModelBase::getBundleDescription) //
95-
.filter(d -> JUNIT_PLATFORM_ENGINE_BUNLDES.contains(d.getSymbolicName())) //
96-
.map(BundleDescription::getVersion).collect(Collectors.toSet());
97-
}
98113
}

ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/pderesources.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Therefore this launch is expected to fail.\n\
3131
Either update the launch configuration to target JUnit {1},\n\
3232
or restrict the versions of JUnit Jupiter and JUnit Platform\n\
3333
by specifying corresponding version bounds\n\
34-
in your test-project to match only JUnit {0}.
34+
of bundle {2} to match only JUnit {0}.
3535

3636
OSGiLaunchConfiguration_cannotFindLaunchConfiguration=Cannot find the {0} OSGi framework.
3737
OSGiLaunchConfiguration_selected=selected

0 commit comments

Comments
 (0)