|
24 | 24 | import java.nio.file.Path; |
25 | 25 | import java.util.ArrayList; |
26 | 26 | import java.util.Arrays; |
| 27 | +import java.util.Collection; |
27 | 28 | import java.util.Collections; |
28 | 29 | import java.util.Comparator; |
| 30 | +import java.util.Iterator; |
29 | 31 | import java.util.LinkedHashMap; |
30 | 32 | import java.util.List; |
31 | 33 | import java.util.Map; |
|
82 | 84 | import org.eclipse.pde.internal.launching.launcher.RequirementHelper; |
83 | 85 | import org.eclipse.pde.internal.launching.launcher.VMHelper; |
84 | 86 | import org.osgi.framework.Constants; |
| 87 | +import org.osgi.framework.Version; |
| 88 | +import org.osgi.framework.hooks.resolver.ResolverHook; |
| 89 | +import org.osgi.framework.wiring.BundleCapability; |
| 90 | +import org.osgi.framework.wiring.BundleRequirement; |
| 91 | +import org.osgi.framework.wiring.BundleRevision; |
85 | 92 |
|
86 | 93 | /** |
87 | 94 | * A launch delegate for launching JUnit Plug-in tests. |
@@ -609,8 +616,41 @@ protected void validateProjectDependencies(ILaunchConfiguration configuration, I |
609 | 616 | * @param monitor |
610 | 617 | * a progress monitor |
611 | 618 | */ |
| 619 | + @SuppressWarnings("restriction") |
612 | 620 | protected void validatePluginDependencies(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { |
613 | 621 | EclipsePluginValidationOperation op = new EclipsePluginValidationOperation(configuration, fModels.keySet(), launchMode); |
| 622 | + org.eclipse.jdt.internal.junit.launcher.ITestKind testKind = org.eclipse.jdt.internal.junit.launcher.JUnitLaunchConfigurationConstants.getTestRunnerKind(configuration); |
| 623 | + if (org.eclipse.jdt.internal.junit.launcher.TestKindRegistry.JUNIT5_TEST_KIND_ID.equals(testKind.getId())) { |
| 624 | + op.setResolverHook(new RemoveJunit6Hook()); |
| 625 | + } |
614 | 626 | LaunchPluginValidator.runValidationOperation(op, monitor); |
615 | 627 | } |
| 628 | + |
| 629 | + private static class RemoveJunit6Hook implements ResolverHook { |
| 630 | + |
| 631 | + @Override |
| 632 | + public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) { |
| 633 | + Iterator<BundleCapability> iterator = candidates.iterator(); |
| 634 | + while (iterator.hasNext()) { |
| 635 | + BundleCapability candidate = iterator.next(); |
| 636 | + String name = candidate.getResource().getSymbolicName(); |
| 637 | + Version version = candidate.getResource().getVersion(); |
| 638 | + if (version.getMajor() == 6 && (name.startsWith("junit") || name.startsWith("org.junit"))) { //$NON-NLS-1$ //$NON-NLS-2$ |
| 639 | + iterator.remove(); |
| 640 | + } |
| 641 | + } |
| 642 | + } |
| 643 | + |
| 644 | + @Override |
| 645 | + public void filterResolvable(Collection<BundleRevision> candidates) { |
| 646 | + } |
| 647 | + |
| 648 | + @Override |
| 649 | + public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) { |
| 650 | + } |
| 651 | + |
| 652 | + @Override |
| 653 | + public void end() { |
| 654 | + } |
| 655 | + } |
616 | 656 | } |
0 commit comments