Skip to content

Commit 3201782

Browse files
trancexpressHannesWell
authored andcommitted
Re-add JUnit 4 to org.eclipse.pde.core.requiredPlugins
Due to the changes for #2007, the container org.eclipse.pde.core.requiredPlugins is now missing JUnit 4. This change re-adds JUnit 4 to this container. Fixes: #2020
1 parent c06c4ef commit 3201782

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/RequiredPluginsClasspathContainer.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Comparator;
2525
import java.util.HashMap;
2626
import java.util.HashSet;
27+
import java.util.LinkedHashSet;
2728
import java.util.List;
2829
import java.util.Map;
2930
import java.util.Objects;
@@ -79,6 +80,9 @@ class RequiredPluginsClasspathContainer {
7980
private static final Version JUNIT_5_9 = new Version(5, 9, 0);
8081
private static final VersionRange BELOW_JUNIT_5_9 = new VersionRange("[1.0,5.9)"); //$NON-NLS-1$
8182

83+
@SuppressWarnings("nls")
84+
private static final String JUNIT4_PLUGIN = "org.junit";
85+
private static final VersionRange JUNIT_4_VERSION = new VersionRange("[4.0,5)"); //$NON-NLS-1$
8286
@SuppressWarnings("nls")
8387
private static final Set<String> JUNIT5_RUNTIME_PLUGINS = Set.of("org.junit", //
8488
"junit-platform-launcher",
@@ -592,9 +596,15 @@ private void addJunit5RuntimeDependencies(Set<BundleDescription> added, List<ICl
592596
Collection<BundleDescription> junitRequirements;
593597
if (junitBundle.getVersion().compareTo(JUNIT_5_9) < 0) {
594598
// JUnit 5.8 and below bundles don't have specific version requirements that we can use
595-
junitRequirements = collectRuntimeRequirementsBelowJunit5_9();
599+
junitRequirements = collectRequirements(
600+
JUNIT5_RUNTIME_PLUGINS.stream().map(id -> PluginRegistry.findModel(id, BELOW_JUNIT_5_9)));
596601
} else {
597-
junitRequirements = DependencyManager.findRequirementsClosure(List.of(junitBundle));
602+
junitRequirements = new LinkedHashSet<>();
603+
List<BundleDescription> junitJupiterRequirements = collectRequirements(List.of(junitBundle));
604+
junitRequirements.addAll(junitJupiterRequirements);
605+
List<BundleDescription> junit4Requirements = collectRequirements(
606+
Stream.of(PluginRegistry.findModel(JUNIT4_PLUGIN, JUNIT_4_VERSION)));
607+
junitRequirements.addAll(junit4Requirements);
598608
}
599609
if (junitRequirements.isEmpty()) {
600610
return;
@@ -616,12 +626,14 @@ private void addJunit5RuntimeDependencies(Set<BundleDescription> added, List<ICl
616626
}
617627
}
618628

619-
private static List<BundleDescription> collectRuntimeRequirementsBelowJunit5_9() {
620-
List<BundleDescription> roots = JUNIT5_RUNTIME_PLUGINS.stream()
621-
.map(id -> PluginRegistry.findModel(id, BELOW_JUNIT_5_9)).filter(Objects::nonNull)
622-
.filter(IPluginModelBase::isEnabled).map(IPluginModelBase::getBundleDescription).toList();
623-
Set<BundleDescription> closure = DependencyManager.findRequirementsClosure(roots,
624-
INCLUDE_OPTIONAL_DEPENDENCIES);
629+
private static List<BundleDescription> collectRequirements(Stream<IPluginModelBase> models) {
630+
List<BundleDescription> roots = models.filter(Objects::nonNull).filter(IPluginModelBase::isEnabled)
631+
.map(IPluginModelBase::getBundleDescription).toList();
632+
return collectRequirements(roots);
633+
}
634+
635+
private static List<BundleDescription> collectRequirements(List<BundleDescription> roots) {
636+
var closure = DependencyManager.findRequirementsClosure(roots, INCLUDE_OPTIONAL_DEPENDENCIES);
625637
String systemBundleBSN = TargetPlatformHelper.getPDEState().getSystemBundle();
626638
return closure.stream().filter(b -> !b.getSymbolicName().equals(systemBundleBSN))
627639
.sorted(Comparator.comparing(BundleDescription::getSymbolicName)).toList();

0 commit comments

Comments
 (0)