Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2018-01-22 22:18:39 +0000
committerAlexander Kurtakov2018-01-22 22:20:00 +0000
commitb5fe42dfc2ca68d6153010efb901560e415c6dad (patch)
treec946170860538c0e28de5dd809921945db34d7a7 /bundles/org.eclipse.equinox.p2.publisher.eclipse
parent0e3caa9359428dcb20c1dc3a2c580fff64777d3d (diff)
downloadrt.equinox.p2-b5fe42dfc2ca68d6153010efb901560e415c6dad.tar.gz
rt.equinox.p2-b5fe42dfc2ca68d6153010efb901560e415c6dad.tar.xz
rt.equinox.p2-b5fe42dfc2ca68d6153010efb901560e415c6dad.zip
Revert "Revert "Bug 528387 - Dedicated xml elements for genericI20180122-2000
requirements"" This reverts commit 0e3caa9359428dcb20c1dc3a2c580fff64777d3d. Change-Id: Ifafe2feedb963b90f54a19b2e08a49d3b18d475a Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.publisher.eclipse')
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher.eclipse/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java91
2 files changed, 56 insertions, 37 deletions
diff --git a/bundles/org.eclipse.equinox.p2.publisher.eclipse/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.publisher.eclipse/META-INF/MANIFEST.MF
index 5ff218a9e..36dbe0f51 100644
--- a/bundles/org.eclipse.equinox.p2.publisher.eclipse/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.publisher.eclipse/META-INF/MANIFEST.MF
@@ -39,6 +39,8 @@ Import-Package: org.eclipse.equinox.app;version="[1.0.0,2.0.0)",
org.eclipse.osgi.service.resolver;version="1.5.0",
org.eclipse.osgi.util;version="1.1.0",
org.osgi.framework;version="1.3.0",
+ org.osgi.framework.wiring;version="1.2.0",
+ org.osgi.resource;version="1.0.0",
org.osgi.service.application;version="1.1.0",
org.osgi.service.packageadmin;version="1.2.0"
Export-Package: org.eclipse.equinox.internal.p2.publisher.compatibility;x-internal:=true,
diff --git a/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java b/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java
index b3411b045..c2ec094be 100644
--- a/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java
+++ b/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java
@@ -12,6 +12,9 @@
******************************************************************************/
package org.eclipse.equinox.p2.publisher.eclipse;
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
@@ -28,7 +31,7 @@ import org.eclipse.equinox.p2.metadata.*;
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitFragmentDescription;
import org.eclipse.equinox.p2.metadata.VersionRange;
-import org.eclipse.equinox.p2.metadata.expression.*;
+import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
import org.eclipse.equinox.p2.publisher.*;
import org.eclipse.equinox.p2.publisher.actions.*;
import org.eclipse.equinox.p2.query.IQueryResult;
@@ -43,6 +46,8 @@ import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.internal.publishing.Activator;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.resource.Namespace;
/**
* Publish IUs for all of the bundles in a given set of locations or described by a set of
@@ -78,7 +83,6 @@ public class BundlesAction extends AbstractPublisherAction {
public static final String OSGI_BUNDLE_CLASSIFIER = "osgi.bundle"; //$NON-NLS-1$
public static final String CAPABILITY_NS_OSGI_BUNDLE = "osgi.bundle"; //$NON-NLS-1$
public static final String CAPABILITY_NS_OSGI_FRAGMENT = "osgi.fragment"; //$NON-NLS-1$
- public static final String CAPABILITY_ATTR_VERSION = "version"; //$NON-NLS-1$
public static final IProvidedCapability BUNDLE_CAPABILITY = MetadataFactory.createProvidedCapability(PublisherHelper.NAMESPACE_ECLIPSE_TYPE, TYPE_ECLIPSE_BUNDLE, Version.createOSGi(1, 0, 0));
public static final IProvidedCapability SOURCE_BUNDLE_CAPABILITY = MetadataFactory.createProvidedCapability(PublisherHelper.NAMESPACE_ECLIPSE_TYPE, TYPE_ECLIPSE_SOURCE, Version.createOSGi(1, 0, 0));
@@ -194,7 +198,7 @@ public class BundlesAction extends AbstractPublisherAction {
// Process generic requirements
ManifestElement[] rawRequireCapHeader = parseManifestHeader(Constants.REQUIRE_CAPABILITY, manifest, bd.getLocation());
for (GenericSpecification requiredCap : bd.getGenericRequires()) {
- addGenericRequirement(requirements, requiredCap, rawRequireCapHeader);
+ addRequirement(requirements, requiredCap, rawRequireCapHeader);
}
iu.setRequirements(requirements.toArray(new IRequirement[requirements.size()]));
@@ -223,7 +227,7 @@ public class BundlesAction extends AbstractPublisherAction {
int capNo = 0;
for (GenericDescription genericCap : bd.getGenericCapabilities()) {
- addGenericCapability(providedCapabilities, genericCap, iu, capNo);
+ addCapability(providedCapabilities, genericCap, iu, capNo);
capNo++;
}
@@ -301,36 +305,45 @@ public class BundlesAction extends AbstractPublisherAction {
reqsDeps.add(MetadataFactory.createRequirement(PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE, importSpec.getName(), versionRange, null, optional, false, greedy));
}
- // TODO Handle all attributes and directives somehow? Especially the "effective" directive.
- protected void addGenericRequirement(List<IRequirement> reqsDeps, GenericSpecification requireCapSpec, ManifestElement[] rawRequiresPackageHeader) {
- String ns = requireCapSpec.getType();
- String ldap = requireCapSpec.getMatchingFilter();
- String matcher = "providedCapabilities.exists(pc | pc.namespace == '" + ns + "' && pc.attributes ~= filter('" + ldap + "'))"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- IExpression expr = ExpressionUtil.parse(matcher);
- IMatchExpression<IInstallableUnit> matchExpr = ExpressionUtil.getFactory().matchExpression(expr);
-
- // Optional and greedy in order to be backward compatible.
- IRequirement requireCap = MetadataFactory.createRequirement(matchExpr, null, 0, 1, true);
-
- reqsDeps.add(requireCap);
- }
-
protected void addRequireBundleRequirement(List<IRequirement> reqsDeps, BundleSpecification requiredBundle, ManifestElement[] rawRequireBundleHeader) {
final boolean optional = requiredBundle.isOptional();
final boolean greedy;
- if (optional)
+ if (optional) {
greedy = INSTALLATION_GREEDY.equals(getInstallationDirective(requiredBundle.getName(), rawRequireBundleHeader));
- else
+ } else {
greedy = true;
+ }
reqsDeps.add(MetadataFactory.createRequirement(CAPABILITY_NS_OSGI_BUNDLE, requiredBundle.getName(), PublisherHelper.fromOSGiVersionRange(requiredBundle.getVersionRange()), null, optional ? 0 : 1, 1, greedy));
}
- protected void addGenericCapability(List<IProvidedCapability> caps, GenericDescription provideCapDesc, InstallableUnitDescription iu, int capNo) {
+ // TODO Handle the "effective:=" directive somehow?
+ protected void addRequirement(List<IRequirement> reqsDeps, GenericSpecification requireCapSpec, ManifestElement[] rawRequireCapabilities) {
+ BundleRequirement req = requireCapSpec.getRequirement();
+
+ String namespace = req.getNamespace();
+ Map<String, String> directives = req.getDirectives();
+
+ String capFilter = directives.get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
+ boolean optional = directives.get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE) == Namespace.RESOLUTION_OPTIONAL;
+ boolean greedy = optional
+ ? INSTALLATION_GREEDY.equals(directives.get(INSTALLATION_DIRECTIVE))
+ : true;
+
+ IRequirement requireCap = MetadataFactory.createRequirement(namespace, capFilter, null, optional ? 0 : 1, 1, greedy);
+ reqsDeps.add(requireCap);
+ }
+
+ protected void addCapability(List<IProvidedCapability> caps, GenericDescription provideCapDesc, InstallableUnitDescription iu, int capNo) {
+ // Convert the values to String, Version, List of String or Version
+ Map<String, Object> capAttrs = provideCapDesc.getDeclaredAttributes()
+ .entrySet()
+ .stream()
+ .collect(toMap(Entry::getKey, e -> convertAttribute(e.getValue())));
+
+ // Resolve the namespace
String capNs = provideCapDesc.getType();
- Map<String, Object> capAttrs = new HashMap<>(provideCapDesc.getDeclaredAttributes());
- // Resolve the p2 name
+ // Resolve the mandatory p2 name
// By convention OSGi capabilities have an attribute named like the capability namespace.
// If this is not the case synthesize a unique name (e.g. "osgi.service" has an "objectClass" attribute instead).
// TODO If present but not a String log a warning somehow that it is ignored? Or fail the publication?
@@ -338,28 +351,32 @@ public class BundlesAction extends AbstractPublisherAction {
capNs,
(k, v) -> (v instanceof String) ? v : String.format("%s_%s-%s", iu.getId(), iu.getVersion(), capNo)); //$NON-NLS-1$
- // Convert all OSGi versions to P2 versions
- for (String key : new HashSet<>(capAttrs.keySet())) {
- Object val = capAttrs.get(key);
- if (!(val instanceof org.osgi.framework.Version)) {
- continue;
- }
- org.osgi.framework.Version osgiVer = (org.osgi.framework.Version) val;
- Version p2Ver = Version.createOSGi(osgiVer.getMajor(), osgiVer.getMinor(), osgiVer.getMicro(), osgiVer.getQualifier());
- capAttrs.put(key, p2Ver);
- }
-
- // Resolve the version
+ // Resolve the mandatory p2 version
// By convention versioned OSGi capabilities have a "version" attribute containing the OSGi Version object
// If this is not the case use an empty version (e.g. "osgi.ee" has a list of versions).
// TODO If present but not a Version log a warning somehow that it is ignored? Or fail the publication?
capAttrs.compute(
- CAPABILITY_ATTR_VERSION,
+ IProvidedCapability.PROPERTY_VERSION,
(k, v) -> (v instanceof Version) ? v : Version.emptyVersion);
caps.add(MetadataFactory.createProvidedCapability(capNs, capAttrs));
}
+ private Object convertAttribute(Object attr) {
+ if (attr instanceof Collection<?>) {
+ return ((Collection<?>) attr).stream().map(this::convertScalarAttribute).collect(toList());
+ }
+ return convertScalarAttribute(attr);
+ }
+
+ private Object convertScalarAttribute(Object attr) {
+ if (attr instanceof org.osgi.framework.Version) {
+ org.osgi.framework.Version osgiVer = (org.osgi.framework.Version) attr;
+ return Version.createOSGi(osgiVer.getMajor(), osgiVer.getMinor(), osgiVer.getMicro(), osgiVer.getQualifier());
+ }
+ return attr.toString();
+ }
+
static VersionRange computeUpdateRange(org.osgi.framework.Version base) {
VersionRange updateRange = null;
if (!base.equals(org.osgi.framework.Version.emptyVersion)) {

Back to the top