Skip to content

Commit c7418b3

Browse files
committed
Restrict junit-jupiter-api version to [5,6) when adding JUnit 5 bundle
requirements Fixes: #2051
1 parent 98f11cb commit c7418b3

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/JavaResolutionFactory.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ public void initializeValidationData(IProgressMonitor pm) {
180180
*/
181181
private static class RequireBundleManifestChange extends AbstractManifestChange {
182182

183+
private static final String ADD_JUNIT5_BUNDLES_DESCRIPTION = "JUnit 5 bundles"; //$NON-NLS-1$
184+
private static final String JUNIT_JUPITER_API = "junit-jupiter-api"; //$NON-NLS-1$
185+
183186
private RequireBundleManifestChange(IProject project, ExportPackageDescription desc, CompilationUnit cu,
184187
String qualifiedTypeToImport) {
185188
super(project, desc, cu, qualifiedTypeToImport);
@@ -198,13 +201,20 @@ protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws Co
198201
if (!(model instanceof IPluginModelBase base)) {
199202
return;
200203
}
201-
String[] pluginIdStrings = null;
202-
if ("JUnit 5 bundles".equals(getChangeObject())) { //$NON-NLS-1$
203-
pluginIdStrings = getJUnit5Bundles();
204+
Object changeObject = getChangeObject();
205+
String[] pluginIdStrings = {};
206+
String version = null;
207+
if (changeObject instanceof String changeString) {
208+
switch (changeString) {
209+
case ADD_JUNIT5_BUNDLES_DESCRIPTION -> {
210+
pluginIdStrings = getJUnit5Bundles();
211+
version = "[5.0.0,6.0.0)"; //$NON-NLS-1$
212+
}
213+
}
204214
}
205-
if (getChangeObject() instanceof ExportPackageDescription) {
215+
if (changeObject instanceof ExportPackageDescription) {
206216
pluginIdStrings = new String[1];
207-
pluginIdStrings[0] = ((ExportPackageDescription) getChangeObject()).getSupplier()
217+
pluginIdStrings[0] = ((ExportPackageDescription) changeObject).getSupplier()
208218
.getSymbolicName();
209219
}
210220
for (int i = 0; i < pluginIdStrings.length; i++) {
@@ -222,6 +232,9 @@ protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws Co
222232
continue;
223233
}
224234
IPluginImport impt = base.getPluginFactory().createImport();
235+
if (version != null && JUNIT_JUPITER_API.equals(pluginId)) {
236+
impt.setVersion(version);
237+
}
225238
impt.setId(pluginId);
226239
base.getPluginBase().add(impt);
227240
} else {
@@ -236,7 +249,7 @@ protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws Co
236249
}
237250

238251
private String[] getJUnit5Bundles() {
239-
return new String[] { "org.junit", "junit-jupiter-api" }; //$NON-NLS-1$ //$NON-NLS-2$
252+
return new String[] { "org.junit", JUNIT_JUPITER_API }; //$NON-NLS-1$
240253
}
241254
}, new NullProgressMonitor());
242255

0 commit comments

Comments
 (0)