Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace APIs using equinox VersionRange and PluginRegistry.PluginFilter #1163

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions ui/org.eclipse.pde.core/.settings/.api_filters
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.pde.core" version="2">
<resource path="src/org/eclipse/pde/core/plugin/PluginRegistry.java" type="org.eclipse.pde.core.plugin.PluginRegistry">
<filter id="354463860">
<message_arguments>
<message_argument value="org.eclipse.pde.core.plugin.PluginRegistry"/>
<message_argument value="PluginRegistry()"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/pde/internal/core/project/BundleProjectService.java" type="org.eclipse.pde.internal.core.project.BundleProjectService">
<filter comment="Platform Team allows use of bundle importers for PDE import from source repository" id="640712815">
<message_arguments>
Expand Down
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.18.0.qualifier
Bundle-Version: 3.19.0.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 @@ -23,6 +23,7 @@
* @noextend This interface is not intended to be extended by clients.
*/
public interface IMatchRules {
// TODO: convert this to enums?
/**
* No rule.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.pde.core.build.IBuildModel;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.build.WorkspaceBuildModel;
import org.eclipse.pde.internal.core.project.PDEProject;
import org.eclipse.pde.internal.core.util.VersionUtil;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;
import org.osgi.resource.Resource;

/**
Expand All @@ -45,15 +46,21 @@
*/
public class PluginRegistry {

private PluginRegistry() { // static use only
}

/**
* Filter used when searching for plug-in models.
* <p>
* Clients may subclass this class to implement custom filters.
* </p>
* @see PluginRegistry#findModel(String, String, int, PluginFilter)
* @see PluginRegistry#findModel(String, VersionRange, PluginFilter)
*
* @see PluginRegistry#findModel(String, String, int, Predicate)
* @see PluginRegistry#findModel(String, VersionRange, Predicate)
* @since 3.6
* @deprecated Instead use {@link Predicate}
*/
@Deprecated(forRemoval = true, since = "3.19")
public static class PluginFilter {

/**
Expand All @@ -79,6 +86,10 @@ public static ModelEntry findEntry(String id) {
return PDECore.getDefault().getModelManager().findEntry(id);
}

// TODO: use stream and optional and remove filters?!
// At least Stream instead of List to be consistent with the existing
// methods returning a single element

/**
* Returns the plug-in model for the best match plug-in with the given ID.
* A null value is returned if no such bundle is found in the workspace or target platform.
Expand Down Expand Up @@ -274,10 +285,21 @@ public static IPluginModelBase[] getExternalModels() {
* a plug-in filter or <code>null</code>
*
* @return a matching model or <code>null</code>
* @since 3.19
*/
public static IPluginModelBase findModel(String id, String version, int match, Predicate<IPluginModelBase> filter) {
return getMax(findModels(id, version, match, filter));
}

/**
* @see #findModel(String, String, int, Predicate)
* @since 3.6
* @deprecated Instead use
* {@link #findModel(String, String, int, Predicate)}
*/
@Deprecated(forRemoval = true, since = "3.19")
public static IPluginModelBase findModel(String id, String version, int match, PluginFilter filter) {
return getMax(findModels(id, version, match, filter));
return findModel(id, version, match, filter::accept);
}

/**
Expand All @@ -298,22 +320,36 @@ public static IPluginModelBase findModel(String id, String version, int match, P
* @param filter a plug-in filter or <code>null</code>
*
* @return a matching models, possibly an empty collection
* @since 3.6
* @since 3.19
*/
public static IPluginModelBase[] findModels(String id, String version, int match, PluginFilter filter) {
public static List<IPluginModelBase> findModels(String id, String version, int match,
Predicate<IPluginModelBase> filter) {
IPluginModelBase[] models = findModels(id);
List<IPluginModelBase> results = new ArrayList<>();
for (IPluginModelBase model : models) {
IPluginBase base = model.getPluginBase();
if (base == null || base.getId() == null) {
continue; // guard against invalid plug-ins
}
if ((filter == null || filter.accept(model))
if ((filter == null || filter.test(model))
&& (version == null || VersionUtil.compare(base.getVersion(), version, match))) {
results.add(model);
}
}
return results.toArray(IPluginModelBase[]::new);
return List.copyOf(results);
}
// TODO: translate Version+Match kind into a VersionRange. Provide it as
// method for a IMatchRules enum?

/**
* @see #findModels(String, String, int, Predicate)
* @since 3.6
* @deprecated Instead use
* {@link #findModels(String, String, int, Predicate)}
*/
@Deprecated(forRemoval = true, since = "3.19")
public static IPluginModelBase[] findModels(String id, String version, int match, PluginFilter filter) {
return findModels(id, version, match, filter::accept).toArray(IPluginModelBase[]::new);
}

/**
Expand All @@ -337,24 +373,36 @@ public static IPluginModelBase[] findModels(String id, String version, int match
* @param filter a plug-in filter or <code>null</code>
*
* @return a matching model or <code>null</code>
* @since 3.6
* @since 3.19
*/
public static IPluginModelBase findModel(String id, VersionRange range, PluginFilter filter) {
public static IPluginModelBase findModel(String id, VersionRange range, Predicate<IPluginModelBase> filter) {
return getMax(findModels(id, range, filter));
}

/**
* @see #findModel(String, VersionRange, Predicate)
* @since 3.6
* @deprecated Instead use
* {@link #findModel(String, VersionRange, Predicate)}
*/
@Deprecated(forRemoval = true, since = "3.19")
public static IPluginModelBase findModel(String id, org.eclipse.osgi.service.resolver.VersionRange range,
PluginFilter filter) {
return findModel(id, range, filter::accept);
}

/**
* Returns the plug-in with the highest version, or <code>null</code> if empty.
*
* @param models models
* @return plug-in with the highest version or <code>null</code>
*/
private static IPluginModelBase getMax(IPluginModelBase[] models) {
if (models.length == 0) {
private static IPluginModelBase getMax(List<IPluginModelBase> models) {
if (models.isEmpty()) {
return null;
}
if (models.length == 1) {
return models[0];
if (models.size() == 1) {
return models.get(0);
}
IPluginModelBase max = null;
Version maxV = null;
Expand Down Expand Up @@ -389,21 +437,33 @@ private static IPluginModelBase getMax(IPluginModelBase[] models) {
* @param filter a plug-in filter or <code>null</code>
*
* @return a matching models, possibly empty
* @since 3.6
* @since 3.19
*/
public static IPluginModelBase[] findModels(String id, VersionRange range, PluginFilter filter) {
public static List<IPluginModelBase> findModels(String id, VersionRange range, Predicate<IPluginModelBase> filter) {
IPluginModelBase[] models = findModels(id);
List<IPluginModelBase> results = new ArrayList<>();
for (IPluginModelBase model : models) {
if (filter == null || filter.accept(model)) {
if (filter == null || filter.test(model)) {
String versionStr = model.getPluginBase().getVersion();
Version version = VersionUtil.validateVersion(versionStr).isOK() ? new Version(versionStr) : Version.emptyVersion;
if (range == null || range.isIncluded(version)) {
if (range == null || range.includes(version)) {
results.add(model);
}
}
}
return results.toArray(IPluginModelBase[]::new);
return List.copyOf(results);
}

/**
* @see #findModels(String, VersionRange, Predicate)
* @since 3.6
* @deprecated Instead use
* {@link #findModels(String, VersionRange, Predicate)}
*/
@Deprecated(forRemoval = true, since = "3.19")
public static IPluginModelBase[] findModels(String id, org.eclipse.osgi.service.resolver.VersionRange range,
PluginFilter filter) {
return findModels(id, range, filter::accept).toArray(IPluginModelBase[]::new);
}

private static IPluginModelBase[] findModels(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.ServiceCaller;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;

/**
* Service used to create and configure bundle project descriptions.
Expand Down Expand Up @@ -55,19 +55,39 @@ public interface IBundleProjectService {
* @param name symbolic name of the host
* @param range version constraint or <code>null</code>
* @return host description
* @since 3.19
*/
IHostDescription newHost(String name, VersionRange range);

/**
* @deprecated Instead use {@link #newHost(String, VersionRange)}
*/
@Deprecated(forRemoval = true, since = "4.19")
default IHostDescription newHost(String name, org.eclipse.osgi.service.resolver.VersionRange range) {
return newHost(name, (VersionRange) range);
}

/**
* Creates and returns a new package import description.
*
* @param name fully qualified name of imported package
* @param range version constraint or <code>null</code>
* @param optional whether the import is optional
* @return package import description
* @since 3.19
*/
IPackageImportDescription newPackageImport(String name, VersionRange range, boolean optional);

/**
* @deprecated Instead use
* {@link #newPackageImport(String, VersionRange, boolean)}
*/
@Deprecated(forRemoval = true, since = "4.19")
default IPackageImportDescription newPackageImport(String name,
org.eclipse.osgi.service.resolver.VersionRange range, boolean optional) {
return newPackageImport(name, (VersionRange) range, optional);
}

/**
* Constructs a new package export description.
*
Expand All @@ -88,9 +108,20 @@ public interface IBundleProjectService {
* @param optional whether the required bundle is optional
* @param export whether the required bundle is re-exported
* @return required bundle description
* @since 3.19
*/
IRequiredBundleDescription newRequiredBundle(String name, VersionRange range, boolean optional, boolean export);

/**
* @deprecated Instead use
* {@link #newRequiredBundle(String, VersionRange, boolean, boolean)}
*/
@Deprecated(forRemoval = true, since = "4.19")
default IRequiredBundleDescription newRequiredBundle(String name,
org.eclipse.osgi.service.resolver.VersionRange range, boolean optional, boolean export) {
return newRequiredBundle(name, range, optional, export);
}

/**
* Creates and returns a new bundle classpath entry defining the relationship
* between a source, binaries, and library on the Bundle-Classpath header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*******************************************************************************/
package org.eclipse.pde.core.project;

import org.eclipse.osgi.service.resolver.VersionRange;
import org.osgi.framework.VersionRange;

/**
* Describes a fragment host. Instances of this class can be created
Expand All @@ -30,14 +30,25 @@ public interface IHostDescription {
*
* @return symbolic name of the host
*/
public String getName();
String getName();

/**
* Returns the version constraint of the host or <code>null</code>
* if unspecified.
*
* @return version constraint or <code>null</code>
* @since 3.19
*/
public VersionRange getVersionRange();
VersionRange getVersion();
// TODO: alternatively name it getHostVersion()

/**
* @deprecated Instead use {@link #getVersion()}
*/
@Deprecated(forRemoval = true, since = "4.19")
default org.eclipse.osgi.service.resolver.VersionRange getVersionRange() {
VersionRange version = getVersion();
return version != null ? new org.eclipse.osgi.service.resolver.VersionRange(version.toString()) : null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*******************************************************************************/
package org.eclipse.pde.core.project;

import org.eclipse.osgi.service.resolver.VersionRange;
import org.osgi.framework.VersionRange;

/**
* Describes a package import. Instances of this class can be created
Expand All @@ -30,21 +30,31 @@ public interface IPackageImportDescription {
*
* @return fully qualified name of the imported package
*/
public String getName();
String getName();

/**
* Returns the version constraint of the imported package or <code>null</code>
* if unspecified.
*
* @return version constraint or <code>null</code>
* @since 3.19
*/
public VersionRange getVersionRange();
VersionRange getVersion();

/**
* @deprecated Instead use {@link #getVersion()}
*/
@Deprecated(forRemoval = true, since = "4.19")
default org.eclipse.osgi.service.resolver.VersionRange getVersionRange() {
VersionRange version = getVersion();
return version != null ? new org.eclipse.osgi.service.resolver.VersionRange(version.toString()) : null;
}

/**
* Returns whether the package import is optional.
*
* @return whether optional
*/
public boolean isOptional();
boolean isOptional();

}