Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/org.eclipse.pde.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %name
Bundle-SymbolicName: org.eclipse.pde.core; singleton:=true
Bundle-Version: 3.21.100.qualifier
Bundle-Version: 3.21.200.qualifier
Bundle-Activator: org.eclipse.pde.internal.core.PDECore
Bundle-Vendor: %provider-name
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,11 @@ private void validateImportPackageVersion(IHeader header, ManifestElement elemen
String version = element.getAttribute(Constants.VERSION_ATTRIBUTE);
int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_MISSING_VERSION_IMP_PKG);
if (severity != CompilerFlags.IGNORE && version == null) {
VirtualMarker marker = report(NLS.bind(PDECoreMessages.BundleErrorReporter_MissingVersion, element.getValue()), getPackageLine(header, element), severity, PDEMarkerFactory.CAT_OTHER);
VirtualMarker marker = report(
NLS.bind(PDECoreMessages.BundleErrorReporter_MissingVersion, element.getValue()),
getPackageLine(header, element), severity, PDEMarkerFactory.M_MISSINGVERSION_IMPORT_PACKAGE,
PDEMarkerFactory.CAT_OTHER);
marker.setAttribute("bundleId", element.getValue()); //$NON-NLS-1$
addMarkerAttribute(marker,PDEMarkerFactory.compilerKey, CompilerFlags.P_MISSING_VERSION_IMP_PKG);
}
validateVersionAttribute(header, element, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class PDEMarkerFactory {
public static final int M_SINGLETON_DIR_CHANGE = 0x1033; // other problem
public static final int M_MISSINGVERSION_REQ_BUNDLE = 0x1034; // other
// problem
public static final int M_MISSINGVERSION_IMPORT_PACKAGE = 0x1035; // other
// problem

// build properties fixes
public static final int B_APPEND_SLASH_FOLDER_ENTRY = 0x2001;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -67,8 +66,6 @@
import org.osgi.framework.Filter;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;
import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
import org.osgi.resource.Namespace;
import org.osgi.resource.Requirement;
Expand Down Expand Up @@ -399,16 +396,6 @@ public static void parseRequiredEEsFromFilter(String eeFilter, Consumer<String>
}
}

public static Optional<VersionRange> createConsumerRequirementRange(Version version) {
if (version != null && !Version.emptyVersion.equals(version)) {
return Optional.ofNullable(new VersionRange(VersionRange.LEFT_CLOSED, //
new Version(version.getMajor(), version.getMinor(), 0), //
new Version(version.getMajor() + 1, 0, 0), //
VersionRange.RIGHT_OPEN));
}
return Optional.empty();
}

/**
* Return the value of "Eclipse-SourceReferences" in MANIFEST.MF from the
* given bundle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.eclipse.pde.internal.core.util;

import java.util.Comparator;
import java.util.Optional;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
Expand Down Expand Up @@ -120,4 +121,14 @@ public static String computeInitialPluginVersion(String version) {
return version;
}

public static Optional<VersionRange> createConsumerRequirementRange(Version version) {
if (version != null && !Version.emptyVersion.equals(version)) {
return Optional.ofNullable(new VersionRange(VersionRange.LEFT_CLOSED, //
new Version(version.getMajor(), version.getMinor(), 0), //
new Version(version.getMajor() + 1, 0, 0), //
VersionRange.RIGHT_OPEN));
}
return Optional.empty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.eclipse.pde.internal.core.PDEState;
import org.eclipse.pde.internal.core.bundle.BundlePluginBase;
import org.eclipse.pde.internal.core.ibundle.IBundleModel;
import org.eclipse.pde.internal.core.util.ManifestUtils;
import org.eclipse.pde.internal.core.util.VersionUtil;
import org.osgi.framework.Constants;
import org.osgi.framework.VersionRange;

Expand All @@ -33,7 +33,7 @@ public class ImportPackageObject extends PackageObject {
private static final long serialVersionUID = 1L;

private static String getVersion(ExportPackageDescription desc) {
return ManifestUtils.createConsumerRequirementRange(desc.getVersion()).map(VersionRange::toString).orElse(null);
return VersionUtil.createConsumerRequirementRange(desc.getVersion()).map(VersionRange::toString).orElse(null);
}

public ImportPackageObject(ManifestHeader header, ManifestElement element, String versionAttribute) {
Expand Down
2 changes: 1 addition & 1 deletion ui/org.eclipse.pde.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %name
Bundle-SymbolicName: org.eclipse.pde.ui; singleton:=true
Bundle-Version: 3.16.300.qualifier
Bundle-Version: 3.16.400.qualifier
Bundle-Activator: org.eclipse.pde.internal.ui.PDEPlugin
Bundle-Vendor: %provider-name
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3444,6 +3444,6 @@ public class PDEUIMessages extends NLS {
public static String ProjectUpdateChange_convert_build_to_bnd;
public static String ProjectUpdateChange_set_pde_preference;

public static String AddMatchingVersion_RequireBundle;
public static String AddMatchingVersion;

}
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public IMarkerResolution[] getNonConfigSevResolutions(IMarker marker) {
case PDEMarkerFactory.M_NO_SPACE_AFTER_COLON:
return new IMarkerResolution[] {
new AddSpaceBeforeValue(AbstractPDEMarkerResolution.CREATE_TYPE, marker) };
case PDEMarkerFactory.M_MISSINGVERSION_IMPORT_PACKAGE:
return new IMarkerResolution[] {
new VersionMatchImportPackageResolution(AbstractPDEMarkerResolution.CREATE_TYPE, marker) };
}
return NO_RESOLUTIONS;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*******************************************************************************
* 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();
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.equalsIgnoreCase(inputElement.toString())) {
return exportedPackage.getVersion();
}
}
}
return null;
}

@Override
protected void createChange(BundleModel model) {
String bundleId = Objects.requireNonNull(marker.getAttribute("bundleId", (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 (bundleId.equals(importPackage.getName())) {
Version version = getVersion(bundleId);
if (version != null) {
// 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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.eclipse.pde.internal.ui.correction;

import java.util.Objects;
import java.util.Optional;

import org.eclipse.core.resources.IMarker;
import org.eclipse.pde.core.plugin.IPluginModelBase;
Expand All @@ -26,6 +27,8 @@
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 Required bundles in MANIFEST
Expand All @@ -47,8 +50,9 @@ protected void createChange(BundleModel model) {
if (modelBase != null) {
String version = modelBase.getPluginBase().getVersion();
// Sanitize version: Remove a potential qualifier
version = VersionUtil.computeInitialPluginVersion(version);
requiredBundle.setVersion(version);
Optional<VersionRange> versionRange = VersionUtil
.createConsumerRequirementRange(new Version(version));
requiredBundle.setVersion(versionRange.map(VersionRange::toString).orElse(null));
}
}
}
Expand All @@ -57,7 +61,7 @@ protected void createChange(BundleModel model) {

@Override
public String getLabel() {
return PDEUIMessages.AddMatchingVersion_RequireBundle;
return PDEUIMessages.AddMatchingVersion;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
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.util.ManifestUtils;
import org.eclipse.pde.internal.core.util.VersionUtil;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.pde.internal.ui.PDEPluginImages;
import org.eclipse.pde.internal.ui.PDEUIMessages;
Expand Down Expand Up @@ -195,7 +195,7 @@ protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws Co
}
BundleDescription requiredBundle = getChangeObject();
String pluginId = requiredBundle.getSymbolicName();
VersionRange versionRange = ManifestUtils
VersionRange versionRange = VersionUtil
.createConsumerRequirementRange(requiredBundle.getVersion()).orElse(null);
IPluginImport[] imports = base.getPluginBase().getImports();
if (!isUndo()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ UpdateClasspathResolution_label=Update the classpath and compliance settings
UpdateExecutionEnvironment_label=Update the execution environment based on JRE on the classpath
UpdateClasspathJob_task = Update classpaths...
UpdateClasspathJob_title = Updating Plug-in Classpaths
AddMatchingVersion_RequireBundle = Require latest available version
AddMatchingVersion = Require latest available version

RuntimeWorkbenchShortcut_title=Select Configuration
RuntimeWorkbenchShortcut_select_debug=Select a launch configuration to debug:
Expand Down
Loading