Skip to content

Commit 09b7f61

Browse files
Neha BurnwalHannesWell
authored andcommitted
Add Quick fix to add version to required bundle
Fixes #1623
1 parent 66a95fd commit 09b7f61

File tree

6 files changed

+74
-2
lines changed

6 files changed

+74
-2
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,9 @@ private void validateBundleVersionAttribute(IHeader header, ManifestElement elem
11131113
int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_MISSING_VERSION_REQ_BUNDLE);
11141114
if (severity != CompilerFlags.IGNORE && versionRange == null) {
11151115
VirtualMarker marker = report(NLS.bind(PDECoreMessages.BundleErrorReporter_MissingVersion, element.getValue()),
1116-
getPackageLine(header, element), severity, PDEMarkerFactory.CAT_OTHER);
1116+
getPackageLine(header, element), severity, PDEMarkerFactory.M_MISSINGVERSION_REQ_BUNDLE,
1117+
PDEMarkerFactory.CAT_OTHER);
1118+
marker.setAttribute("bundleId", element.getValue()); //$NON-NLS-1$
11171119
addMarkerAttribute(marker,PDEMarkerFactory.compilerKey, CompilerFlags.P_MISSING_VERSION_REQ_BUNDLE);
11181120
}
11191121

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/PDEMarkerFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public class PDEMarkerFactory {
7777
public static final int M_CONFLICTING_AUTOMATIC_MODULE = 0x1030; // other problem
7878
public static final int M_HEADER_INCORRECT = 0x1031; // other problem
7979
public static final int M_SINGLETON_DIR_CHANGE = 0x1033; // other problem
80+
public static final int M_MISSINGVERSION_REQ_BUNDLE = 0x1034; // other
81+
// problem
8082

8183
// build properties fixes
8284
public static final int B_APPEND_SLASH_FOLDER_ENTRY = 0x2001;

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3438,5 +3438,6 @@ public class PDEUIMessages extends NLS {
34383438
public static String ProjectUpdateChange_convert_build_to_bnd;
34393439
public static String ProjectUpdateChange_set_pde_preference;
34403440

3441-
}
3441+
public static String AddMatchingVersion_RequireBundle;
34423442

3443+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ public IMarkerResolution[] getNonConfigSevResolutions(IMarker marker) {
152152
case PDEMarkerFactory.M_HEADER_INCORRECT:
153153
return new IMarkerResolution[] {
154154
new UpdateCorrectHeaderName(AbstractPDEMarkerResolution.RENAME_TYPE, marker) };
155+
case PDEMarkerFactory.M_MISSINGVERSION_REQ_BUNDLE:
156+
return new IMarkerResolution[] {
157+
new VersionMatchResolution(AbstractPDEMarkerResolution.CREATE_TYPE, marker) };
155158
}
156159
return NO_RESOLUTIONS;
157160
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025, 2025 IBM Corporation 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+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
15+
package org.eclipse.pde.internal.ui.correction;
16+
17+
import java.util.Objects;
18+
19+
import org.eclipse.core.resources.IMarker;
20+
import org.eclipse.pde.core.plugin.IPluginModelBase;
21+
import org.eclipse.pde.core.plugin.PluginRegistry;
22+
import org.eclipse.pde.internal.core.text.bundle.Bundle;
23+
import org.eclipse.pde.internal.core.text.bundle.BundleModel;
24+
import org.eclipse.pde.internal.core.text.bundle.RequireBundleHeader;
25+
import org.eclipse.pde.internal.core.text.bundle.RequireBundleObject;
26+
import org.eclipse.pde.internal.core.util.VersionUtil;
27+
import org.eclipse.pde.internal.ui.PDEUIMessages;
28+
import org.osgi.framework.Constants;
29+
30+
/**
31+
* Resolution to add available matching version for Required bundles in MANIFEST
32+
*/
33+
public class VersionMatchResolution extends AbstractManifestMarkerResolution {
34+
public VersionMatchResolution(int type, IMarker marker) {
35+
super(type, marker);
36+
}
37+
38+
@Override
39+
protected void createChange(BundleModel model) {
40+
String bundleId = Objects.requireNonNull(marker.getAttribute("bundleId", (String) null)); //$NON-NLS-1$
41+
Bundle bundle = (Bundle) model.getBundle();
42+
RequireBundleHeader header = (RequireBundleHeader) bundle.getManifestHeader(Constants.REQUIRE_BUNDLE);
43+
if (header != null) {
44+
for (RequireBundleObject requiredBundle : header.getRequiredBundles()) {
45+
if (bundleId.equals(requiredBundle.getId())) {
46+
IPluginModelBase modelBase = PluginRegistry.findModel(bundleId);
47+
if (modelBase != null) {
48+
String version = modelBase.getPluginBase().getVersion();
49+
// Sanitize version: Remove a potential qualifier
50+
version = VersionUtil.computeInitialPluginVersion(version);
51+
requiredBundle.setVersion(version);
52+
}
53+
}
54+
}
55+
}
56+
}
57+
58+
@Override
59+
public String getLabel() {
60+
return PDEUIMessages.AddMatchingVersion_RequireBundle;
61+
}
62+
63+
}

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,7 @@ UpdateClasspathResolution_label=Update the classpath and compliance settings
13011301
UpdateExecutionEnvironment_label=Update the execution environment based on JRE on the classpath
13021302
UpdateClasspathJob_task = Update classpaths...
13031303
UpdateClasspathJob_title = Updating Plug-in Classpaths
1304+
AddMatchingVersion_RequireBundle = Require latest available version
13041305

13051306
RuntimeWorkbenchShortcut_title=Select Configuration
13061307
RuntimeWorkbenchShortcut_select_debug=Select a launch configuration to debug:

0 commit comments

Comments
 (0)