Skip to content

Commit

Permalink
Add support for the 'deprecated' directive on required bundles
Browse files Browse the repository at this point in the history
OSGi recently has added support for a 'deprecated' directive that can be
used by tools to inform users that the bundle supplier in one way or
another has deprecated a capability and it will likely removed in the
future.

This now adds support to PDE to show a deprecation warning if such a
bundle is used in require bundles.
  • Loading branch information
laeubi committed Dec 31, 2024
1 parent 91cdb59 commit 177fe6b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public class PDECoreMessages extends NLS {
public static String BundleErrorReporter_unecessaryDependencyDueToFragmentHost;
public static String BundleErrorReporter_missingPackagesInProject;
public static String BundleErrorReporter_noExecutionEnvironmentSet;
public static String BundleErrorReporter_deprecatedBundle;

public static String BundleErrorReporter_startHeader_autoStartDeprecated;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
import org.eclipse.osgi.service.resolver.BaseDescription;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.BundleSpecification;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
Expand Down Expand Up @@ -97,6 +98,7 @@
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;
import org.osgi.framework.wiring.BundleCapability;

public class BundleErrorReporter extends JarManifestErrorReporter {

Expand Down Expand Up @@ -184,6 +186,36 @@ protected void validate(IProgressMonitor monitor) {
validateEclipseGenericCapability();
validateEclipseGenericRequire();
validateServiceComponent();
if (isCheckDeprecated()) {
validateDeprecated();
}
}

private void validateDeprecated() {
IHeader header = getHeader(Constants.REQUIRE_BUNDLE);
if (header == null) {
return;
}
BundleDescription desc = fModel.getBundleDescription();
if (desc == null) {
return;
}
BundleSpecification[] requiredBundles = desc.getRequiredBundles();
for (BundleSpecification bundleSpecification : requiredBundles) {
BaseDescription bundle = bundleSpecification.getSupplier();
if (bundle != null) {
BundleCapability capability = bundle.getCapability();
if (capability != null) {
String deprecatedDirective = capability.getDirectives().get("deprecated"); //$NON-NLS-1$
if (deprecatedDirective != null) {
report(NLS.bind(PDECoreMessages.BundleErrorReporter_deprecatedBundle, bundle.getName(),
deprecatedDirective), header.getLineNumber(), CompilerFlags.WARNING,
PDEMarkerFactory.CAT_DEPRECATION);
}
}
}
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ BundleErrorReporter_eclipse_genericRequireDeprecated=''{0}'' header is deprecate
BundleErrorReporter_unecessaryDependencyDueToFragmentHost=The ''{0}'' dependency is not necessary as it is already specified in Fragment-Host header
BundleErrorReporter_localization_properties_file_not_exist=no valid properties files exist in the localization directory specified
BundleErrorReporter_illegalManifestVersion=The bundle manifest version is invalid. Valid ranges are 1-2.
BundleErrorReporter_deprecatedBundle=The bundle {0} is deprecated: {1}
BundleErrorReporter_serviceComponentLazyStart=Bundles with a Service-Component should set the Bundle-ActivationPolicy to lazy.
BundleManifestSourceLocationManager_problemProcessBundleManifestHeaderAttributeMissing=Problem processing bundle manifest header in source bundle {0}, plugin name and version must both be specified.
BundleValidationOperation_multiple_singletons={0} versions of singleton ''{1}'' exist
Expand Down

0 comments on commit 177fe6b

Please sign in to comment.