-
Notifications
You must be signed in to change notification settings - Fork 126
Quick fix to add available matching version for Imported packages #1962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
noopur2507
merged 1 commit into
eclipse-pde:master
from
nburnwal09:quickFix_verMatch_import_package
Apr 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...de.ui/src/org/eclipse/pde/internal/ui/correction/VersionMatchImportPackageResolution.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025, 2025 IBM Corporation and others. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * IBM Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
|
|
||
| package org.eclipse.pde.internal.ui.correction; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| import org.eclipse.core.resources.IMarker; | ||
| import org.eclipse.osgi.service.resolver.BundleDescription; | ||
| import org.eclipse.osgi.service.resolver.ExportPackageDescription; | ||
| import org.eclipse.pde.core.plugin.IPluginModelBase; | ||
| import org.eclipse.pde.core.plugin.PluginRegistry; | ||
| import org.eclipse.pde.internal.core.text.bundle.Bundle; | ||
| import org.eclipse.pde.internal.core.text.bundle.BundleModel; | ||
| import org.eclipse.pde.internal.core.text.bundle.ImportPackageHeader; | ||
| import org.eclipse.pde.internal.core.text.bundle.ImportPackageObject; | ||
| import org.eclipse.pde.internal.core.util.VersionUtil; | ||
| import org.eclipse.pde.internal.ui.PDEUIMessages; | ||
| import org.osgi.framework.Constants; | ||
| import org.osgi.framework.Version; | ||
| import org.osgi.framework.VersionRange; | ||
|
|
||
| /** | ||
| * Resolution to add available matching version for Imported package in MANIFEST | ||
| */ | ||
| public class VersionMatchImportPackageResolution extends AbstractManifestMarkerResolution { | ||
|
|
||
| public VersionMatchImportPackageResolution(int type, IMarker marker) { | ||
| super(type, marker); | ||
| } | ||
|
|
||
| public Version getVersion(Object inputElement) { | ||
| IPluginModelBase[] models = PluginRegistry.getActiveModels(); | ||
| Version highest = null; | ||
| for (IPluginModelBase pluginModel : models) { | ||
| BundleDescription desc = pluginModel.getBundleDescription(); | ||
|
|
||
| String id = desc == null ? null : desc.getSymbolicName(); | ||
| if (id == null) { | ||
| continue; | ||
| } | ||
| ExportPackageDescription[] exported = desc.getExportPackages(); | ||
| for (ExportPackageDescription exportedPackage : exported) { | ||
| String name = exportedPackage.getName(); | ||
| if (("java".equals(name) || name.startsWith("java."))) { //$NON-NLS-1$ //$NON-NLS-2$ | ||
| // $NON-NLS-2$ | ||
| continue; | ||
| } | ||
| if (name.equals(inputElement.toString())) { | ||
| Version ver = exportedPackage.getVersion(); | ||
| if (ver != null) { | ||
| if (highest == null || ver.compareTo(highest) > 0) { | ||
| highest = ver; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return highest; | ||
| } | ||
|
|
||
| @Override | ||
| protected void createChange(BundleModel model) { | ||
| String pkgName = Objects.requireNonNull(marker.getAttribute("pkgName", (String) null)); //$NON-NLS-1$ | ||
| Bundle bundle = (Bundle) model.getBundle(); | ||
| ImportPackageHeader header = (ImportPackageHeader) bundle.getManifestHeader(Constants.IMPORT_PACKAGE); | ||
| if (header != null) { | ||
| for (ImportPackageObject importPackage : header.getPackages()) { | ||
| if (pkgName.equals(importPackage.getName())) { | ||
| Version version = getVersion(pkgName); | ||
| if (version == null) { | ||
| return; | ||
| } | ||
| // Sanitize version: Remove a potential qualifier | ||
| Optional<VersionRange> versionRange = VersionUtil.createConsumerRequirementRange(version); | ||
| importPackage.setVersion(versionRange.map(VersionRange::toString).orElse(null)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getLabel() { | ||
| return PDEUIMessages.AddMatchingVersion; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return PDEUIMessages.AddMatchingVersionDescription; | ||
| } | ||
|
|
||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this parameter be of type String instead of Object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
versionRange is calculated based on version object(in line 79). If we change the type to string, we will have to change the type again there.