From d34e795e05ef52e0292d6e56ee08cd6134a2e005 Mon Sep 17 00:00:00 2001 From: Alshama M S Date: Thu, 14 Dec 2023 18:36:14 +0530 Subject: [PATCH] Strip micro-version while importing packages This commit resets the micro-version to '0' while importing packages as part of quick fix, as it is not relevant. Fixes https://github.com/eclipse-pde/eclipse.pde/issues/401 Co-authored-by: Hannes Wellmann --- .../core/text/bundle/ImportPackageObject.java | 8 +++++--- .../correction/java/JavaResolutionFactory.java | 16 +++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/ImportPackageObject.java b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/ImportPackageObject.java index 150eeaad172..245702e19d5 100644 --- a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/ImportPackageObject.java +++ b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/ImportPackageObject.java @@ -32,9 +32,11 @@ public class ImportPackageObject extends PackageObject { private static final long serialVersionUID = 1L; private static String getVersion(ExportPackageDescription desc) { - String version = desc.getVersion().toString(); - if (!version.equals(Version.emptyVersion.toString())) { - return desc.getVersion().toString(); + Version version = desc.getVersion(); + if (version != null && !Version.emptyVersion.equals(version)) { + return new VersionRange( + "[" + version.getMajor() + "." + version.getMinor() + "," + (version.getMajor() + 1) + "]") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$ + .toString(); } return null; } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/JavaResolutionFactory.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/JavaResolutionFactory.java index b2b9c196b82..5ef062efcf9 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/JavaResolutionFactory.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/JavaResolutionFactory.java @@ -49,7 +49,6 @@ import org.eclipse.pde.internal.core.text.bundle.ExportPackageObject; import org.eclipse.pde.internal.core.text.bundle.ImportPackageHeader; import org.eclipse.pde.internal.core.text.bundle.ImportPackageObject; -import org.eclipse.pde.internal.core.text.bundle.ManifestHeader; import org.eclipse.pde.internal.ui.PDEPlugin; import org.eclipse.pde.internal.ui.PDEPluginImages; import org.eclipse.pde.internal.ui.PDEUIMessages; @@ -321,14 +320,17 @@ protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws Co if (!(model instanceof IBundlePluginModelBase base)) return; IBundle bundle = base.getBundleModel().getBundle(); - String pkgId = ((ExportPackageDescription) getChangeObject()).getName(); + ExportPackageDescription desc = (ExportPackageDescription) getChangeObject(); + String pkgId = desc.getName(); IManifestHeader header = bundle.getManifestHeader(Constants.IMPORT_PACKAGE); if (header == null) { - bundle.setHeader(Constants.IMPORT_PACKAGE, pkgId); - } else if (header instanceof ImportPackageHeader ipHeader) { - int manifestVersion = BundlePluginBase.getBundleManifestVersion(bundle); - String versionAttr = (manifestVersion < 2) ? ICoreConstants.PACKAGE_SPECIFICATION_VERSION : Constants.VERSION_ATTRIBUTE; - ImportPackageObject impObject = new ImportPackageObject((ManifestHeader) header, (ExportPackageDescription) getChangeObject(), versionAttr); + header = bundle.getModel().getFactory().createHeader(Constants.IMPORT_PACKAGE, pkgId); + } + if (header instanceof ImportPackageHeader ipHeader) { + String versionAttr = (BundlePluginBase.getBundleManifestVersion(bundle) < 2) + ? ICoreConstants.PACKAGE_SPECIFICATION_VERSION + : Constants.VERSION_ATTRIBUTE; + ImportPackageObject impObject = new ImportPackageObject(ipHeader, desc, versionAttr); if (!isUndo()) { ipHeader.addPackage(impObject); } else {