3737
3838public class JUnitLaunchRequirements {
3939
40- public static final String JUNIT4_JDT_RUNTIME_PLUGIN = "org.eclipse.jdt.junit4.runtime" ; //$NON-NLS-1$
41- public static final String JUNIT5_JDT_RUNTIME_PLUGIN = "org.eclipse.jdt.junit5.runtime" ; //$NON-NLS-1$
42- public static void addRequiredJunitRuntimePlugins (ILaunchConfiguration configuration , Map <String , List <IPluginModelBase >> allBundles , Map <IPluginModelBase , String > allModels ) throws CoreException {
40+ private static final String PDE_JUNIT_RUNTIME = "org.eclipse.pde.junit.runtime" ; //$NON-NLS-1$
41+ private static final String JUNIT4_JDT_RUNTIME_PLUGIN = "org.eclipse.jdt.junit4.runtime" ; //$NON-NLS-1$
42+ private static final String JUNIT5_JDT_RUNTIME_PLUGIN = "org.eclipse.jdt.junit5.runtime" ; //$NON-NLS-1$
43+
44+ public static void addRequiredJunitRuntimePlugins (ILaunchConfiguration configuration , Map <String , List <IPluginModelBase >> collectedModels , Map <IPluginModelBase , String > startLevelMap ) throws CoreException {
4345 Collection <String > runtimePlugins = getRequiredJunitRuntimeEclipsePlugins (configuration );
44- Set <BundleDescription > addedRuntimeBundles = addAbsentRequirements (runtimePlugins , allBundles , allModels );
46+ Set <BundleDescription > addedRuntimeBundles = addAbsentRequirements (runtimePlugins , collectedModels , startLevelMap );
4547 Set <BundleDescription > runtimeRequirements = DependencyManager .findRequirementsClosure (addedRuntimeBundles );
46- addAbsentRequirements (runtimeRequirements , allBundles , allModels );
48+ addAbsentRequirements (runtimeRequirements , collectedModels , startLevelMap );
4749 }
4850
4951 @ SuppressWarnings ("restriction" )
@@ -52,40 +54,42 @@ public static Collection<String> getRequiredJunitRuntimeEclipsePlugins(ILaunchCo
5254 if (testKind .isNull ()) {
5355 return List .of ();
5456 }
55- List <String > plugins = new ArrayList <>();
56- plugins .add ("org.eclipse.pde.junit.runtime" ); //$NON-NLS-1$
5757 switch (testKind .getId ()) {
5858 case org .eclipse .jdt .internal .junit .launcher .TestKindRegistry .JUNIT3_TEST_KIND_ID -> {
59+ return List .of (PDE_JUNIT_RUNTIME );
5960 } // Nothing to add for JUnit-3
60- case org .eclipse .jdt .internal .junit .launcher .TestKindRegistry .JUNIT4_TEST_KIND_ID -> plugins .add (JUNIT4_JDT_RUNTIME_PLUGIN );
61- case org .eclipse .jdt .internal .junit .launcher .TestKindRegistry .JUNIT5_TEST_KIND_ID -> plugins .add (JUNIT5_JDT_RUNTIME_PLUGIN );
61+ case org .eclipse .jdt .internal .junit .launcher .TestKindRegistry .JUNIT4_TEST_KIND_ID -> {
62+ return List .of (PDE_JUNIT_RUNTIME ,JUNIT4_JDT_RUNTIME_PLUGIN );
63+ }
64+ case org .eclipse .jdt .internal .junit .launcher .TestKindRegistry .JUNIT5_TEST_KIND_ID -> {
65+ return List .of (PDE_JUNIT_RUNTIME , JUNIT5_JDT_RUNTIME_PLUGIN );
66+ }
6267 default -> throw new IllegalArgumentException ("Unsupported junit test kind: " + testKind .getId ()); //$NON-NLS-1$
6368 }
64- return plugins ;
6569 }
6670
67- private static Set <BundleDescription > addAbsentRequirements (Collection <String > requirements , Map <String , List <IPluginModelBase >> allBundles , Map <IPluginModelBase , String > allModels ) throws CoreException {
71+ private static Set <BundleDescription > addAbsentRequirements (Collection <String > requirements , Map <String , List <IPluginModelBase >> collectedModels , Map <IPluginModelBase , String > startLevelMap ) throws CoreException {
6872 Set <BundleDescription > addedRequirements = new LinkedHashSet <>();
6973 for (String id : requirements ) {
70- List <IPluginModelBase > models = allBundles .computeIfAbsent (id , k -> new ArrayList <>());
74+ List <IPluginModelBase > models = collectedModels .computeIfAbsent (id , k -> new ArrayList <>());
7175 if (models .stream ().noneMatch (p -> p .getBundleDescription ().isResolved ())) {
7276 IPluginModelBase model = findRequiredPluginInTargetOrHost (PluginRegistry .findModel (id ), plugins -> plugins .max (PDECore .VERSION ), id );
7377 models .add (model );
74- BundleLauncherHelper .addDefaultStartingBundle (allModels , model );
78+ BundleLauncherHelper .addDefaultStartingBundle (startLevelMap , model );
7579 addedRequirements .add (model .getBundleDescription ());
7680 }
7781 }
7882 return addedRequirements ;
7983 }
8084
81- private static void addAbsentRequirements (Set <BundleDescription > requirements , Map <String , List <IPluginModelBase >> allBundles , Map <IPluginModelBase , String > allModels ) throws CoreException {
85+ private static void addAbsentRequirements (Set <BundleDescription > requirements , Map <String , List <IPluginModelBase >> collectedModels , Map <IPluginModelBase , String > startLevelMap ) throws CoreException {
8286 for (BundleRevision bundle : requirements ) {
8387 String id = bundle .getSymbolicName ();
84- List <IPluginModelBase > models = allBundles .computeIfAbsent (id , k -> new ArrayList <>());
88+ List <IPluginModelBase > models = collectedModels .computeIfAbsent (id , k -> new ArrayList <>());
8589 if (models .stream ().map (IPluginModelBase ::getBundleDescription ).noneMatch (b -> b .isResolved () && b .getVersion ().equals (bundle .getVersion ()))) {
8690 IPluginModelBase model = findRequiredPluginInTargetOrHost (PluginRegistry .findModel (bundle ), plgs -> plgs .filter (p -> p .getBundleDescription () == bundle ).findFirst (), id );
8791 models .add (model );
88- BundleLauncherHelper .addDefaultStartingBundle (allModels , model );
92+ BundleLauncherHelper .addDefaultStartingBundle (startLevelMap , model );
8993 }
9094 }
9195 }
0 commit comments