Skip to content

Commit 771099d

Browse files
author
Neha Burnwal
committed
Quick fix to add available matching version
1 parent 3807d8b commit 771099d

File tree

6 files changed

+68
-2
lines changed

6 files changed

+68
-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
@@ -1099,7 +1099,9 @@ private void validateBundleVersionAttribute(IHeader header, ManifestElement elem
10991099
int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_MISSING_VERSION_REQ_BUNDLE);
11001100
if (severity != CompilerFlags.IGNORE && versionRange == null) {
11011101
VirtualMarker marker = report(NLS.bind(PDECoreMessages.BundleErrorReporter_MissingVersion, element.getValue()),
1102-
getPackageLine(header, element), severity, PDEMarkerFactory.CAT_OTHER);
1102+
getPackageLine(header, element), severity, PDEMarkerFactory.M_MISSINGVERSION_REQ_BUNDLE,
1103+
PDEMarkerFactory.CAT_OTHER);
1104+
marker.setAttribute("bundleId", element.getValue()); //$NON-NLS-1$
11031105
addMarkerAttribute(marker,PDEMarkerFactory.compilerKey, CompilerFlags.P_MISSING_VERSION_REQ_BUNDLE);
11041106
}
11051107

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
@@ -76,6 +76,8 @@ public class PDEMarkerFactory {
7676
public static final int M_EXEC_ENV_TOO_LOW = 0x1029; // other problem
7777
public static final int M_CONFLICTING_AUTOMATIC_MODULE = 0x1030; // other
7878
// problem
79+
public static final int M_MISSINGVERSION_REQ_BUNDLE = 0x1031; // other
80+
// problem
7981

8082
// build properties fixes
8183
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
@@ -3425,5 +3425,6 @@ public class PDEUIMessages extends NLS {
34253425
public static String ProjectUpdateChange_convert_build_to_bnd;
34263426
public static String ProjectUpdateChange_set_pde_preference;
34273427

3428-
}
3428+
public static String AddMatchingVersion_RequireBundle;
34293429

3430+
}

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
@@ -147,6 +147,9 @@ public IMarkerResolution[] getNonConfigSevResolutions(IMarker marker) {
147147
case PDEMarkerFactory.M_CONFLICTING_AUTOMATIC_MODULE:
148148
return new IMarkerResolution[] {
149149
new RemoveRedundantAutomaticModuleHeader(AbstractPDEMarkerResolution.REMOVE_TYPE, marker) };
150+
case PDEMarkerFactory.M_MISSINGVERSION_REQ_BUNDLE:
151+
return new IMarkerResolution[] {
152+
new VersionMatchResolution(AbstractPDEMarkerResolution.CREATE_TYPE, marker) };
150153
}
151154
return NO_RESOLUTIONS;
152155
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
import org.eclipse.core.resources.IMarker;
17+
import org.eclipse.pde.core.plugin.IPluginModelBase;
18+
import org.eclipse.pde.core.plugin.PluginRegistry;
19+
import org.eclipse.pde.internal.core.text.bundle.Bundle;
20+
import org.eclipse.pde.internal.core.text.bundle.BundleModel;
21+
import org.eclipse.pde.internal.core.text.bundle.RequireBundleHeader;
22+
import org.eclipse.pde.internal.core.text.bundle.RequireBundleObject;
23+
import org.eclipse.pde.internal.core.util.VersionUtil;
24+
import org.eclipse.pde.internal.ui.PDEUIMessages;
25+
import org.osgi.framework.Constants;
26+
27+
public class VersionMatchResolution extends AbstractManifestMarkerResolution {
28+
public VersionMatchResolution(int type, IMarker marker) {
29+
super(type, marker);
30+
}
31+
32+
@Override
33+
protected void createChange(BundleModel model) {
34+
String bundleId = marker.getAttribute("bundleId", (String) null); //$NON-NLS-1$
35+
Bundle bundle = (Bundle) model.getBundle();
36+
RequireBundleHeader header = (RequireBundleHeader) bundle.getManifestHeader(Constants.REQUIRE_BUNDLE);
37+
if (header != null) {
38+
for (RequireBundleObject requiredBundle : header.getRequiredBundles()) {
39+
if (bundleId.equals(requiredBundle.getId())) {
40+
IPluginModelBase modelBase = PluginRegistry.findModel(bundleId);
41+
if (modelBase != null) {
42+
String version = modelBase.getPluginBase().getVersion();
43+
// Sanitize version: Remove a potential qualifier
44+
version = VersionUtil.computeInitialPluginVersion(version);
45+
requiredBundle.setVersion(version);
46+
}
47+
}
48+
}
49+
}
50+
}
51+
52+
@Override
53+
public String getLabel() {
54+
return PDEUIMessages.AddMatchingVersion_RequireBundle;
55+
}
56+
57+
}

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
@@ -1299,6 +1299,7 @@ UpdateClasspathResolution_label=Update the classpath and compliance settings
12991299
UpdateExecutionEnvironment_label=Update the execution environment based on JRE on the classpath
13001300
UpdateClasspathJob_task = Update classpaths...
13011301
UpdateClasspathJob_title = Updating Plug-in Classpaths
1302+
AddMatchingVersion_RequireBundle = Set latest available matching version
13021303

13031304
RuntimeWorkbenchShortcut_title=Select Configuration
13041305
RuntimeWorkbenchShortcut_select_debug=Select a launch configuration to debug:

0 commit comments

Comments
 (0)