diff options
3 files changed, 82 insertions, 30 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 3cdb71077..390dbea9f 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 @@ -634,18 +634,7 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { String description = descriptionHandler == null ? null : descriptionHandler.getText(); IRequirement requirement; if (match != null) { - IExpressionFactory factory = ExpressionUtil.getFactory(); - IExpression expr = ExpressionUtil.parse(match); - Object[] params; - if (matchParams == null) - params = new Object[0]; - else { - IExpression[] arrayExpr = ExpressionUtil.getOperands(ExpressionUtil.parse(matchParams)); - params = new Object[arrayExpr.length]; - for (int idx = 0; idx < arrayExpr.length; ++idx) - params[idx] = arrayExpr[idx].evaluate(null); - } - IMatchExpression<IInstallableUnit> matchExpr = factory.matchExpression(expr, params); + IMatchExpression<IInstallableUnit> matchExpr = createMatchExpression(match, matchParams); requirement = MetadataFactory.createRequirement(matchExpr, filter, min, max, greedy, description); } else requirement = MetadataFactory.createRequirement(namespace, name, range, filter, min, max, greedy, description); @@ -803,24 +792,46 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { } protected class UpdateDescriptorHandler extends TextHandler { - private final String[] required = new String[] {ID_ATTRIBUTE, VERSION_RANGE_ATTRIBUTE}; - private final String[] optional = new String[] {UPDATE_DESCRIPTOR_SEVERITY, DESCRIPTION_ATTRIBUTE}; + private final String[] requiredSimple = new String[] {ID_ATTRIBUTE, VERSION_RANGE_ATTRIBUTE}; + private final String[] optionalSimple = new String[] {UPDATE_DESCRIPTOR_SEVERITY, DESCRIPTION_ATTRIBUTE}; + + private final String[] requiredComplex = new String[] {MATCH_ATTRIBUTE}; + private final String[] optionalComplex = new String[] {UPDATE_DESCRIPTOR_SEVERITY, DESCRIPTION_ATTRIBUTE, MATCH_PARAMETERS_ATTRIBUTE}; private IUpdateDescriptor descriptor; public UpdateDescriptorHandler(AbstractHandler parentHandler, Attributes attributes) { super(parentHandler, INSTALLABLE_UNIT_ELEMENT); - String[] values = parseAttributes(attributes, required, optional); - VersionRange range = checkVersionRange(REQUIREMENT_ELEMENT, VERSION_RANGE_ATTRIBUTE, values[1]); + boolean simple = attributes.getIndex(ID_ATTRIBUTE) >= 0; + String[] values; + int severityIdx; + String description; + if (simple) { + values = parseAttributes(attributes, requiredSimple, optionalSimple); + severityIdx = 2; + description = values[3]; + } else { + values = parseAttributes(attributes, requiredComplex, optionalComplex); + severityIdx = 1; + description = values[2]; + } + int severity; try { - severity = new Integer(values[2]).intValue(); + severity = new Integer(values[severityIdx]).intValue(); } catch (NumberFormatException e) { - invalidAttributeValue(UPDATE_DESCRIPTOR_ELEMENT, UPDATE_DESCRIPTOR_SEVERITY, values[2]); + invalidAttributeValue(UPDATE_DESCRIPTOR_ELEMENT, UPDATE_DESCRIPTOR_SEVERITY, values[severityIdx]); severity = IUpdateDescriptor.NORMAL; } URI location = parseURIAttribute(attributes, false); - descriptor = MetadataFactory.createUpdateDescriptor(values[0], range, severity, values[3], location); + + if (simple) { + VersionRange range = checkVersionRange(REQUIREMENT_ELEMENT, VERSION_RANGE_ATTRIBUTE, values[1]); + descriptor = MetadataFactory.createUpdateDescriptor(values[0], range, severity, description, location); + } else { + IMatchExpression<IInstallableUnit> r = createMatchExpression(values[0], values[3]); + descriptor = MetadataFactory.createUpdateDescriptor(Collections.singleton(r), severity, description, location); + } } public IUpdateDescriptor getUpdateDescriptor() { @@ -905,4 +916,19 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants { return copyright; } } + + static IMatchExpression<IInstallableUnit> createMatchExpression(String match, String matchParams) { + IExpressionFactory factory = ExpressionUtil.getFactory(); + IExpression expr = ExpressionUtil.parse(match); + Object[] params; + if (matchParams == null) + params = new Object[0]; + else { + IExpression[] arrayExpr = ExpressionUtil.getOperands(ExpressionUtil.parse(matchParams)); + params = new Object[arrayExpr.length]; + for (int idx = 0; idx < arrayExpr.length; ++idx) + params[idx] = arrayExpr[idx].evaluate(null); + } + return factory.matchExpression(expr, params); + } } 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 acd3d7f80..98ff47f4c 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 @@ -98,6 +98,13 @@ public abstract class MetadataWriter extends XMLWriter implements XMLConstants { if (r.getMax() == 0 || !RequiredCapability.isSimpleRequirement(r.getMatches())) return false; + if (iu.getUpdateDescriptor() != null) { + for (IMatchExpression<IInstallableUnit> m : iu.getUpdateDescriptor().getIUsBeingUpdated()) { + if (!RequiredCapability.isSimpleRequirement(m)) + return false; + } + } + for (IRequirement r : iu.getMetaRequirements()) if (r.getMax() == 0 || !RequiredCapability.isSimpleRequirement(r.getMatches())) return false; @@ -186,8 +193,12 @@ public abstract class MetadataWriter extends XMLWriter implements XMLConstants { throw new IllegalStateException(); IMatchExpression<IInstallableUnit> singleUD = descriptor.getIUsBeingUpdated().iterator().next(); start(UPDATE_DESCRIPTOR_ELEMENT); - attribute(ID_ATTRIBUTE, RequiredCapability.extractName(singleUD)); - attribute(VERSION_RANGE_ATTRIBUTE, RequiredCapability.extractRange(singleUD)); + if (RequiredCapability.isSimpleRequirement(singleUD)) { + attribute(ID_ATTRIBUTE, RequiredCapability.extractName(singleUD)); + attribute(VERSION_RANGE_ATTRIBUTE, RequiredCapability.extractRange(singleUD)); + } else { + writeMatchExpression(singleUD); + } attribute(UPDATE_DESCRIPTOR_SEVERITY, descriptor.getSeverity()); attribute(DESCRIPTION_ATTRIBUTE, descriptor.getDescription()); end(UPDATE_DESCRIPTOR_ELEMENT); @@ -236,15 +247,7 @@ public abstract class MetadataWriter extends XMLWriter implements XMLConstants { attribute(CAPABILITY_OPTIONAL_ATTRIBUTE, requirement.getMin() == 0, false); attribute(CAPABILITY_MULTIPLE_ATTRIBUTE, requirement.getMax() > 1, false); } else { - attribute(MATCH_ATTRIBUTE, ExpressionUtil.getOperand(match)); - Object[] params = match.getParameters(); - if (params.length > 0) { - IExpressionFactory factory = ExpressionUtil.getFactory(); - IExpression[] constantArray = new IExpression[params.length]; - for (int idx = 0; idx < params.length; ++idx) - constantArray[idx] = factory.constant(params[idx]); - attribute(MATCH_PARAMETERS_ATTRIBUTE, factory.array(constantArray)); - } + writeMatchExpression(match); if (requirement.getMin() != 1) attribute(MIN_ATTRIBUTE, requirement.getMin()); if (requirement.getMax() != 1) @@ -258,6 +261,18 @@ public abstract class MetadataWriter extends XMLWriter implements XMLConstants { end(REQUIREMENT_ELEMENT); } + private void writeMatchExpression(IMatchExpression<IInstallableUnit> match) { + attribute(MATCH_ATTRIBUTE, ExpressionUtil.getOperand(match)); + Object[] params = match.getParameters(); + if (params.length > 0) { + IExpressionFactory factory = ExpressionUtil.getFactory(); + IExpression[] constantArray = new IExpression[params.length]; + for (int idx = 0; idx < params.length; ++idx) + constantArray[idx] = factory.constant(params[idx]); + attribute(MATCH_PARAMETERS_ATTRIBUTE, factory.array(constantArray)); + } + } + protected void writeArtifactKeys(Collection<IArtifactKey> artifactKeys) { if (artifactKeys != null && artifactKeys.size() > 0) { start(ARTIFACT_KEYS_ELEMENT); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/UpdateForTwoIUs.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/UpdateForTwoIUs.java index 6e7ec001c..fe6dc2447 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/UpdateForTwoIUs.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/UpdateForTwoIUs.java @@ -9,11 +9,13 @@ import org.eclipse.equinox.p2.metadata.*; import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription; import org.eclipse.equinox.p2.metadata.expression.*; import org.eclipse.equinox.p2.query.IQueryResult; +import org.eclipse.equinox.p2.query.QueryUtil; import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; public class UpdateForTwoIUs extends AbstractProvisioningTest { private IInstallableUnit iua; + private Collection<IMatchExpression<IInstallableUnit>> x; @Override protected void setUp() throws Exception { @@ -30,6 +32,15 @@ public class UpdateForTwoIUs extends AbstractProvisioningTest { updateExpression.add(matchExpression); iud.setUpdateDescriptor(MetadataFactory.createUpdateDescriptor(updateExpression, IUpdateDescriptor.HIGH, (String) null, (URI) null)); iua = MetadataFactory.createInstallableUnit(iud); + + Collection<IInstallableUnit> ius = new ArrayList<IInstallableUnit>(); + ius.add(iua); + URI repoURI = getTempFolder().toURI(); + createMetadataRepository(repoURI, null).addInstallableUnits(ius); + getMetadataRepositoryManager().removeRepository(repoURI); + + x = getMetadataRepositoryManager().loadRepository(repoURI, null).query(QueryUtil.ALL_UNITS, null).iterator().next().getUpdateDescriptor().getIUsBeingUpdated(); + assertEquals(matchExpression, x.iterator().next()); } public void testUpdateQueryForTwoIUs() { |