Skip to content

Commit 177fe6b

Browse files
committed
Add support for the 'deprecated' directive on required bundles
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.
1 parent 91cdb59 commit 177fe6b

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public class PDECoreMessages extends NLS {
222222
public static String BundleErrorReporter_unecessaryDependencyDueToFragmentHost;
223223
public static String BundleErrorReporter_missingPackagesInProject;
224224
public static String BundleErrorReporter_noExecutionEnvironmentSet;
225+
public static String BundleErrorReporter_deprecatedBundle;
225226

226227
public static String BundleErrorReporter_startHeader_autoStartDeprecated;
227228

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.eclipse.jdt.launching.JavaRuntime;
5656
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
5757
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
58+
import org.eclipse.osgi.service.resolver.BaseDescription;
5859
import org.eclipse.osgi.service.resolver.BundleDescription;
5960
import org.eclipse.osgi.service.resolver.BundleSpecification;
6061
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
@@ -97,6 +98,7 @@
9798
import org.osgi.framework.InvalidSyntaxException;
9899
import org.osgi.framework.Version;
99100
import org.osgi.framework.VersionRange;
101+
import org.osgi.framework.wiring.BundleCapability;
100102

101103
public class BundleErrorReporter extends JarManifestErrorReporter {
102104

@@ -184,6 +186,36 @@ protected void validate(IProgressMonitor monitor) {
184186
validateEclipseGenericCapability();
185187
validateEclipseGenericRequire();
186188
validateServiceComponent();
189+
if (isCheckDeprecated()) {
190+
validateDeprecated();
191+
}
192+
}
193+
194+
private void validateDeprecated() {
195+
IHeader header = getHeader(Constants.REQUIRE_BUNDLE);
196+
if (header == null) {
197+
return;
198+
}
199+
BundleDescription desc = fModel.getBundleDescription();
200+
if (desc == null) {
201+
return;
202+
}
203+
BundleSpecification[] requiredBundles = desc.getRequiredBundles();
204+
for (BundleSpecification bundleSpecification : requiredBundles) {
205+
BaseDescription bundle = bundleSpecification.getSupplier();
206+
if (bundle != null) {
207+
BundleCapability capability = bundle.getCapability();
208+
if (capability != null) {
209+
String deprecatedDirective = capability.getDirectives().get("deprecated"); //$NON-NLS-1$
210+
if (deprecatedDirective != null) {
211+
report(NLS.bind(PDECoreMessages.BundleErrorReporter_deprecatedBundle, bundle.getName(),
212+
deprecatedDirective), header.getLineNumber(), CompilerFlags.WARNING,
213+
PDEMarkerFactory.CAT_DEPRECATION);
214+
}
215+
}
216+
}
217+
}
218+
187219
}
188220

189221

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties

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

0 commit comments

Comments
 (0)