diff options
author | Thomas Watson | 2018-01-22 17:45:31 +0000 |
---|---|---|
committer | Thomas Watson | 2018-01-22 17:45:31 +0000 |
commit | 0e3caa9359428dcb20c1dc3a2c580fff64777d3d (patch) | |
tree | 491a0aa61382ad685c708f7c5c3943af043f5738 /bundles/org.eclipse.equinox.p2.metadata.repository | |
parent | 81563662fc363e85f9311289f2e9026ecfacd390 (diff) | |
download | rt.equinox.p2-0e3caa9359428dcb20c1dc3a2c580fff64777d3d.tar.gz rt.equinox.p2-0e3caa9359428dcb20c1dc3a2c580fff64777d3d.tar.xz rt.equinox.p2-0e3caa9359428dcb20c1dc3a2c580fff64777d3d.zip |
Revert "Bug 528387 - Dedicated xml elements for generic requirements"
This reverts commit a7a99e1fa49938a8f62d44d5c443d38981afeace.
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.metadata.repository')
4 files changed, 164 insertions, 241 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 4243ad59d..ed67c081a 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, 2, 0); + public static final Version CURRENT_VERSION = Version.createOSGi(1, 1, 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 024631745..20fc56a8d 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,14 +12,11 @@ *******************************************************************************/ 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.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.*; @@ -33,6 +30,18 @@ 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); } @@ -313,7 +322,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.getRequirements()); + IRequirement[] requiredCapabilities = (requiredCapabilitiesHandler == null ? new IRequirement[0] : requiredCapabilitiesHandler.getRequiredCapabilities()); currentUnit.setRequirements(requiredCapabilities); IRequirement[] metaRequiredCapabilities = (metaRequiredCapabilitiesHandler == null ? new IRequirement[0] : metaRequiredCapabilitiesHandler.getMetaRequiredCapabilities()); currentUnit.setMetaRequirements(metaRequiredCapabilities); @@ -380,7 +389,7 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { @Override protected void finished() { if (children != null) { - scopes.add(children.getRequirements()); + scopes.add(children.getRequiredCapabilities()); } } } @@ -508,7 +517,7 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { private String namespace; private String name; private Version version; - private ProvidedCapabilityPropertiesHandler propertiesHandler; + private ProvidedCapabilityAttributesHandler attributesHandler; private List<IProvidedCapability> capabilities; @@ -525,68 +534,63 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { @Override public void startElement(String elem, Attributes attributes) { - switch (elem) { - case PROPERTIES_ELEMENT : - this.propertiesHandler = new ProvidedCapabilityPropertiesHandler(this, attributes); - break; - default : - invalidElement(elem, attributes); - break; + if (elem.equals(CAPABILITY_ATTRIBUTES_ELEMENT)) { + this.attributesHandler = new ProvidedCapabilityAttributesHandler(this, attributes); + } else { + invalidElement(elem, attributes); } } @Override protected void finished() { - Map<String, Object> properties = (propertiesHandler != null) - ? propertiesHandler.getProperties() + Map<String, Object> capAttrs = (attributesHandler != null) + ? attributesHandler.getAttributes() : new HashMap<>(); - properties.put(namespace, name); - properties.put(IProvidedCapability.PROPERTY_VERSION, version); - IProvidedCapability cap = MetadataFactory.createProvidedCapability(namespace, properties); + capAttrs.put(namespace, name); + capAttrs.put(ProvidedCapability.ATTRIBUTE_VERSION, version); + IProvidedCapability cap = MetadataFactory.createProvidedCapability(namespace, capAttrs); capabilities.add(cap); } } - protected class ProvidedCapabilityPropertiesHandler extends AbstractMetadataHandler { - private Map<String, Object> properties; + protected class ProvidedCapabilityAttributesHandler extends AbstractMetadataHandler { + private Map<String, Object> capAttributes; - public ProvidedCapabilityPropertiesHandler(AbstractHandler parentHandler, Attributes attributes) { - super(parentHandler, PROPERTIES_ELEMENT); - this.properties = new HashMap<>(getOptionalSize(attributes, 2)); + public ProvidedCapabilityAttributesHandler(AbstractHandler parentHandler, Attributes attributes) { + super(parentHandler, CAPABILITY_ATTRIBUTES_ELEMENT); + // TODO add getOptionalSize(attributes, 4) + this.capAttributes = new HashMap<>(); } - public Map<String, Object> getProperties() { - return properties; + public Map<String, Object> getAttributes() { + return capAttributes; } @Override - public void startElement(String elem, Attributes attributes) { - switch (elem) { - case PROPERTY_ELEMENT : - new ProvidedCapabilityPropertyHandler(this, attributes, properties); - break; - default : - invalidElement(elem, attributes); - break; + public void startElement(String name, Attributes attributes) { + if (name.equals(CAPABILITY_ATTRIBUTE_ELEMENT)) { + new ProvidedCapabilityAttributeHandler(this, attributes, capAttributes); + } else { + invalidElement(name, attributes); } } } - protected class ProvidedCapabilityPropertyHandler extends AbstractMetadataHandler { - public ProvidedCapabilityPropertyHandler(AbstractHandler parentHandler, Attributes attributes, Map<String, Object> properties) { - super(parentHandler, PROPERTY_ELEMENT); + protected class ProvidedCapabilityAttributeHandler extends AbstractMetadataHandler { + public ProvidedCapabilityAttributeHandler(AbstractHandler parentHandler, Attributes attributes, Map<String, Object> capAttributes) { + super(parentHandler, CAPABILITY_ATTRIBUTE_ELEMENT); - String[] values = parseAttributes(attributes, PROPERTY_ATTRIBUTES, PROPERTY_OPTIONAL_ATTRIBUTES); + String[] values = parseRequiredAttributes(attributes, CAPABILITY_ATTRIBUTE_REQUIRED_ATTRIBUTES); String name = values[0]; String value = values[1]; - String type = values[2] == null ? PROPERTY_TYPE_STRING : values[2]; + String type = values[2]; - if (type.startsWith(PROPERTY_TYPE_LIST)) { - properties.put(name, parseList(type, value)); + if (type.startsWith(ATTR_TYPE_LIST_HEAD)) { + capAttributes.put(name, parseList(type, value)); } else { - properties.put(name, parseScalar(type, value)); + capAttributes.put(name, parseScalar(type, value)); } } @@ -596,53 +600,49 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { } private List<Object> parseList(String type, String value) { - 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; + 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)); } - return Arrays.stream(value.split("\\s*,\\s*")) //$NON-NLS-1$ - .map(val -> parseScalar(elType, val)) - .collect(toList()); + return res; } private Object parseScalar(String type, String value) { - if (PROPERTY_TYPE_STRING.equals(type)) { + if (ATTR_TYPE_STRING.equals(type)) { return value; } - if (PROPERTY_TYPE_INTEGER.equals(type)) { + if (ATTR_TYPE_INTEGER.equals(type)) { return Integer.parseInt(value); } - if (PROPERTY_TYPE_LONG.equals(type)) { + if (ATTR_TYPE_LONG.equals(type)) { return Long.parseLong(value); } - if (PROPERTY_TYPE_FLOAT.equals(type)) { + if (ATTR_TYPE_FLOAT.equals(type)) { return Float.parseFloat(value); } - if (PROPERTY_TYPE_DOUBLE.equals(type)) { + if (ATTR_TYPE_DOUBLE.equals(type)) { return Double.parseDouble(value); } - if (PROPERTY_TYPE_BYTE.equals(type)) { + if (ATTR_TYPE_BYTE.equals(type)) { return Byte.parseByte(value); } - if (PROPERTY_TYPE_SHORT.equals(type)) { + if (ATTR_TYPE_SHORT.equals(type)) { return Short.parseShort(value); } - if (PROPERTY_TYPE_CHARACTER.equals(type)) { + if (ATTR_TYPE_CHARACTER.equals(type)) { return value.charAt(0); } - if (PROPERTY_TYPE_BOOLEAN.equals(type)) { + if (ATTR_TYPE_BOOLEAN.equals(type)) { return Boolean.parseBoolean(value); } - if (PROPERTY_TYPE_VERSION.equals(type)) { + if (ATTR_TYPE_VERSION.equals(type)) { return Version.create(value); } - - // String is the default - return value; + // TODO Throw what? + return value.toString(); } } @@ -691,29 +691,23 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { } protected class RequirementsHandler extends AbstractMetadataHandler { - private List<IRequirement> requirements; + private List<IRequirement> requiredCapabilities; public RequirementsHandler(AbstractHandler parentHandler, Attributes attributes) { super(parentHandler, REQUIREMENTS_ELEMENT); - requirements = new ArrayList<>(getOptionalSize(attributes, 4)); + requiredCapabilities = new ArrayList<>(getOptionalSize(attributes, 4)); } - public IRequirement[] getRequirements() { - return requirements.toArray(new IRequirement[requirements.size()]); + public IRequirement[] getRequiredCapabilities() { + return requiredCapabilities.toArray(new IRequirement[requiredCapabilities.size()]); } @Override public void startElement(String name, Attributes 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; + if (name.equals(REQUIREMENT_ELEMENT)) { + new RequirementHandler(this, attributes, requiredCapabilities); + } else { + invalidElement(name, attributes); } } } @@ -740,34 +734,31 @@ 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, REQUIRED_CAPABILITY_OPTIONAL_ATTRIBUTES); + String[] values = parseAttributes(attributes, REQIURED_CAPABILITY_ATTRIBUTES, OPTIONAL_CAPABILITY_ATTRIBUTES); namespace = values[0]; name = values[1]; range = checkVersionRange(REQUIREMENT_ELEMENT, VERSION_RANGE_ATTRIBUTE, values[2]); - boolean isOptional = checkBoolean(REQUIREMENT_ELEMENT, REQUIRED_CAPABILITY_OPTIONAL_ATTRIBUTE, values[3], false).booleanValue(); + boolean isOptional = checkBoolean(REQUIREMENT_ELEMENT, CAPABILITY_OPTIONAL_ATTRIBUTE, values[3], false).booleanValue(); min = isOptional ? 0 : 1; - boolean isMultiple = checkBoolean(REQUIREMENT_ELEMENT, REQUIRED_CAPABILITY_MULTIPLE_ATTRIBUTE, values[4], false).booleanValue(); + boolean isMultiple = checkBoolean(REQUIREMENT_ELEMENT, CAPABILITY_MULTIPLE_ATTRIBUTE, values[4], false).booleanValue(); max = isMultiple ? Integer.MAX_VALUE : 1; - 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); + greedy = checkBoolean(REQUIREMENT_ELEMENT, CAPABILITY_GREED_ATTRIBUTE, values[5], true).booleanValue(); + } else { + // Expression based requirement + String[] values = parseAttributes(attributes, REQIUREMENT_ATTRIBUTES, OPTIONAL_REQUIREMENT_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, REQUIREMENT_GREED_ATTRIBUTE, values[4], true).booleanValue(); + greedy = checkBoolean(REQUIREMENT_ELEMENT, CAPABILITY_GREED_ATTRIBUTE, values[4], true).booleanValue(); } } @Override public void startElement(String elem, Attributes attributes) { - if (elem.equals(REQUIREMENT_FILTER_ELEMENT)) { - filterHandler = new TextHandler(this, REQUIREMENT_FILTER_ELEMENT, attributes); + if (elem.equals(CAPABILITY_FILTER_ELEMENT)) { + filterHandler = new TextHandler(this, CAPABILITY_FILTER_ELEMENT, attributes); } else if (elem.equals(REQUIREMENT_DESCRIPTION_ELEMENT)) { descriptionHandler = new TextHandler(this, REQUIREMENT_DESCRIPTION_ELEMENT, attributes); } else { @@ -814,83 +805,6 @@ 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 f88d52bdd..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 @@ -14,10 +14,11 @@ 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.*; @@ -95,23 +96,23 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { private boolean hasOnlySimpleRequirements(IInstallableUnit iu) { for (IRequirement r : iu.getRequirements()) - if (r.getMax() == 0 || !RequiredCapability.isVersionRangeRequirement(r.getMatches())) + if (r.getMax() == 0 || !RequiredCapability.isSimpleRequirement(r.getMatches())) return false; if (iu.getUpdateDescriptor() != null) { for (IMatchExpression<IInstallableUnit> m : iu.getUpdateDescriptor().getIUsBeingUpdated()) { - if (!RequiredCapability.isVersionRangeRequirement(m)) + if (!RequiredCapability.isSimpleRequirement(m)) return false; } } for (IRequirement r : iu.getMetaRequirements()) - if (r.getMax() == 0 || !RequiredCapability.isVersionRangeRequirement(r.getMatches())) + if (r.getMax() == 0 || !RequiredCapability.isSimpleRequirement(r.getMatches())) return false; if (iu instanceof IInstallableUnitFragment) { for (IRequirement r : ((IInstallableUnitFragment) iu).getHost()) - if (!RequiredCapability.isVersionRangeRequirement(r.getMatches())) + if (!RequiredCapability.isSimpleRequirement(r.getMatches())) return false; } @@ -119,11 +120,11 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { IInstallableUnitPatch iuPatch = (IInstallableUnitPatch) iu; for (IRequirement[] rArr : iuPatch.getApplicabilityScope()) for (IRequirement r : rArr) - if (!RequiredCapability.isVersionRangeRequirement(r.getMatches())) + if (!RequiredCapability.isSimpleRequirement(r.getMatches())) return false; IRequirement lifeCycle = iuPatch.getLifeCycle(); - if (lifeCycle != null && !RequiredCapability.isVersionRangeRequirement(lifeCycle.getMatches())) + if (lifeCycle != null && !RequiredCapability.isSimpleRequirement(lifeCycle.getMatches())) return false; } return true; @@ -166,12 +167,50 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { attribute(NAME_ATTRIBUTE, capability.getName()); attribute(VERSION_ATTRIBUTE, capability.getVersion()); - Map<String, Object> props = new HashMap<>(capability.getProperties()); - props.remove(capability.getNamespace()); - props.remove(IProvidedCapability.PROPERTY_VERSION); + Map<String, Object> attrs = new HashMap<>(capability.getAttributes()); + attrs.remove(capability.getNamespace()); + attrs.remove(ProvidedCapability.ATTRIBUTE_VERSION); - if (!props.isEmpty()) { - writeProperties(props); + 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); } end(PROVIDED_CAPABILITY_ELEMENT); @@ -207,7 +246,7 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { throw new IllegalStateException(); IMatchExpression<IInstallableUnit> singleUD = descriptor.getIUsBeingUpdated().iterator().next(); start(UPDATE_DESCRIPTOR_ELEMENT); - if (RequiredCapability.isVersionRangeRequirement(singleUD)) { + if (RequiredCapability.isSimpleRequirement(singleUD)) { attribute(ID_ATTRIBUTE, RequiredCapability.extractName(singleUD)); attribute(VERSION_RANGE_ATTRIBUTE, RequiredCapability.extractRange(singleUD)); } else { @@ -252,59 +291,27 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { } protected void writeRequirement(IRequirement requirement) { + start(REQUIREMENT_ELEMENT); IMatchExpression<IInstallableUnit> match = requirement.getMatches(); - - // A (namespace, name, version-range) type of requirement - if (requirement.getMax() > 0 && RequiredCapability.isVersionRangeRequirement(match)) { - start(REQUIREMENT_ELEMENT); - + if (requirement.getMax() > 0 && RequiredCapability.isSimpleRequirement(match)) { attribute(NAMESPACE_ATTRIBUTE, RequiredCapability.extractNamespace(match)); attribute(NAME_ATTRIBUTE, RequiredCapability.extractName(match)); attribute(VERSION_RANGE_ATTRIBUTE, RequiredCapability.extractRange(match)); - 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); - + attribute(CAPABILITY_OPTIONAL_ATTRIBUTE, requirement.getMin() == 0, false); + attribute(CAPABILITY_MULTIPLE_ATTRIBUTE, requirement.getMax() > 1, false); + } else { 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()); } - - if (requirement.getDescription() != null) { + attribute(CAPABILITY_GREED_ATTRIBUTE, requirement.isGreedy(), true); + if (requirement.getFilter() != null) + writeTrimmedCdata(CAPABILITY_FILTER_ELEMENT, requirement.getFilter().getParameters()[0].toString()); + if (requirement.getDescription() != null) writeTrimmedCdata(REQUIREMENT_DESCRIPTION_ELEMENT, requirement.getDescription()); - } - - end(); + end(REQUIREMENT_ELEMENT); } 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 621356e4a..44db99925 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,7 +39,9 @@ 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$ @@ -61,26 +63,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 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 CAPABILITY_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$ - 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}; + // 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[] 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 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[] 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}; + 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}; // Constants for attributes of an artifact key element public static final String ARTIFACT_KEY_CLASSIFIER_ATTRIBUTE = "classifier"; //$NON-NLS-1$ |