From c5b75fe31206295cc10b676eac953c6a6006d9f2 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Thu, 22 Feb 2024 00:04:38 +0100 Subject: [PATCH] Replace APIs using equinox-resolve's BundleDescription Part of https://github.com/eclipse-pde/eclipse.pde/issues/1069 --- .../.settings/.api_filters | 14 ++++++ ui/org.eclipse.pde.core/META-INF/MANIFEST.MF | 2 +- .../pde/core/IClasspathContributor.java | 36 +++++++++++++- .../pde/core/plugin/IPluginModelBase.java | 40 ++++++++++++---- .../eclipse/pde/core/plugin/ModelEntry.java | 47 ++++++++++++------- .../core/bundle/BundlePluginModelBase.java | 2 +- .../core/plugin/AbstractPluginModelBase.java | 2 +- .../core/text/plugin/FragmentModel.java | 2 +- .../core/text/plugin/PluginModel.java | 2 +- 9 files changed, 112 insertions(+), 35 deletions(-) diff --git a/ui/org.eclipse.pde.core/.settings/.api_filters b/ui/org.eclipse.pde.core/.settings/.api_filters index f26c3f1cfb..7268a3d619 100644 --- a/ui/org.eclipse.pde.core/.settings/.api_filters +++ b/ui/org.eclipse.pde.core/.settings/.api_filters @@ -1,5 +1,19 @@ + + + + + + + + + + + + + + diff --git a/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF index 423c3028e1..3af6fd09f9 100644 --- a/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF +++ b/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF @@ -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.18.0.qualifier +Bundle-Version: 3.19.0.qualifier Bundle-Activator: org.eclipse.pde.internal.core.PDECore Bundle-Vendor: %provider-name Bundle-Localization: plugin diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/IClasspathContributor.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/IClasspathContributor.java index 3780a3eb73..6d4cb4725a 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/IClasspathContributor.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/IClasspathContributor.java @@ -17,6 +17,7 @@ import java.util.List; +import org.eclipse.core.resources.IProject; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.osgi.service.resolver.BundleDescription; import org.eclipse.pde.core.plugin.PluginRegistry; @@ -40,6 +41,8 @@ * @since 3.9 */ public interface IClasspathContributor { + // TODO: The cleaner way would be to create a completely new interface and + // deprecate this one. But how to name it? /** * Get any additional classpath entries to add to a project when its @@ -53,8 +56,21 @@ public interface IClasspathContributor { * classpath computed * @return additional classpath entries to add to the project, possibly * empty, must not be null + * @since 3.19 */ - List getInitialEntries(BundleDescription project); + default List getInitialEntries(IProject project) { + BundleDescription description = PluginRegistry.findModel(project).getBundleDescription(); + return getInitialEntries(description); + } + + /** + * @deprecated Instead implement {@link #getInitialEntries(IProject)} + */ + @Deprecated(forRemoval = true, since = "4.19") + default List getInitialEntries(BundleDescription project) { + throw new UnsupportedOperationException( + "This method is deprecated. Implement and call getInitialEntries(IProject) instead"); + } /** * Get any additional classpath entries to add to a project when a new bundle @@ -66,6 +82,22 @@ public interface IClasspathContributor { * @param project the bundle descriptor for the plug-in project having its classpath computed * @param addedDependency the bundle descriptor for the bundle being added to the classpath as a dependency * @return additional classpath entries to add to the project, possibly empty, must not be null + * @since 3.19 */ - List getEntriesForDependency(BundleDescription project, BundleDescription addedDependency); + default List getEntriesForDependency(IProject project, Resource addedDependency) { + BundleDescription description = PluginRegistry.findModel(project).getBundleDescription(); + return getEntriesForDependency(description, (BundleDescription) addedDependency); + } + + /** + * @deprecated Instead implement + * {@link #getEntriesForDependency(IProject, Resource)} + */ + @Deprecated(forRemoval = true, since = "4.19") + default List getEntriesForDependency(BundleDescription project, + BundleDescription addedDependency) { + throw new UnsupportedOperationException( + "This method is deprecated. Implement and call getEntriesForDependency(IProject, Resource) instead"); + } + } diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/plugin/IPluginModelBase.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/plugin/IPluginModelBase.java index 69aceab376..4e784cfe6e 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/plugin/IPluginModelBase.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/plugin/IPluginModelBase.java @@ -16,9 +16,9 @@ import java.net.URL; import org.eclipse.core.runtime.URIUtil; -import org.eclipse.osgi.service.resolver.BundleDescription; import org.eclipse.pde.core.IModelChangeProvider; import org.eclipse.pde.core.build.IBuildModel; +import org.osgi.resource.Resource; /** * This type of model is created by parsing the manifest file. @@ -63,7 +63,7 @@ public interface IPluginModelBase extends ISharedExtensionsModel, IModelChangePr * @deprecated This method has always returned null. * Since 3.7, use {@link PluginRegistry#createBuildModel(IPluginModelBase)} instead. */ - @Deprecated + @Deprecated(forRemoval = true, since = "4.19") IBuildModel getBuildModel(); /** @@ -128,20 +128,35 @@ public interface IPluginModelBase extends ISharedExtensionsModel, IModelChangePr * an encoding tool such as {@link URIUtil}. Deprecated in * 4.3. */ - @Deprecated + @Deprecated(forRemoval = true, since = "4.19") URL getNLLookupLocation(); /** - * Returns the bundle description of the plug-in - * in case the plug-in uses the new OSGi bundle layout. + * Returns the bundle {@link Resource} of the plug-in in case the plug-in + * uses the OSGi bundle layout. * - * @return bundle description if this is an OSGi plug-in, - * or null if the plug-in is in a classic - * format. + * @return resource if this is an OSGi plug-in, or null if the + * plug-in is in a legacy format. + * @since 3.19 + */ + Resource getBundleResource(); + // TODO: is the legacy format still supported? If yes, remove support for + // that as well? + + /** + * Returns the bundle description of the plug-in in case the plug-in uses + * the new OSGi bundle layout. + * + * @return bundle description if this is an OSGi plug-in, or + * null if the plug-in is in a classic format. * * @since 3.0 + * @deprecated Instead use {@link #getBundleResource() } */ - BundleDescription getBundleDescription(); + @Deprecated(forRemoval = true, since = "4.19") + default org.eclipse.osgi.service.resolver.BundleDescription getBundleDescription() { + return (org.eclipse.osgi.service.resolver.BundleDescription) getBundleResource(); + } /** * Associates the bundle description of the plug-in @@ -152,6 +167,11 @@ public interface IPluginModelBase extends ISharedExtensionsModel, IModelChangePr * with this model * * @since 3.0 + * @deprecated Users should never modify the OSGi bundle representation of a + * plugin-model, this is only done by PDE itself. */ - void setBundleDescription(BundleDescription description); + @Deprecated(forRemoval = true, since = "4.19") + void setBundleDescription(org.eclipse.osgi.service.resolver.BundleDescription description); + // FIXME: I don't think users should be able to set a resource/desription. + // But check possible use-cases again. } diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/plugin/ModelEntry.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/plugin/ModelEntry.java index aecbe7d741..ecf1f69b02 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/plugin/ModelEntry.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/plugin/ModelEntry.java @@ -16,7 +16,8 @@ import java.util.ArrayList; import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.osgi.service.resolver.BundleDescription; +import org.osgi.framework.wiring.BundleRevision; +import org.osgi.resource.Resource; /** * A ModelEntry object has an ID and keeps track of all workspace plug-ins and target @@ -105,7 +106,7 @@ public IPluginModelBase getModel() { private IPluginModelBase getBestCandidate(IPluginModelBase[] models) { IPluginModelBase result = null; for (IPluginModelBase model : models) { - if (model.getBundleDescription() == null) { + if (model.getBundleResource() == null) { continue; } @@ -119,9 +120,11 @@ private IPluginModelBase getBestCandidate(IPluginModelBase[] models) { continue; } - BundleDescription current = result.getBundleDescription(); - BundleDescription candidate = model.getBundleDescription(); - if (!current.isResolved() && candidate.isResolved()) { + BundleRevision current = result.getBundleDescription(); + BundleRevision candidate = model.getBundleDescription(); + // TODO: check if getWiring()!=null is really equivalent to + // BundleDescription.isResolved() + if (current.getWiring() == null && candidate.getWiring() != null) { result = model; continue; } @@ -175,34 +178,42 @@ public String getId() { } /** - * Return the plug-in model associated with the given bundle description or - * null if none is found. + * Return the plug-in model associated with the given bundle + * {@link Resource} or null if none is found. * - * @param desc the given bundle description + * @param resource + * the given bundle resource * - * @return the plug-in model associated with the given bundle description if such a - * model exists. + * @return the plug-in model associated with the given bundle description if + * such a model exists. + * @since 3.19 */ - public IPluginModelBase getModel(BundleDescription desc) { - if (desc == null) { + public IPluginModelBase getModel(Resource resource) { + if (resource == null) { return null; } - for (int i = 0; i < fWorkspaceEntries.size(); i++) { - IPluginModelBase model = fWorkspaceEntries.get(i); - if (desc.equals(model.getBundleDescription())) { + for (IPluginModelBase model : fWorkspaceEntries) { + if (resource.equals(model.getBundleResource())) { return model; } } - for (int i = 0; i < fExternalEntries.size(); i++) { - IPluginModelBase model = fExternalEntries.get(i); - if (desc.equals(model.getBundleDescription())) { + for (IPluginModelBase model : fExternalEntries) { + if (resource.equals(model.getBundleResource())) { return model; } } return null; } + /** + * @deprecated Instead use {@link #getModel(Resource) } + */ + @Deprecated(forRemoval = true, since = "4.19") + public IPluginModelBase getModel(org.eclipse.osgi.service.resolver.BundleDescription desc) { + return getModel((Resource) desc); + } + /** * Returns true if there are workspace plug-ins associated with the ID * of this model entry; falseotherwise. diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundlePluginModelBase.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundlePluginModelBase.java index 9d809e2e6e..3f2fabb414 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundlePluginModelBase.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundlePluginModelBase.java @@ -333,7 +333,7 @@ public boolean isBundleModel() { } @Override - public BundleDescription getBundleDescription() { + public BundleDescription getBundleResource() { return fBundleDescription; } diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/AbstractPluginModelBase.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/AbstractPluginModelBase.java index 41c12d65c9..4e4183543b 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/AbstractPluginModelBase.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/AbstractPluginModelBase.java @@ -236,7 +236,7 @@ public void dispose() { } @Override - public BundleDescription getBundleDescription() { + public BundleDescription getBundleResource() { return fBundleDescription; } diff --git a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/FragmentModel.java b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/FragmentModel.java index cfb66d27b1..31df7de0ee 100644 --- a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/FragmentModel.java +++ b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/FragmentModel.java @@ -35,7 +35,7 @@ public boolean isFragmentModel() { } @Override - public BundleDescription getBundleDescription() { + public BundleDescription getBundleResource() { return null; } diff --git a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginModel.java b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginModel.java index 048110888e..e3107d500f 100644 --- a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginModel.java +++ b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginModel.java @@ -35,7 +35,7 @@ public boolean isFragmentModel() { } @Override - public BundleDescription getBundleDescription() { + public BundleDescription getBundleResource() { return null; }