2424import java .nio .file .Path ;
2525import java .util .ArrayList ;
2626import java .util .Arrays ;
27- import java .util .Collection ;
2827import java .util .Collections ;
2928import java .util .Comparator ;
30- import java .util .HashSet ;
3129import java .util .LinkedHashMap ;
32- import java .util .LinkedHashSet ;
3330import java .util .List ;
3431import java .util .Map ;
3532import java .util .Properties ;
36- import java .util .Set ;
3733import java .util .jar .JarOutputStream ;
3834import java .util .jar .Manifest ;
3935import java .util .stream .Collectors ;
5854import org .eclipse .jdt .launching .IVMInstall ;
5955import org .eclipse .jdt .launching .IVMRunner ;
6056import org .eclipse .jdt .launching .JavaRuntime ;
61- import org .eclipse .osgi .service .resolver .BundleDescription ;
6257import org .eclipse .osgi .util .ManifestElement ;
6358import org .eclipse .osgi .util .NLS ;
6459import org .eclipse .pde .core .plugin .IFragment ;
6964import org .eclipse .pde .core .plugin .TargetPlatform ;
7065import org .eclipse .pde .internal .build .IPDEBuildConstants ;
7166import org .eclipse .pde .internal .core .ClasspathHelper ;
72- import org .eclipse .pde .internal .core .DependencyManager ;
7367import org .eclipse .pde .internal .core .ICoreConstants ;
74- import org .eclipse .pde .internal .core .PDECore ;
7568import org .eclipse .pde .internal .core .TargetPlatformHelper ;
7669import org .eclipse .pde .internal .core .bnd .PdeProjectAnalyzer ;
7770import org .eclipse .pde .internal .core .util .CoreUtility ;
7871import org .eclipse .pde .internal .core .util .VersionUtil ;
7972import org .eclipse .pde .internal .launching .IPDEConstants ;
73+ import org .eclipse .pde .internal .launching .JUnitLaunchRequirements ;
8074import org .eclipse .pde .internal .launching .PDELaunchingPlugin ;
8175import org .eclipse .pde .internal .launching .PDEMessages ;
8276import org .eclipse .pde .internal .launching .launcher .BundleLauncherHelper ;
@@ -393,18 +387,6 @@ protected String getApplication(ILaunchConfiguration configuration) {
393387 return application ;
394388 }
395389
396- private IPluginModelBase findRequiredPluginInTargetOrHost (String id ) throws CoreException {
397- IPluginModelBase model = PluginRegistry .findModel (id );
398- if (model == null || !model .getBundleDescription ().isResolved ()) {
399- // prefer bundle from host over unresolved bundle from target
400- model = PDECore .getDefault ().findPluginInHost (id ).max (Comparator .comparing (p -> p .getBundleDescription ().getVersion ())).orElse (null );
401- }
402- if (model == null ) {
403- abort (NLS .bind (PDEMessages .JUnitLaunchConfiguration_error_missingPlugin , id ), null , IStatus .OK );
404- }
405- return model ;
406- }
407-
408390 @ Override
409391 public String getProgramArguments (ILaunchConfiguration configuration ) throws CoreException {
410392 return LaunchArgumentsHelper .getUserProgramArguments (configuration );
@@ -537,7 +519,7 @@ protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch
537519 launchMode = launch .getLaunchMode ();
538520
539521 // implicitly add the plug-ins required for JUnit testing if necessary
540- addRequiredJunitRuntimePlugins (configuration );
522+ JUnitLaunchRequirements . addRequiredJunitRuntimePlugins (configuration , fAllBundles , fModels );
541523
542524 String attribute = launch .getAttribute (PDE_JUNIT_SHOW_COMMAND );
543525 boolean isShowCommand = false ;
@@ -558,58 +540,6 @@ protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch
558540 synchronizeManifests (configuration , subMonitor .split (1 ));
559541 }
560542
561- private void addRequiredJunitRuntimePlugins (ILaunchConfiguration configuration ) throws CoreException {
562- Set <String > requiredPlugins = new LinkedHashSet <>(getRequiredJunitRuntimePlugins (configuration ));
563-
564- if (fAllBundles .containsKey ("junit-platform-runner" ) || fAllBundles .containsKey ("org.junit.platform.runner" )) { //$NON-NLS-1$ //$NON-NLS-2$
565- // add launcher and jupiter.engine to support @RunWith(JUnitPlatform.class)
566- requiredPlugins .add ("junit-platform-launcher" ); //$NON-NLS-1$
567- requiredPlugins .add ("junit-jupiter-engine" ); //$NON-NLS-1$
568- }
569- Set <BundleDescription > addedRequirements = new HashSet <>();
570- addAbsentRequirements (requiredPlugins , addedRequirements );
571-
572- Set <BundleDescription > requirementsOfRequirements = DependencyManager .findRequirementsClosure (addedRequirements );
573- Set <String > rorIds = requirementsOfRequirements .stream ().map (BundleDescription ::getSymbolicName ).collect (Collectors .toSet ());
574- addAbsentRequirements (rorIds , null );
575- }
576-
577- private void addAbsentRequirements (Collection <String > requirements , Set <BundleDescription > addedRequirements ) throws CoreException {
578- for (String id : requirements ) {
579- List <IPluginModelBase > models = fAllBundles .computeIfAbsent (id , k -> new ArrayList <>());
580- if (models .stream ().noneMatch (m -> m .getBundleDescription ().isResolved ())) {
581- IPluginModelBase model = findRequiredPluginInTargetOrHost (id );
582- models .add (model );
583- BundleLauncherHelper .addDefaultStartingBundle (fModels , model );
584- if (addedRequirements != null ) {
585- addedRequirements .add (model .getBundleDescription ());
586- }
587- }
588- }
589- }
590-
591- /**
592- * @noreference This method is not intended to be referenced by clients.
593- * @param configuration non null config
594- * @return required plugins
595- */
596- @ SuppressWarnings ("restriction" )
597- public static Collection <String > getRequiredJunitRuntimePlugins (ILaunchConfiguration configuration ) {
598- org .eclipse .jdt .internal .junit .launcher .ITestKind testKind = org .eclipse .jdt .internal .junit .launcher .JUnitLaunchConfigurationConstants .getTestRunnerKind (configuration );
599- if (testKind .isNull ()) {
600- return Collections .emptyList ();
601- }
602- List <String > plugins = new ArrayList <>();
603- plugins .add ("org.eclipse.pde.junit.runtime" ); //$NON-NLS-1$
604-
605- if (org .eclipse .jdt .internal .junit .launcher .TestKindRegistry .JUNIT4_TEST_KIND_ID .equals (testKind .getId ())) {
606- plugins .add ("org.eclipse.jdt.junit4.runtime" ); //$NON-NLS-1$
607- } else if (org .eclipse .jdt .internal .junit .launcher .TestKindRegistry .JUNIT5_TEST_KIND_ID .equals (testKind .getId ())) {
608- plugins .add ("org.eclipse.jdt.junit5.runtime" ); //$NON-NLS-1$
609- }
610- return plugins ;
611- }
612-
613543 /**
614544 * Checks for old-style plugin.xml files that have become stale since the last launch.
615545 * For any stale plugin.xml files found, the corresponding MANIFEST.MF is deleted
0 commit comments