Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTodor Boev2017-10-02 12:06:00 -0400
committerTodor Boev2017-10-04 09:26:14 -0400
commit1c02b17b8348fc8a3e04a05db1240a28ecc352cf (patch)
treeed7666b5190cdd77cbb2d9859396b5a19a0c79a8 /bundles/org.eclipse.equinox.p2.metadata
parent719079bb53131a19435e345b0e58228dedb75dbc (diff)
downloadrt.equinox.p2-1c02b17b8348fc8a3e04a05db1240a28ecc352cf.tar.gz
rt.equinox.p2-1c02b17b8348fc8a3e04a05db1240a28ecc352cf.tar.xz
rt.equinox.p2-1c02b17b8348fc8a3e04a05db1240a28ecc352cf.zip
Bug 313553 - Unentangle ProvidedCapability members and attributes
The members are the generic way for p2 queries to describe getters on objects. The capability attributes then participate in queries as the "attributes" member of a ProvidedCapability object. Fixed the IProvidedCapability to follow the OSGi convention that the attributes contain the name of the capability under a key equal to the capability namespace. This is cleaner than to introduce a new "name" attribute for the p2 name that can conflict with an incoming OSGi "name" attribute. Fixed the version of IProvidedCapability to follow the OSGi convention that capabilities with a version have a "version" attribute with a value of type an OSGi version object. Change-Id: Ic9b77c2d103216141035dc3fb5861ca99a3ddccd Signed-off-by: Todor Boev <rinsvind@gmail.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.metadata')
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/ProvidedCapability.java68
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/MemberProvider.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/IProvidedCapability.java15
3 files changed, 45 insertions, 48 deletions
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/ProvidedCapability.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/ProvidedCapability.java
index 2c68d5ecc..5d36a1913 100644
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/ProvidedCapability.java
+++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/ProvidedCapability.java
@@ -25,9 +25,18 @@ import org.eclipse.osgi.util.NLS;
* Describes a capability as exposed or required by an installable unit
*/
public class ProvidedCapability implements IProvidedCapability, IMemberProvider {
+ /** Used for fast access from P2 queries to the {@link #getNamespace} method */
+ public static final String MEMBER_NAMESPACE = "namespace"; //$NON-NLS-1$
+ /** Used for fast access from P2 queries to the {@link #getName} method */
public static final String MEMBER_NAME = "name"; //$NON-NLS-1$
+ /** Used for fast access from P2 queries to the {@link #getVersion} method */
public static final String MEMBER_VERSION = "version"; //$NON-NLS-1$
- public static final String MEMBER_NAMESPACE = "namespace"; //$NON-NLS-1$
+ /** Used for fast access from P2 queries to the {@link #getAttributes} method */
+ public static final String MEMBER_ATTRIBUTES = "attributes"; //$NON-NLS-1$
+
+ // TODO Move this to IProvidedCapability?
+ // The "version" attribute is part of the public contract of getVersion() and getAttributes()
+ public static final String ATTRIBUTE_VERSION = "version"; //$NON-NLS-1$
private final String namespace;
private final Map<String, Object> attributes;
@@ -38,26 +47,19 @@ public class ProvidedCapability implements IProvidedCapability, IMemberProvider
Assert.isNotNull(attrs);
Assert.isTrue(!attrs.isEmpty());
- Assert.isTrue(!attrs.containsKey(MEMBER_NAMESPACE));
+
this.attributes = new HashMap<>(attrs);
- if (!attributes.containsKey(MEMBER_NAME)) {
- // It is common for a capability to have a main attribute under a key
- // with value the same as the capability namespace. Use as "name" if present.
- Assert.isTrue(attributes.containsKey(namespace));
- attributes.put(MEMBER_NAME, attributes.get(namespace));
- }
+ // Verify the name
+ Assert.isTrue(attributes.containsKey(namespace) && (attributes.get(namespace) instanceof String),
+ NLS.bind(Messages.provided_capability_name_not_defined, namespace));
- Object version = attributes.get(MEMBER_VERSION);
- if (version == null) {
- attributes.put(MEMBER_VERSION, Version.emptyVersion);
- } else if (version instanceof org.osgi.framework.Version) {
- org.osgi.framework.Version osgiVer = (org.osgi.framework.Version) version;
- attributes.put(
- MEMBER_VERSION,
- Version.createOSGi(osgiVer.getMajor(), osgiVer.getMinor(), osgiVer.getMicro(), osgiVer.getQualifier()));
+ // Verify the version
+ Object version = attributes.get(ATTRIBUTE_VERSION);
+ if (version != null) {
+ Assert.isTrue(attributes.get(ATTRIBUTE_VERSION) instanceof Version);
} else {
- Assert.isTrue(version instanceof Version);
+ attributes.put(ATTRIBUTE_VERSION, Version.emptyVersion);
}
}
@@ -66,8 +68,8 @@ public class ProvidedCapability implements IProvidedCapability, IMemberProvider
Assert.isNotNull(name, NLS.bind(Messages.provided_capability_name_not_defined, namespace));
this.namespace = namespace;
this.attributes = new HashMap<>();
- attributes.put(MEMBER_NAME, name);
- attributes.put(MEMBER_VERSION, version == null ? Version.emptyVersion : version);
+ attributes.put(namespace, name);
+ attributes.put(ATTRIBUTE_VERSION, version == null ? Version.emptyVersion : version);
}
public boolean equals(Object other) {
@@ -92,18 +94,16 @@ public class ProvidedCapability implements IProvidedCapability, IMemberProvider
return true;
}
- public String getName() {
- // There is always a "name" member, but it may not always be a string.
- // Convert it here so that it is still possible to get the real type via getAttributes().
- return attributes.get(MEMBER_NAME).toString();
- }
-
public String getNamespace() {
return namespace;
}
+ public String getName() {
+ return (String) attributes.get(namespace);
+ }
+
public Version getVersion() {
- return (Version) attributes.get(MEMBER_VERSION);
+ return (Version) attributes.get(ATTRIBUTE_VERSION);
}
public Map<String, Object> getAttributes() {
@@ -129,11 +129,19 @@ public class ProvidedCapability implements IProvidedCapability, IMemberProvider
return str.toString();
}
+ @Override
public Object getMember(String memberName) {
- Object res = memberName.equals(MEMBER_NAMESPACE) ? namespace : attributes.get(memberName);
- if (res == null) {
- throw new IllegalArgumentException("No such member: " + memberName); //$NON-NLS-1$
+ switch (memberName) {
+ case MEMBER_NAMESPACE :
+ return namespace;
+ case MEMBER_NAME :
+ return attributes.get(namespace);
+ case MEMBER_VERSION :
+ return attributes.get(ATTRIBUTE_VERSION);
+ case MEMBER_ATTRIBUTES :
+ return attributes;
+ default :
+ throw new IllegalArgumentException("No such member: " + memberName); //$NON-NLS-1$
}
- return res;
}
}
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/MemberProvider.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/MemberProvider.java
index 4eaa4814b..dccb00397 100644
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/MemberProvider.java
+++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/MemberProvider.java
@@ -12,8 +12,6 @@ package org.eclipse.equinox.internal.p2.metadata.expression;
import java.util.*;
import java.util.Map.Entry;
-import org.eclipse.equinox.internal.p2.metadata.ProvidedCapability;
-import org.eclipse.equinox.p2.metadata.IProvidedCapability;
import org.eclipse.equinox.p2.metadata.expression.IMemberProvider;
import org.osgi.framework.ServiceReference;
@@ -137,14 +135,6 @@ public abstract class MemberProvider implements IMemberProvider {
return caseInsensitive ? new CIDictionaryMemberProvider((Dictionary<String, ?>) value) : new DictionaryMemberProvider((Dictionary<String, ?>) value);
if (value instanceof ServiceReference)
return new ServiceRefMemberProvider((ServiceReference<?>) value);
- // TODO Should there be a clause in Matches.match() instead?
- if (value instanceof IProvidedCapability) {
- IProvidedCapability cap = (IProvidedCapability) value;
- Map<String, Object> attrs = new HashMap<String, Object>();
- attrs.put(ProvidedCapability.MEMBER_NAMESPACE, cap.getNamespace());
- attrs.putAll(cap.getAttributes());
- return caseInsensitive ? new CIMapMemberProvider(attrs) : new MapMemberProvider(attrs);
- }
throw new IllegalArgumentException();
}
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/IProvidedCapability.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/IProvidedCapability.java
index 47aa3ee51..a1c0f3af8 100644
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/IProvidedCapability.java
+++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/IProvidedCapability.java
@@ -28,24 +28,23 @@ import java.util.Map;
* @see IRequirement
*/
public interface IProvidedCapability {
-
/**
*
- * @return String the String representation of the special "name" attribute of this capability.
+ * @return String the namespace of this capability.
* @noreference This method is not intended to be referenced by clients.
*/
- public String getName();
+ public String getNamespace();
/**
*
- * @return String the namespace of this capability.
+ * @return String the attribute stored under a key equal to {@link #getNamespace()} attribute of this capability.
* @noreference This method is not intended to be referenced by clients.
*/
- public String getNamespace();
+ public String getName();
/**
*
- * @return String the special "version" attribute of this capability.
+ * @return String the special <code>version</code> attribute of this capability.
* @noreference This method is not intended to be referenced by clients.
*/
public Version getVersion();
@@ -54,6 +53,7 @@ public interface IProvidedCapability {
*
* @return A full description of this capability
* @noreference This method is not intended to be referenced by clients.
+ * @since 2.4
*/
public Map<String, Object> getAttributes();
@@ -63,9 +63,8 @@ public interface IProvidedCapability {
* This method returns <i>true</i> if:
* <ul>
* <li> Both this object and the given object are of type IProvidedCapability
- * <li> The result of <b>getName()</b> on both objects are equal
* <li> The result of <b>getNamespace()</b> on both objects are equal
- * <li> The result of <b>getVersion()</b> on both objects are equal
+ * <li> The result of <b>getAttributes()</b> on both objects are equal
* </ul>
*/
public boolean equals(Object other);

Back to the top