diff options
author | Alexander Kurtakov | 2018-01-22 22:18:39 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2018-01-22 22:20:00 +0000 |
commit | b5fe42dfc2ca68d6153010efb901560e415c6dad (patch) | |
tree | c946170860538c0e28de5dd809921945db34d7a7 /bundles/org.eclipse.equinox.p2.metadata.repository | |
parent | 0e3caa9359428dcb20c1dc3a2c580fff64777d3d (diff) | |
download | rt.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.metadata.repository')
4 files changed, 241 insertions, 164 deletions
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryIO.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryIO.java index ed67c081a..4243ad59d 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryIO.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryIO.java @@ -104,7 +104,7 @@ public class MetadataRepositoryIO { // A format version number for metadata repository XML. public static final Version COMPATIBLE_VERSION = Version.createOSGi(1, 0, 0); - public static final Version CURRENT_VERSION = Version.createOSGi(1, 1, 0); + public static final Version CURRENT_VERSION = Version.createOSGi(1, 2, 0); public static final VersionRange XML_TOLERANCE = new VersionRange(COMPATIBLE_VERSION, true, Version.createOSGi(2, 0, 0), false); // Constants for processing Instructions 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 20fc56a8d..024631745 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 @@ -12,11 +12,14 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.metadata.repository.io; +import static java.util.stream.Collectors.toList; + 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.*; +import org.eclipse.equinox.internal.p2.metadata.ArtifactKey; +import org.eclipse.equinox.internal.p2.metadata.InstallableUnit; import org.eclipse.equinox.internal.p2.persistence.XMLParser; import org.eclipse.equinox.p2.metadata.*; import org.eclipse.equinox.p2.metadata.MetadataFactory.*; @@ -30,18 +33,6 @@ import org.xml.sax.ContentHandler; public abstract class MetadataParser extends XMLParser implements XMLConstants { static final ILicense[] NO_LICENSES = new ILicense[0]; - static final String ATTR_TYPE_LIST_HEAD = "List<"; //$NON-NLS-1$ - static final String ATTR_TYPE_STRING = String.class.getSimpleName(); - static final String ATTR_TYPE_INTEGER = Integer.class.getSimpleName(); - static final String ATTR_TYPE_LONG = Long.class.getSimpleName(); - static final String ATTR_TYPE_FLOAT = Float.class.getSimpleName(); - static final String ATTR_TYPE_DOUBLE = Double.class.getSimpleName(); - static final String ATTR_TYPE_BYTE = Byte.class.getSimpleName(); - static final String ATTR_TYPE_SHORT = Short.class.getSimpleName(); - static final String ATTR_TYPE_CHARACTER = Character.class.getSimpleName(); - static final String ATTR_TYPE_BOOLEAN = Boolean.class.getSimpleName(); - static final String ATTR_TYPE_VERSION = Version.class.getSimpleName(); - public MetadataParser(BundleContext context, String bundleId) { super(context, bundleId); } @@ -322,7 +313,7 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { IProvidedCapability[] providedCapabilities = (providedCapabilitiesHandler == null ? new IProvidedCapability[0] : providedCapabilitiesHandler.getProvidedCapabilities()); currentUnit.setCapabilities(providedCapabilities); - IRequirement[] requiredCapabilities = (requiredCapabilitiesHandler == null ? new IRequirement[0] : requiredCapabilitiesHandler.getRequiredCapabilities()); + IRequirement[] requiredCapabilities = (requiredCapabilitiesHandler == null ? new IRequirement[0] : requiredCapabilitiesHandler.getRequirements()); currentUnit.setRequirements(requiredCapabilities); IRequirement[] metaRequiredCapabilities = (metaRequiredCapabilitiesHandler == null ? new IRequirement[0] : metaRequiredCapabilitiesHandler.getMetaRequiredCapabilities()); currentUnit.setMetaRequirements(metaRequiredCapabilities); @@ -389,7 +380,7 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { @Override protected void finished() { if (children != null) { - scopes.add(children.getRequiredCapabilities()); + scopes.add(children.getRequirements()); } } } @@ -517,7 +508,7 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { private String namespace; private String name; private Version version; - private ProvidedCapabilityAttributesHandler attributesHandler; + private ProvidedCapabilityPropertiesHandler propertiesHandler; private List<IProvidedCapability> capabilities; @@ -534,63 +525,68 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { @Override public void startElement(String elem, Attributes attributes) { - if (elem.equals(CAPABILITY_ATTRIBUTES_ELEMENT)) { - this.attributesHandler = new ProvidedCapabilityAttributesHandler(this, attributes); - } else { - invalidElement(elem, attributes); + switch (elem) { + case PROPERTIES_ELEMENT : + this.propertiesHandler = new ProvidedCapabilityPropertiesHandler(this, attributes); + break; + default : + invalidElement(elem, attributes); + break; } } @Override protected void finished() { - Map<String, Object> capAttrs = (attributesHandler != null) - ? attributesHandler.getAttributes() + Map<String, Object> properties = (propertiesHandler != null) + ? propertiesHandler.getProperties() : new HashMap<>(); - capAttrs.put(namespace, name); - capAttrs.put(ProvidedCapability.ATTRIBUTE_VERSION, version); - IProvidedCapability cap = MetadataFactory.createProvidedCapability(namespace, capAttrs); + properties.put(namespace, name); + properties.put(IProvidedCapability.PROPERTY_VERSION, version); + IProvidedCapability cap = MetadataFactory.createProvidedCapability(namespace, properties); capabilities.add(cap); } } - protected class ProvidedCapabilityAttributesHandler extends AbstractMetadataHandler { - private Map<String, Object> capAttributes; + protected class ProvidedCapabilityPropertiesHandler extends AbstractMetadataHandler { + private Map<String, Object> properties; - public ProvidedCapabilityAttributesHandler(AbstractHandler parentHandler, Attributes attributes) { - super(parentHandler, CAPABILITY_ATTRIBUTES_ELEMENT); - // TODO add getOptionalSize(attributes, 4) - this.capAttributes = new HashMap<>(); + public ProvidedCapabilityPropertiesHandler(AbstractHandler parentHandler, Attributes attributes) { + super(parentHandler, PROPERTIES_ELEMENT); + this.properties = new HashMap<>(getOptionalSize(attributes, 2)); } - public Map<String, Object> getAttributes() { - return capAttributes; + public Map<String, Object> getProperties() { + return properties; } @Override - public void startElement(String name, Attributes attributes) { - if (name.equals(CAPABILITY_ATTRIBUTE_ELEMENT)) { - new ProvidedCapabilityAttributeHandler(this, attributes, capAttributes); - } else { - invalidElement(name, attributes); + public void startElement(String elem, Attributes attributes) { + switch (elem) { + case PROPERTY_ELEMENT : + new ProvidedCapabilityPropertyHandler(this, attributes, properties); + break; + default : + invalidElement(elem, attributes); + break; } } } - protected class ProvidedCapabilityAttributeHandler extends AbstractMetadataHandler { - public ProvidedCapabilityAttributeHandler(AbstractHandler parentHandler, Attributes attributes, Map<String, Object> capAttributes) { - super(parentHandler, CAPABILITY_ATTRIBUTE_ELEMENT); + protected class ProvidedCapabilityPropertyHandler extends AbstractMetadataHandler { + public ProvidedCapabilityPropertyHandler(AbstractHandler parentHandler, Attributes attributes, Map<String, Object> properties) { + super(parentHandler, PROPERTY_ELEMENT); - String[] values = parseRequiredAttributes(attributes, CAPABILITY_ATTRIBUTE_REQUIRED_ATTRIBUTES); + String[] values = parseAttributes(attributes, PROPERTY_ATTRIBUTES, PROPERTY_OPTIONAL_ATTRIBUTES); String name = values[0]; String value = values[1]; - String type = values[2]; + String type = values[2] == null ? PROPERTY_TYPE_STRING : values[2]; - if (type.startsWith(ATTR_TYPE_LIST_HEAD)) { - capAttributes.put(name, parseList(type, value)); + if (type.startsWith(PROPERTY_TYPE_LIST)) { + properties.put(name, parseList(type, value)); } else { - capAttributes.put(name, parseScalar(type, value)); + properties.put(name, parseScalar(type, value)); } } @@ -600,49 +596,53 @@ 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<>(); - for (String el : value.split("\\s*,\\s*")) { //$NON-NLS-1$ - res.add(parseScalar(elType, el)); + final String elType; + if (type.length() > PROPERTY_TYPE_LIST.length()) { + // Strip the leading "List<" and trailing ">" + elType = type.substring(PROPERTY_TYPE_LIST.length() + 1, type.length() - 1); + } else { + elType = PROPERTY_TYPE_STRING; } - return res; + return Arrays.stream(value.split("\\s*,\\s*")) //$NON-NLS-1$ + .map(val -> parseScalar(elType, val)) + .collect(toList()); } private Object parseScalar(String type, String value) { - if (ATTR_TYPE_STRING.equals(type)) { + if (PROPERTY_TYPE_STRING.equals(type)) { return value; } - if (ATTR_TYPE_INTEGER.equals(type)) { + if (PROPERTY_TYPE_INTEGER.equals(type)) { return Integer.parseInt(value); } - if (ATTR_TYPE_LONG.equals(type)) { + if (PROPERTY_TYPE_LONG.equals(type)) { return Long.parseLong(value); } - if (ATTR_TYPE_FLOAT.equals(type)) { + if (PROPERTY_TYPE_FLOAT.equals(type)) { return Float.parseFloat(value); } - if (ATTR_TYPE_DOUBLE.equals(type)) { + if (PROPERTY_TYPE_DOUBLE.equals(type)) { return Double.parseDouble(value); } - if (ATTR_TYPE_BYTE.equals(type)) { + if (PROPERTY_TYPE_BYTE.equals(type)) { return Byte.parseByte(value); } - if (ATTR_TYPE_SHORT.equals(type)) { + if (PROPERTY_TYPE_SHORT.equals(type)) { return Short.parseShort(value); } - if (ATTR_TYPE_CHARACTER.equals(type)) { + if (PROPERTY_TYPE_CHARACTER.equals(type)) { return value.charAt(0); } - if (ATTR_TYPE_BOOLEAN.equals(type)) { + if (PROPERTY_TYPE_BOOLEAN.equals(type)) { return Boolean.parseBoolean(value); } - if (ATTR_TYPE_VERSION.equals(type)) { + if (PROPERTY_TYPE_VERSION.equals(type)) { return Version.create(value); } - // TODO Throw what? - return value.toString(); + + // String is the default + return value; } } @@ -691,23 +691,29 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { } protected class RequirementsHandler extends AbstractMetadataHandler { - private List<IRequirement> requiredCapabilities; + private List<IRequirement> requirements; public RequirementsHandler(AbstractHandler parentHandler, Attributes attributes) { super(parentHandler, REQUIREMENTS_ELEMENT); - requiredCapabilities = new ArrayList<>(getOptionalSize(attributes, 4)); + requirements = new ArrayList<>(getOptionalSize(attributes, 4)); } - public IRequirement[] getRequiredCapabilities() { - return requiredCapabilities.toArray(new IRequirement[requiredCapabilities.size()]); + public IRequirement[] getRequirements() { + return requirements.toArray(new IRequirement[requirements.size()]); } @Override public void startElement(String name, Attributes attributes) { - if (name.equals(REQUIREMENT_ELEMENT)) { - new RequirementHandler(this, attributes, requiredCapabilities); - } else { - invalidElement(name, attributes); + switch (name) { + case REQUIREMENT_ELEMENT : + new RequirementHandler(this, attributes, requirements); + break; + case REQUIREMENT_PROPERTIES_ELEMENT : + new RequirementPropertiesHandler(this, attributes, requirements); + break; + default : + invalidElement(name, attributes); + break; } } } @@ -734,31 +740,34 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { public RequirementHandler(AbstractHandler parentHandler, Attributes attributes, List<IRequirement> capabilities) { super(parentHandler, REQUIREMENT_ELEMENT); this.capabilities = capabilities; + + // Version range requirement if (attributes.getIndex(NAMESPACE_ATTRIBUTE) >= 0) { - String[] values = parseAttributes(attributes, REQIURED_CAPABILITY_ATTRIBUTES, OPTIONAL_CAPABILITY_ATTRIBUTES); + String[] values = parseAttributes(attributes, REQIURED_CAPABILITY_ATTRIBUTES, REQUIRED_CAPABILITY_OPTIONAL_ATTRIBUTES); namespace = values[0]; name = values[1]; range = checkVersionRange(REQUIREMENT_ELEMENT, VERSION_RANGE_ATTRIBUTE, values[2]); - boolean isOptional = checkBoolean(REQUIREMENT_ELEMENT, CAPABILITY_OPTIONAL_ATTRIBUTE, values[3], false).booleanValue(); + boolean isOptional = checkBoolean(REQUIREMENT_ELEMENT, REQUIRED_CAPABILITY_OPTIONAL_ATTRIBUTE, values[3], false).booleanValue(); min = isOptional ? 0 : 1; - boolean isMultiple = checkBoolean(REQUIREMENT_ELEMENT, CAPABILITY_MULTIPLE_ATTRIBUTE, values[4], false).booleanValue(); + boolean isMultiple = checkBoolean(REQUIREMENT_ELEMENT, REQUIRED_CAPABILITY_MULTIPLE_ATTRIBUTE, values[4], false).booleanValue(); max = isMultiple ? Integer.MAX_VALUE : 1; - greedy = checkBoolean(REQUIREMENT_ELEMENT, CAPABILITY_GREED_ATTRIBUTE, values[5], true).booleanValue(); - } else { - // Expression based requirement - String[] values = parseAttributes(attributes, REQIUREMENT_ATTRIBUTES, OPTIONAL_REQUIREMENT_ATTRIBUTES); + greedy = checkBoolean(REQUIREMENT_ELEMENT, REQUIREMENT_GREED_ATTRIBUTE, values[5], true).booleanValue(); + } + // IU match expression requirement + else { + String[] values = parseAttributes(attributes, REQUIRED_IU_MATCH_ATTRIBUTES, REQUIRED_IU_MATCH_OPTIONAL_ATTRIBUTES); match = values[0]; matchParams = values[1]; min = values[2] == null ? 1 : checkInteger(REQUIREMENT_ELEMENT, MIN_ATTRIBUTE, values[2]); max = values[3] == null ? 1 : checkInteger(REQUIREMENT_ELEMENT, MAX_ATTRIBUTE, values[3]); - greedy = checkBoolean(REQUIREMENT_ELEMENT, CAPABILITY_GREED_ATTRIBUTE, values[4], true).booleanValue(); + greedy = checkBoolean(REQUIREMENT_ELEMENT, REQUIREMENT_GREED_ATTRIBUTE, values[4], true).booleanValue(); } } @Override public void startElement(String elem, Attributes attributes) { - if (elem.equals(CAPABILITY_FILTER_ELEMENT)) { - filterHandler = new TextHandler(this, CAPABILITY_FILTER_ELEMENT, attributes); + if (elem.equals(REQUIREMENT_FILTER_ELEMENT)) { + filterHandler = new TextHandler(this, REQUIREMENT_FILTER_ELEMENT, attributes); } else if (elem.equals(REQUIREMENT_DESCRIPTION_ELEMENT)) { descriptionHandler = new TextHandler(this, REQUIREMENT_DESCRIPTION_ELEMENT, attributes); } else { @@ -805,6 +814,83 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { } } + protected class RequirementPropertiesHandler extends AbstractHandler { + private List<IRequirement> requirements; + + private String namespace; + private String match; + private int min; + private int max; + private boolean greedy; + + private TextHandler filterHandler; + private TextHandler descriptionHandler; + + public RequirementPropertiesHandler(AbstractHandler parentHandler, Attributes attributes, List<IRequirement> requirements) { + super(parentHandler, REQUIREMENT_PROPERTIES_ELEMENT); + this.requirements = requirements; + + String[] values = parseAttributes(attributes, REQIURED_PROPERTIES_MATCH_ATTRIBUTES, REQIURED_PROPERTIES_MATCH_OPTIONAL_ATTRIBUTES); + namespace = values[0]; + match = values[1]; + min = (values[2] == null) ? 1 : checkInteger(REQUIREMENT_PROPERTIES_ELEMENT, MIN_ATTRIBUTE, values[2]); + max = (values[3] == null) ? 1 : checkInteger(REQUIREMENT_PROPERTIES_ELEMENT, MAX_ATTRIBUTE, values[3]); + greedy = checkBoolean(REQUIREMENT_PROPERTIES_ELEMENT, REQUIREMENT_GREED_ATTRIBUTE, values[4], true).booleanValue(); + } + + @Override + public void startElement(String elem, Attributes attributes) { + switch (elem) { + case REQUIREMENT_FILTER_ELEMENT : + filterHandler = new TextHandler(this, REQUIREMENT_FILTER_ELEMENT, attributes); + break; + case REQUIREMENT_DESCRIPTION_ELEMENT : + descriptionHandler = new TextHandler(this, REQUIREMENT_DESCRIPTION_ELEMENT, attributes); + break; + default : + invalidElement(elem, attributes); + break; + } + } + + @Override + protected void finished() { + if (!isValidXML()) { + return; + } + + IMatchExpression<IInstallableUnit> filter = null; + if (filterHandler != null) { + try { + filter = InstallableUnit.parseFilter(filterHandler.getText()); + } catch (ExpressionParseException e) { + if (removeWhiteSpace(filterHandler.getText()).equals("(&(|)(|)(|))")) {//$NON-NLS-1$ + // We could log this I guess + } else { + throw e; + } + } + } + + String description = (descriptionHandler != null) ? descriptionHandler.getText() : null; + + IFilterExpression attrMatch = ExpressionUtil.parseLDAP(match); + IRequirement requirement = MetadataFactory.createRequirement(namespace, attrMatch, filter, min, max, greedy, description); + requirements.add(requirement); + } + + private String removeWhiteSpace(String s) { + if (s == null) + return ""; //$NON-NLS-1$ + StringBuffer builder = new StringBuffer(); + for (int i = 0; i < s.length(); i++) { + if (s.charAt(i) != ' ') + builder.append(s.charAt(i)); + } + return builder.toString(); + } + } + protected class ArtifactsHandler extends AbstractHandler { private List<IArtifactKey> artifacts; 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 2b7686e35..f88d52bdd 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 @@ -14,11 +14,10 @@ package org.eclipse.equinox.internal.p2.metadata.repository.io; import java.io.OutputStream; import java.net.MalformedURLException; 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.RequiredPropertiesMatch; import org.eclipse.equinox.internal.p2.metadata.repository.Activator; import org.eclipse.equinox.internal.p2.persistence.XMLWriter; import org.eclipse.equinox.p2.metadata.*; @@ -96,23 +95,23 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { private boolean hasOnlySimpleRequirements(IInstallableUnit iu) { for (IRequirement r : iu.getRequirements()) - if (r.getMax() == 0 || !RequiredCapability.isSimpleRequirement(r.getMatches())) + if (r.getMax() == 0 || !RequiredCapability.isVersionRangeRequirement(r.getMatches())) return false; if (iu.getUpdateDescriptor() != null) { for (IMatchExpression<IInstallableUnit> m : iu.getUpdateDescriptor().getIUsBeingUpdated()) { - if (!RequiredCapability.isSimpleRequirement(m)) + if (!RequiredCapability.isVersionRangeRequirement(m)) return false; } } for (IRequirement r : iu.getMetaRequirements()) - if (r.getMax() == 0 || !RequiredCapability.isSimpleRequirement(r.getMatches())) + if (r.getMax() == 0 || !RequiredCapability.isVersionRangeRequirement(r.getMatches())) return false; if (iu instanceof IInstallableUnitFragment) { for (IRequirement r : ((IInstallableUnitFragment) iu).getHost()) - if (!RequiredCapability.isSimpleRequirement(r.getMatches())) + if (!RequiredCapability.isVersionRangeRequirement(r.getMatches())) return false; } @@ -120,11 +119,11 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { IInstallableUnitPatch iuPatch = (IInstallableUnitPatch) iu; for (IRequirement[] rArr : iuPatch.getApplicabilityScope()) for (IRequirement r : rArr) - if (!RequiredCapability.isSimpleRequirement(r.getMatches())) + if (!RequiredCapability.isVersionRangeRequirement(r.getMatches())) return false; IRequirement lifeCycle = iuPatch.getLifeCycle(); - if (lifeCycle != null && !RequiredCapability.isSimpleRequirement(lifeCycle.getMatches())) + if (lifeCycle != null && !RequiredCapability.isVersionRangeRequirement(lifeCycle.getMatches())) return false; } return true; @@ -167,50 +166,12 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { attribute(NAME_ATTRIBUTE, capability.getName()); attribute(VERSION_ATTRIBUTE, capability.getVersion()); - Map<String, Object> attrs = new HashMap<>(capability.getAttributes()); - attrs.remove(capability.getNamespace()); - attrs.remove(ProvidedCapability.ATTRIBUTE_VERSION); + Map<String, Object> props = new HashMap<>(capability.getProperties()); + props.remove(capability.getNamespace()); + props.remove(IProvidedCapability.PROPERTY_VERSION); - if (!attrs.isEmpty()) { - start(CAPABILITY_ATTRIBUTES_ELEMENT); - attribute(COLLECTION_SIZE_ATTRIBUTE, attrs.size()); - - for (Entry<String, Object> attr : attrs.entrySet()) { - start(CAPABILITY_ATTRIBUTE_ELEMENT); - - String name = attr.getKey(); - Object val = attr.getValue(); - String type; - - if (Collection.class.isAssignableFrom(val.getClass())) { - Collection<?> coll = (Collection<?>) val; - - String elType = coll.iterator().next().getClass().getSimpleName(); - type = String.format("List<%s>", elType); //$NON-NLS-1$ - - StringBuilder valBuff = new StringBuilder(); - for (Iterator<?> iter = coll.iterator(); iter.hasNext();) { - String el = iter.next().toString(); - - valBuff.append(el); - if (iter.hasNext()) { - valBuff.append(","); //$NON-NLS-1$ - } - } - - val = valBuff.toString(); - } else { - type = val.getClass().getSimpleName(); - val = val.toString(); - } - - attribute(CAPABILITY_ATTRIBUTE_NAME_ATTRIBUTE, name); - attribute(CAPABILITY_ATTRIBUTE_TYPE_ATTRIBUTE, type); - attribute(CAPABILITY_ATTRIBUTE_VALUE_ATTRIBUTE, val); - - end(CAPABILITY_ATTRIBUTE_ELEMENT); - } - end(CAPABILITY_ATTRIBUTES_ELEMENT); + if (!props.isEmpty()) { + writeProperties(props); } end(PROVIDED_CAPABILITY_ELEMENT); @@ -246,7 +207,7 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { throw new IllegalStateException(); IMatchExpression<IInstallableUnit> singleUD = descriptor.getIUsBeingUpdated().iterator().next(); start(UPDATE_DESCRIPTOR_ELEMENT); - if (RequiredCapability.isSimpleRequirement(singleUD)) { + if (RequiredCapability.isVersionRangeRequirement(singleUD)) { attribute(ID_ATTRIBUTE, RequiredCapability.extractName(singleUD)); attribute(VERSION_RANGE_ATTRIBUTE, RequiredCapability.extractRange(singleUD)); } else { @@ -291,27 +252,59 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { } protected void writeRequirement(IRequirement requirement) { - start(REQUIREMENT_ELEMENT); IMatchExpression<IInstallableUnit> match = requirement.getMatches(); - if (requirement.getMax() > 0 && RequiredCapability.isSimpleRequirement(match)) { + + // A (namespace, name, version-range) type of requirement + if (requirement.getMax() > 0 && RequiredCapability.isVersionRangeRequirement(match)) { + start(REQUIREMENT_ELEMENT); + attribute(NAMESPACE_ATTRIBUTE, RequiredCapability.extractNamespace(match)); attribute(NAME_ATTRIBUTE, RequiredCapability.extractName(match)); attribute(VERSION_RANGE_ATTRIBUTE, RequiredCapability.extractRange(match)); - attribute(CAPABILITY_OPTIONAL_ATTRIBUTE, requirement.getMin() == 0, false); - attribute(CAPABILITY_MULTIPLE_ATTRIBUTE, requirement.getMax() > 1, false); - } else { + attribute(REQUIRED_CAPABILITY_OPTIONAL_ATTRIBUTE, requirement.getMin() == 0, false); + attribute(REQUIRED_CAPABILITY_MULTIPLE_ATTRIBUTE, requirement.getMax() > 1, false); + } + // A (namespace, attributes-match) type of requirement + else if (RequiredPropertiesMatch.isPropertiesMatchRequirement(match)) { + start(REQUIREMENT_PROPERTIES_ELEMENT); + + attribute(NAMESPACE_ATTRIBUTE, RequiredPropertiesMatch.extractNamespace(match)); + attribute(MATCH_ATTRIBUTE, RequiredPropertiesMatch.extractPropertiesMatch(match)); + + if (requirement.getMin() != 1) { + attribute(MIN_ATTRIBUTE, requirement.getMin()); + } + + if (requirement.getMax() != 1) { + attribute(MAX_ATTRIBUTE, requirement.getMax()); + } + } + // A general match expression type of requirement + else { + start(REQUIREMENT_ELEMENT); + writeMatchExpression(match); - if (requirement.getMin() != 1) + + if (requirement.getMin() != 1) { attribute(MIN_ATTRIBUTE, requirement.getMin()); - if (requirement.getMax() != 1) + } + + if (requirement.getMax() != 1) { attribute(MAX_ATTRIBUTE, requirement.getMax()); + } + } + + attribute(REQUIREMENT_GREED_ATTRIBUTE, requirement.isGreedy(), true); + + if (requirement.getFilter() != null) { + writeTrimmedCdata(REQUIREMENT_FILTER_ELEMENT, requirement.getFilter().getParameters()[0].toString()); } - attribute(CAPABILITY_GREED_ATTRIBUTE, requirement.isGreedy(), true); - if (requirement.getFilter() != null) - writeTrimmedCdata(CAPABILITY_FILTER_ELEMENT, requirement.getFilter().getParameters()[0].toString()); - if (requirement.getDescription() != null) + + if (requirement.getDescription() != null) { writeTrimmedCdata(REQUIREMENT_DESCRIPTION_ELEMENT, requirement.getDescription()); - end(REQUIREMENT_ELEMENT); + } + + end(); } private void writeMatchExpression(IMatchExpression<IInstallableUnit> match) { diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java index 44db99925..621356e4a 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java @@ -39,9 +39,7 @@ public interface XMLConstants extends org.eclipse.equinox.internal.p2.persistenc public static final String REQUIREMENTS_ELEMENT = "requires"; //$NON-NLS-1$ public static final String HOST_REQUIREMENTS_ELEMENT = "hostRequirements"; //$NON-NLS-1$ public static final String META_REQUIREMENTS_ELEMENT = "metaRequirements"; //$NON-NLS-1$ - public static final String REQUIREMENT_ELEMENT = "required"; //$NON-NLS-1$ public static final String PROVIDED_CAPABILITIES_ELEMENT = "provides"; //$NON-NLS-1$ - public static final String PROVIDED_CAPABILITY_ELEMENT = "provided"; //$NON-NLS-1$ public static final String[] REQUIRED_PROVIDED_CAPABILITY_ATTRIBUTES = new String[] {NAMESPACE_ATTRIBUTE, NAME_ATTRIBUTE, VERSION_ATTRIBUTE}; public static final String TOUCHPOINT_TYPE_ELEMENT = "touchpoint"; //$NON-NLS-1$ public static final String TOUCHPOINT_DATA_ELEMENT = "touchpointData"; //$NON-NLS-1$ @@ -63,26 +61,26 @@ public interface XMLConstants extends org.eclipse.equinox.internal.p2.persistenc public static final String[] OPTIONAL_IU_ATTRIBUTES = new String[] {SINGLETON_ATTRIBUTE}; public static final String GENERATION_ATTRIBUTE = "generation"; //$NON-NLS-1$ + // Constants for the provided capability element + public static final String PROVIDED_CAPABILITY_ELEMENT = "provided"; //$NON-NLS-1$ + // Constants for sub-elements of a required capability element - public static final String CAPABILITY_FILTER_ELEMENT = "filter"; //$NON-NLS-1$ + public static final String REQUIREMENT_ELEMENT = "required"; //$NON-NLS-1$ + public static final String REQUIREMENT_PROPERTIES_ELEMENT = "requiredProperties"; //$NON-NLS-1$ + public static final String REQUIREMENT_FILTER_ELEMENT = "filter"; //$NON-NLS-1$ public static final String REQUIREMENT_DESCRIPTION_ELEMENT = "description"; //$NON-NLS-1$ + public static final String REQUIREMENT_GREED_ATTRIBUTE = "greedy"; //$NON-NLS-1$ - // Constants for attributes of a required capability element - public static final String CAPABILITY_OPTIONAL_ATTRIBUTE = "optional"; //$NON-NLS-1$ - public static final String CAPABILITY_MULTIPLE_ATTRIBUTE = "multiple"; //$NON-NLS-1$ - public static final String CAPABILITY_GREED_ATTRIBUTE = "greedy"; //$NON-NLS-1$ + public static final String REQUIRED_CAPABILITY_OPTIONAL_ATTRIBUTE = "optional"; //$NON-NLS-1$ + public static final String REQUIRED_CAPABILITY_MULTIPLE_ATTRIBUTE = "multiple"; //$NON-NLS-1$ + public static final String[] REQIURED_CAPABILITY_ATTRIBUTES = new String[] {NAMESPACE_ATTRIBUTE, NAME_ATTRIBUTE, VERSION_RANGE_ATTRIBUTE}; + public static final String[] REQUIRED_CAPABILITY_OPTIONAL_ATTRIBUTES = new String[] {REQUIRED_CAPABILITY_OPTIONAL_ATTRIBUTE, REQUIRED_CAPABILITY_MULTIPLE_ATTRIBUTE, REQUIREMENT_GREED_ATTRIBUTE}; - public static final String CAPABILITY_ATTRIBUTES_ELEMENT = "attributes"; //$NON-NLS-1$ - public static final String CAPABILITY_ATTRIBUTE_ELEMENT = "attribute"; //$NON-NLS-1$ - public static final String CAPABILITY_ATTRIBUTE_NAME_ATTRIBUTE = "name"; //$NON-NLS-1$ - public static final String CAPABILITY_ATTRIBUTE_TYPE_ATTRIBUTE = "type"; //$NON-NLS-1$ - public static final String CAPABILITY_ATTRIBUTE_VALUE_ATTRIBUTE = "value"; //$NON-NLS-1$ - public static final String[] CAPABILITY_ATTRIBUTE_REQUIRED_ATTRIBUTES = new String[] {CAPABILITY_ATTRIBUTE_NAME_ATTRIBUTE, CAPABILITY_ATTRIBUTE_VALUE_ATTRIBUTE, CAPABILITY_ATTRIBUTE_TYPE_ATTRIBUTE}; + public static final String[] REQIURED_PROPERTIES_MATCH_ATTRIBUTES = new String[] {NAMESPACE_ATTRIBUTE, MATCH_ATTRIBUTE}; + public static final String[] REQIURED_PROPERTIES_MATCH_OPTIONAL_ATTRIBUTES = new String[] {MIN_ATTRIBUTE, MAX_ATTRIBUTE, REQUIREMENT_GREED_ATTRIBUTE}; - public static final String[] REQIURED_CAPABILITY_ATTRIBUTES = new String[] {NAMESPACE_ATTRIBUTE, NAME_ATTRIBUTE, VERSION_RANGE_ATTRIBUTE}; - public static final String[] REQIUREMENT_ATTRIBUTES = new String[] {MATCH_ATTRIBUTE}; - public static final String[] OPTIONAL_CAPABILITY_ATTRIBUTES = new String[] {CAPABILITY_OPTIONAL_ATTRIBUTE, CAPABILITY_MULTIPLE_ATTRIBUTE, CAPABILITY_GREED_ATTRIBUTE}; - public static final String[] OPTIONAL_REQUIREMENT_ATTRIBUTES = new String[] {MATCH_PARAMETERS_ATTRIBUTE, MIN_ATTRIBUTE, MAX_ATTRIBUTE, CAPABILITY_GREED_ATTRIBUTE}; + public static final String[] REQUIRED_IU_MATCH_ATTRIBUTES = new String[] {MATCH_ATTRIBUTE}; + public static final String[] REQUIRED_IU_MATCH_OPTIONAL_ATTRIBUTES = new String[] {MATCH_PARAMETERS_ATTRIBUTE, MIN_ATTRIBUTE, MAX_ATTRIBUTE, REQUIREMENT_GREED_ATTRIBUTE}; // Constants for attributes of an artifact key element public static final String ARTIFACT_KEY_CLASSIFIER_ATTRIBUTE = "classifier"; //$NON-NLS-1$ |