Skip to content

Commit 8a1fa96

Browse files
eclipse-pde-bottrancexpress
authored andcommitted
Version bump(s) for 4.38 stream
1 parent d35054f commit 8a1fa96

File tree

6 files changed

+171
-218
lines changed

6 files changed

+171
-218
lines changed

features/org.eclipse.pde.unittest.junit-feature/feature.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<feature
33
id="org.eclipse.pde.unittest.junit"
44
label="%featureName"
5-
version="1.0.1100.qualifier"
5+
version="1.0.1200.qualifier"
66
provider-name="%providerName"
77
license-feature="org.eclipse.license"
88
license-feature-version="0.0.0">
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Advantest and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Advantest - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.pde.internal.launching;
15+
16+
import java.util.ArrayList;
17+
import java.util.Collection;
18+
import java.util.Collections;
19+
import java.util.LinkedHashSet;
20+
import java.util.List;
21+
import java.util.Map;
22+
import java.util.Set;
23+
import java.util.function.Supplier;
24+
25+
import org.eclipse.core.runtime.CoreException;
26+
import org.eclipse.core.runtime.IStatus;
27+
import org.eclipse.core.runtime.Status;
28+
import org.eclipse.debug.core.ILaunchConfiguration;
29+
import org.eclipse.osgi.service.resolver.BundleDescription;
30+
import org.eclipse.osgi.util.NLS;
31+
import org.eclipse.pde.core.plugin.IPluginModelBase;
32+
import org.eclipse.pde.core.plugin.PluginRegistry;
33+
import org.eclipse.pde.internal.core.DependencyManager;
34+
import org.eclipse.pde.internal.core.PDECore;
35+
import org.eclipse.pde.internal.launching.launcher.BundleLauncherHelper;
36+
import org.osgi.framework.VersionRange;
37+
38+
public class JUnitLaunchRequirements {
39+
40+
public static final String JUNIT4_RUNTIME_PLUGIN = "org.eclipse.jdt.junit4.runtime"; //$NON-NLS-1$
41+
public static final String JUNIT5_RUNTIME_PLUGIN = "org.eclipse.jdt.junit5.runtime"; //$NON-NLS-1$
42+
43+
private static final VersionRange JUNIT5_VERSIONS = new VersionRange("[1, 5)"); //$NON-NLS-1$
44+
45+
public static void addRequiredJunitRuntimePlugins(ILaunchConfiguration configuration, Map<String, List<IPluginModelBase>> allBundles, Map<IPluginModelBase, String> allModels) throws CoreException {
46+
Collection<String> plugins = getRequiredJunitRuntimePlugins(configuration);
47+
addPlugins(plugins, allBundles, allModels);
48+
if (plugins.contains(JUNIT5_RUNTIME_PLUGIN) && (allBundles.containsKey("junit-platform-runner") || allBundles.containsKey("org.junit.platform.runner"))) { //$NON-NLS-1$ //$NON-NLS-2$
49+
Set<BundleDescription> descriptions = JUnitLaunchRequirements.junit5PlatformRequirements();
50+
Set<BundleDescription> junitRquirements = DependencyManager.findRequirementsClosure(descriptions);
51+
addAbsentRequirements(junitRquirements, allBundles, allModels);
52+
}
53+
}
54+
55+
@SuppressWarnings("restriction")
56+
public static Collection<String> getRequiredJunitRuntimePlugins(ILaunchConfiguration configuration) {
57+
org.eclipse.jdt.internal.junit.launcher.ITestKind testKind = org.eclipse.jdt.internal.junit.launcher.JUnitLaunchConfigurationConstants.getTestRunnerKind(configuration);
58+
if (testKind.isNull()) {
59+
return Collections.emptyList();
60+
}
61+
List<String> plugins = new ArrayList<>();
62+
plugins.add("org.eclipse.pde.junit.runtime"); //$NON-NLS-1$
63+
64+
if (org.eclipse.jdt.internal.junit.launcher.TestKindRegistry.JUNIT4_TEST_KIND_ID.equals(testKind.getId())) {
65+
plugins.add(JUNIT4_RUNTIME_PLUGIN);
66+
} else if (org.eclipse.jdt.internal.junit.launcher.TestKindRegistry.JUNIT5_TEST_KIND_ID.equals(testKind.getId())) {
67+
plugins.add(JUNIT5_RUNTIME_PLUGIN);
68+
}
69+
return plugins;
70+
}
71+
72+
private static void addPlugins(Collection<String> plugins, Map<String, List<IPluginModelBase>> allBundles, Map<IPluginModelBase, String> allModels) throws CoreException {
73+
Set<String> requiredPlugins = new LinkedHashSet<>(plugins);
74+
75+
Set<BundleDescription> addedRequirements = new LinkedHashSet<>();
76+
addAbsentRequirements(requiredPlugins, addedRequirements, allBundles, allModels);
77+
78+
Set<BundleDescription> requirementsOfRequirements = DependencyManager.findRequirementsClosure(addedRequirements);
79+
addAbsentRequirements(requirementsOfRequirements, allBundles, allModels);
80+
}
81+
82+
private static void addAbsentRequirements(Collection<String> requirements, Set<BundleDescription> addedRequirements, Map<String, List<IPluginModelBase>> allBundles, Map<IPluginModelBase, String> allModels) throws CoreException {
83+
for (String id : requirements) {
84+
List<IPluginModelBase> models = allBundles.computeIfAbsent(id, k -> new ArrayList<>());
85+
if (models.stream().noneMatch(m -> m.getBundleDescription().isResolved())) {
86+
IPluginModelBase model = JUnitLaunchRequirements.findRequiredPluginInTargetOrHost(id);
87+
models.add(model);
88+
BundleLauncherHelper.addDefaultStartingBundle(allModels, model);
89+
if (addedRequirements != null) {
90+
addedRequirements.add(model.getBundleDescription());
91+
}
92+
}
93+
}
94+
}
95+
96+
private static void addAbsentRequirements(Set<BundleDescription> toAdd, Map<String, List<IPluginModelBase>> allBundles, Map<IPluginModelBase, String> allModels) throws CoreException {
97+
for (BundleDescription requirement : toAdd) {
98+
String id = requirement.getSymbolicName();
99+
List<IPluginModelBase> models = allBundles.computeIfAbsent(id, k -> new ArrayList<>());
100+
boolean replace = !models.isEmpty() && models.stream().noneMatch(m -> m.getBundleDescription().getVersion().equals(requirement.getVersion()));
101+
if (replace || models.stream().noneMatch(m -> m.getBundleDescription().isResolved())) {
102+
IPluginModelBase model = JUnitLaunchRequirements.findRequiredPluginInTargetOrHost(requirement);
103+
if (replace) {
104+
String startLevel = null;
105+
for (IPluginModelBase m : models) {
106+
startLevel = allModels.remove(m);
107+
}
108+
models.clear();
109+
allModels.put(model, startLevel);
110+
}
111+
models.add(model);
112+
BundleLauncherHelper.addDefaultStartingBundle(allModels, model);
113+
}
114+
}
115+
}
116+
117+
public static Set<BundleDescription> junit5PlatformRequirements() throws CoreException {
118+
// add launcher and jupiter.engine to support @RunWith(JUnitPlatform.class)
119+
String[] requiredPlugins = {"junit-platform-launcher", //$NON-NLS-1$
120+
"junit-jupiter-engine", //$NON-NLS-1$
121+
};
122+
Set<BundleDescription> descriptions = new LinkedHashSet<>();
123+
for (String id : requiredPlugins) {
124+
IPluginModelBase model = findRequiredPluginInTargetOrHost(id, JUNIT5_VERSIONS);
125+
if (model != null) {
126+
BundleDescription description = model.getBundleDescription();
127+
descriptions.add(description);
128+
}
129+
}
130+
return descriptions;
131+
}
132+
133+
public static IPluginModelBase findRequiredPluginInTargetOrHost(String id) throws CoreException {
134+
IPluginModelBase model = findRequiredPluginInTargetOrHost(id, () -> PluginRegistry.findModel(id));
135+
return model;
136+
}
137+
138+
private static IPluginModelBase findRequiredPluginInTargetOrHost(String id, VersionRange versionRange) throws CoreException {
139+
IPluginModelBase model = findRequiredPluginInTargetOrHost(id, () -> PluginRegistry.findModel(id, versionRange));
140+
return model;
141+
}
142+
143+
public static IPluginModelBase findRequiredPluginInTargetOrHost(BundleDescription bundleDescription) throws CoreException {
144+
String id = bundleDescription.getSymbolicName();
145+
IPluginModelBase model = findRequiredPluginInTargetOrHost(id, () -> PluginRegistry.findModel((org.osgi.resource.Resource) bundleDescription));
146+
return model;
147+
}
148+
149+
private static IPluginModelBase findRequiredPluginInTargetOrHost(String id, Supplier<IPluginModelBase> findModel) throws CoreException {
150+
IPluginModelBase model = findModel.get();
151+
if (model == null || !model.getBundleDescription().isResolved()) {
152+
// prefer bundle from host over unresolved bundle from target
153+
model = PDECore.getDefault().findPluginInHost(id);
154+
}
155+
if (model == null) {
156+
String message = NLS.bind(PDEMessages.JUnitLaunchConfiguration_error_missingPlugin, id);
157+
Status error = new Status(IStatus.ERROR, IPDEConstants.PLUGIN_ID, IStatus.OK, message, null);
158+
throw new CoreException(error);
159+
}
160+
return model;
161+
}
162+
163+
}

ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/JUnitLaunchConfigurationDelegate.java

