diff options
author | Todor Boev | 2017-10-02 16:06:00 +0000 |
---|---|---|
committer | Todor Boev | 2017-10-04 13:26:14 +0000 |
commit | 1c02b17b8348fc8a3e04a05db1240a28ecc352cf (patch) | |
tree | ed7666b5190cdd77cbb2d9859396b5a19a0c79a8 /bundles/org.eclipse.equinox.p2.metadata.repository | |
parent | 719079bb53131a19435e345b0e58228dedb75dbc (diff) | |
download | rt.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.repository')
2 files changed, 13 insertions, 10 deletions
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java index a1ff60596..90e27da4b 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java @@ -16,8 +16,7 @@ import java.net.URI; import java.util.*; import java.util.Map.Entry; import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; -import org.eclipse.equinox.internal.p2.metadata.ArtifactKey; -import org.eclipse.equinox.internal.p2.metadata.InstallableUnit; +import org.eclipse.equinox.internal.p2.metadata.*; import org.eclipse.equinox.internal.p2.persistence.XMLParser; import org.eclipse.equinox.p2.metadata.*; import org.eclipse.equinox.p2.metadata.MetadataFactory.*; @@ -533,6 +532,7 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { this.version = checkVersion(PROVIDED_CAPABILITY_ELEMENT, VERSION_ATTRIBUTE, values[2]); } + @Override public void startElement(String elem, Attributes attributes) { if (elem.equals(CAPABILITY_ATTRIBUTES_ELEMENT)) { this.attributesHandler = new ProvidedCapabilityAttributesHandler(this, attributes); @@ -541,13 +541,14 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { } } + @Override protected void finished() { Map<String, Object> capAttrs = (attributesHandler != null) ? attributesHandler.getAttributes() - : new HashMap<String, Object>(); + : new HashMap<>(); - capAttrs.put(NAME_ATTRIBUTE, name); - capAttrs.put(VERSION_ATTRIBUTE, version); + capAttrs.put(namespace, name); + capAttrs.put(ProvidedCapability.ATTRIBUTE_VERSION, version); IProvidedCapability cap = MetadataFactory.createProvidedCapability(namespace, capAttrs); capabilities.add(cap); } @@ -559,13 +560,14 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { public ProvidedCapabilityAttributesHandler(AbstractHandler parentHandler, Attributes attributes) { super(parentHandler, CAPABILITY_ATTRIBUTES_ELEMENT); // TODO add getOptionalSize(attributes, 4) - this.capAttributes = new HashMap<String, Object>(); + this.capAttributes = new HashMap<>(); } public Map<String, Object> getAttributes() { return capAttributes; } + @Override public void startElement(String name, Attributes attributes) { if (name.equals(CAPABILITY_ATTRIBUTE_ELEMENT)) { new ProvidedCapabilityAttributeHandler(this, attributes, capAttributes); @@ -600,7 +602,7 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { private List<Object> parseList(String type, String value) { String elType = type.substring(ATTR_TYPE_LIST_HEAD.length(), type.length() - 1); - List<Object> res = new ArrayList<Object>(); + List<Object> res = new ArrayList<>(); for (String el : value.split("\\s*,\\s*")) { //$NON-NLS-1$ res.add(parseScalar(elType, el)); } diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java index 37559a7b9..2b7686e35 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java @@ -17,6 +17,7 @@ import java.util.*; import java.util.Map.Entry; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; +import org.eclipse.equinox.internal.p2.metadata.ProvidedCapability; import org.eclipse.equinox.internal.p2.metadata.RequiredCapability; import org.eclipse.equinox.internal.p2.metadata.repository.Activator; import org.eclipse.equinox.internal.p2.persistence.XMLWriter; @@ -167,8 +168,8 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { attribute(VERSION_ATTRIBUTE, capability.getVersion()); Map<String, Object> attrs = new HashMap<>(capability.getAttributes()); - attrs.remove(NAME_ATTRIBUTE); - attrs.remove(VERSION_ATTRIBUTE); + attrs.remove(capability.getNamespace()); + attrs.remove(ProvidedCapability.ATTRIBUTE_VERSION); if (!attrs.isEmpty()) { start(CAPABILITY_ATTRIBUTES_ELEMENT); @@ -185,7 +186,7 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { Collection<?> coll = (Collection<?>) val; String elType = coll.iterator().next().getClass().getSimpleName(); - type = "List<" + elType + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + type = String.format("List<%s>", elType); //$NON-NLS-1$ StringBuilder valBuff = new StringBuilder(); for (Iterator<?> iter = coll.iterator(); iter.hasNext();) { |