Lines changed: 2 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@
2424
import java.nio.file.Path;
2525
import java.util.ArrayList;
2626
import java.util.Arrays;
27-
import java.util.Collection;
2827
import java.util.Collections;
2928
import java.util.Comparator;
3029
import java.util.LinkedHashMap;
31-
import java.util.LinkedHashSet;
3230
import java.util.List;
3331
import java.util.Map;
3432
import java.util.Properties;
35-
import java.util.Set;
36-
import java.util.function.Supplier;
3733
import java.util.jar.JarOutputStream;
3834
import java.util.jar.Manifest;
3935
import java.util.stream.Collectors;
@@ -58,7 +54,6 @@
5854
import org.eclipse.jdt.launching.IVMInstall;
5955
import org.eclipse.jdt.launching.IVMRunner;
6056
import org.eclipse.jdt.launching.JavaRuntime;
61-
import org.eclipse.osgi.service.resolver.BundleDescription;
6257
import org.eclipse.osgi.util.ManifestElement;
6358
import org.eclipse.osgi.util.NLS;
6459
import org.eclipse.pde.core.plugin.IFragment;
@@ -69,14 +64,13 @@
6964
import org.eclipse.pde.core.plugin.TargetPlatform;
7065
import org.eclipse.pde.internal.build.IPDEBuildConstants;
7166
import org.eclipse.pde.internal.core.ClasspathHelper;
72-
import org.eclipse.pde.internal.core.DependencyManager;
7367
import org.eclipse.pde.internal.core.ICoreConstants;
74-
import org.eclipse.pde.internal.core.PDECore;
7568
import org.eclipse.pde.internal.core.TargetPlatformHelper;
7669
import org.eclipse.pde.internal.core.bnd.PdeProjectAnalyzer;
7770
import org.eclipse.pde.internal.core.util.CoreUtility;
7871
import org.eclipse.pde.internal.core.util.VersionUtil;
7972
import org.eclipse.pde.internal.launching.IPDEConstants;
73+
import org.eclipse.pde.internal.launching.JUnitLaunchRequirements;
8074
import org.eclipse.pde.internal.launching.PDELaunchingPlugin;
8175
import org.eclipse.pde.internal.launching.PDEMessages;
8276
import org.eclipse.pde.internal.launching.launcher.BundleLauncherHelper;
@@ -88,7 +82,6 @@
8882
import org.eclipse.pde.internal.launching.launcher.RequirementHelper;
8983
import org.eclipse.pde.internal.launching.launcher.VMHelper;
9084
import org.osgi.framework.Constants;
91-
import org.osgi.framework.VersionRange;
9285

9386
/**
9487
* A launch delegate for launching JUnit Plug-in tests.
@@ -100,11 +93,6 @@
10093
*/
10194
public class JUnitLaunchConfigurationDelegate extends org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate {
10295

103-
public static final String JUNIT4_RUNTIME_PLUGIN = "org.eclipse.jdt.junit4.runtime"; //$NON-NLS-1$
104-
public static final String JUNIT5_RUNTIME_PLUGIN = "org.eclipse.jdt.junit5.runtime"; //$NON-NLS-1$
105-
106-
private static final VersionRange JUNIT5_VERSIONS = new VersionRange("[1, 5)"); //$NON-NLS-1$
107-
10896
static {
10997
RequirementHelper.registerLaunchTypeRequirements("org.eclipse.pde.ui.JunitLaunchConfig", lc -> { //$NON-NLS-1$
11098
// Junit launch configs can have the core test application set in either the 'app to test' or the 'application' attribute
@@ -399,36 +387,6 @@ protected String getApplication(ILaunchConfiguration configuration) {
399387
return application;
400388
}
401389

402-
private static IPluginModelBase findRequiredPluginInTargetOrHost(String id) throws CoreException {
403-
IPluginModelBase model = findRequiredPluginInTargetOrHost(id, () -> PluginRegistry.findModel(id));
404-
return model;
405-
}
406-
407-
private static IPluginModelBase findRequiredPluginInTargetOrHost(String id, VersionRange versionRange) throws CoreException {
408-
IPluginModelBase model = findRequiredPluginInTargetOrHost(id, () -> PluginRegistry.findModel(id, versionRange));
409-
return model;
410-
}
411-
412-
private static IPluginModelBase findRequiredPluginInTargetOrHost(BundleDescription bundleDescription) throws CoreException {
413-
String id = bundleDescription.getSymbolicName();
414-
IPluginModelBase model = findRequiredPluginInTargetOrHost(id, () -> PluginRegistry.findModel((org.osgi.resource.Resource) bundleDescription));
415-
return model;
416-
}
417-
418-
private static IPluginModelBase findRequiredPluginInTargetOrHost(String id, Supplier<IPluginModelBase> findModel) throws CoreException {
419-
IPluginModelBase model = findModel.get();
420-
if (model == null || !model.getBundleDescription().isResolved()) {
421-
// prefer bundle from host over unresolved bundle from target
422-
model = PDECore.getDefault().findPluginInHost(id);
423-
}
424-
if (model == null) {
425-
String message = NLS.bind(PDEMessages.JUnitLaunchConfiguration_error_missingPlugin, id);
426-
Status error = new Status(IStatus.ERROR, IPDEConstants.PLUGIN_ID, IStatus.OK, message, null);
427-
throw new CoreException(error);
428-
}
429-
return model;
430-
}
431-
432390
@Override
433391
public String getProgramArguments(ILaunchConfiguration configuration) throws CoreException {
434392
return LaunchArgumentsHelper.getUserProgramArguments(configuration);
@@ -561,7 +519,7 @@ protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch
561519
launchMode = launch.getLaunchMode();
562520

563521
// implicitly add the plug-ins required for JUnit testing if necessary
564-
addRequiredJunitRuntimePlugins(configuration);
522+
JUnitLaunchRequirements.addRequiredJunitRuntimePlugins(configuration, fAllBundles, fModels);
565523

566524
String attribute = launch.getAttribute(PDE_JUNIT_SHOW_COMMAND);
567525
boolean isShowCommand = false;
@@ -582,96 +540,6 @@ protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch
582540
synchronizeManifests(configuration, subMonitor.split(1));
583541
}
584542

585-
private void addRequiredJunitRuntimePlugins(ILaunchConfiguration configuration) throws CoreException {
586-
Collection<String> plugins = getRequiredJunitRuntimePlugins(configuration);
587-
addPlugins(plugins);
588-
if (plugins.contains(JUNIT5_RUNTIME_PLUGIN) &&
589-
(fAllBundles.containsKey("junit-platform-runner") || fAllBundles.containsKey("org.junit.platform.runner"))) { //$NON-NLS-1$ //$NON-NLS-2$
590-
Set<BundleDescription> descriptions = junit5PlatformRequirements();
591-
Set<BundleDescription> junitRquirements = DependencyManager.findRequirementsClosure(descriptions);
592-
addAbsentRequirements(junitRquirements);
593-
}
594-
}
595-
596-
/**
597-
* @noreference This method is not intended to be referenced by clients.
598-
* @return plugins required by JUnit 5 platform bundle
599-
*/
600-
public static Set<BundleDescription> junit5PlatformRequirements() throws CoreException {
601-
// add launcher and jupiter.engine to support @RunWith(JUnitPlatform.class)
602-
String[] requiredPlugins = {
603-
"junit-platform-launcher", //$NON-NLS-1$
604-
"junit-jupiter-engine", //$NON-NLS-1$
605-
};
606-
Set<BundleDescription> descriptions = new LinkedHashSet<>();
607-
for (String id : requiredPlugins) {
608-
IPluginModelBase model = findRequiredPluginInTargetOrHost(id, JUNIT5_VERSIONS);
609-
if (model != null) {
610-
BundleDescription description = model.getBundleDescription();
611-
descriptions.add(description);
612-
}
613-
}
614-
return descriptions;
615-
}
616-
617-
private void addPlugins(Collection<String> plugins) throws CoreException {
618-
Set<String> requiredPlugins = new LinkedHashSet<>(plugins);
619-
620-
Set<BundleDescription> addedRequirements = new LinkedHashSet<>();
621-
addAbsentRequirements(requiredPlugins, addedRequirements);
622-
623-
Set<BundleDescription> requirementsOfRequirements = DependencyManager.findRequirementsClosure(addedRequirements);
624-
addAbsentRequirements(requirementsOfRequirements);
625-
}
626-
627-
private void addAbsentRequirements(Collection<String> requirements, Set<BundleDescription> addedRequirements) throws CoreException {
628-
for (String id : requirements) {
629-
List<IPluginModelBase> models = fAllBundles.computeIfAbsent(id, k -> new ArrayList<>());
630-
if (models.stream().noneMatch(m -> m.getBundleDescription().isResolved())) {
631-
IPluginModelBase model = findRequiredPluginInTargetOrHost(id);
632-
models.add(model);
633-
BundleLauncherHelper.addDefaultStartingBundle(fModels, model);
634-
if (addedRequirements != null) {
635-
addedRequirements.add(model.getBundleDescription());
636-
}
637-
}
638-
}
639-
}
640-
641-
private void addAbsentRequirements(Set<BundleDescription> toAdd) throws CoreException {
642-
for (BundleDescription requirement : toAdd) {
643-
String id = requirement.getSymbolicName();
644-
List<IPluginModelBase> models = fAllBundles.computeIfAbsent(id, k -> new ArrayList<>());
645-
if (models.stream().noneMatch(m -> m.getBundleDescription().isResolved())) {
646-
IPluginModelBase model = findRequiredPluginInTargetOrHost(requirement);
647-
models.add(model);
648-
BundleLauncherHelper.addDefaultStartingBundle(fModels, model);
649-
}
650-
}
651-
}
652-
653-
/**
654-
* @noreference This method is not intended to be referenced by clients.
655-
* @param configuration non null config
656-
* @return required plugins
657-
*/
658-
@SuppressWarnings("restriction")
659-
public static Collection<String> getRequiredJunitRuntimePlugins(ILaunchConfiguration configuration) {
660-
org.eclipse.jdt.internal.junit.launcher.ITestKind testKind = org.eclipse.jdt.internal.junit.launcher.JUnitLaunchConfigurationConstants.getTestRunnerKind(configuration);
661-
if (testKind.isNull()) {
662-
return Collections.emptyList();
663-
}
664-
List<String> plugins = new ArrayList<>();
665-
plugins.add("org.eclipse.pde.junit.runtime"); //$NON-NLS-1$
666-
667-
if (org.eclipse.jdt.internal.junit.launcher.TestKindRegistry.JUNIT4_TEST_KIND_ID.equals(testKind.getId())) {
668-
plugins.add(JUNIT4_RUNTIME_PLUGIN);
669-
} else if (org.eclipse.jdt.internal.junit.launcher.TestKindRegistry.JUNIT5_TEST_KIND_ID.equals(testKind.getId())) {
670-
plugins.add(JUNIT5_RUNTIME_PLUGIN);
671-
}
672-
return plugins;
673-
}
674-
675543
/**
676544
* Checks for old-style plugin.xml files that have become stale since the last launch.
677545
* For any stale plugin.xml files found, the corresponding MANIFEST.MF is deleted

0 commit comments

Comments
 (0)