summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2012-12-08 21:59:07 (EST)
committerPascal Rapicault2012-12-08 21:59:07 (EST)
commit3d04353d8947710873181679046fa3ab8fa2fc98 (patch)
tree847d3456d511230b3596bc2da2aea996a6100b8d
parentbb3337b22a12bedb23b068bd4d5f25c4465170ee (diff)
downloadrt.equinox.p2-3d04353d8947710873181679046fa3ab8fa2fc98.zip
rt.equinox.p2-3d04353d8947710873181679046fa3ab8fa2fc98.tar.gz
rt.equinox.p2-3d04353d8947710873181679046fa3ab8fa2fc98.tar.bz2
Bug 396136 - [publisher] Support for expression in update descriptor andv20121209-025907
requirements
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AdviceFileParser.java30
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/AdviceFileParserTest.java41
2 files changed, 65 insertions, 6 deletions
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AdviceFileParser.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AdviceFileParser.java
index 27c1fd9..b197577 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AdviceFileParser.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AdviceFileParser.java
@@ -31,7 +31,7 @@ public class AdviceFileParser {
private static final String UPDATE_SEVERITY = "update.severity"; //$NON-NLS-1$
private static final String UPDATE_RANGE = "update.range"; //$NON-NLS-1$
private static final String UPDATE_ID = "update.id"; //$NON-NLS-1$
- private static final String UPDATE_MATCH = "update.match"; //$NON-NLS-1$
+ private static final String UPDATE_MATCH_EXP = "update.matchExp"; //$NON-NLS-1$
private static final String CLASSIFIER = "classifier"; //$NON-NLS-1$
private static final String TOUCHPOINT_VERSION = "touchpoint.version"; //$NON-NLS-1$
private static final String TOUCHPOINT_ID = "touchpoint.id"; //$NON-NLS-1$
@@ -50,6 +50,7 @@ public class AdviceFileParser {
private static final String VERSION = "version"; //$NON-NLS-1$
private static final String NAMESPACE = "namespace"; //$NON-NLS-1$
private static final String NAME = "name"; //$NON-NLS-1$
+ private static final String MATCH_EXP = "matchExp"; //$NON-NLS-1$
private static final String LOCATION = "location"; //$NON-NLS-1$
private static final String VALUE = "value"; //$NON-NLS-1$
@@ -173,7 +174,7 @@ public class AdviceFileParser {
while (current != null && current.startsWith(prefix)) {
String token = current;
- if (token.equals(UPDATE_MATCH)) {
+ if (token.equals(UPDATE_MATCH_EXP)) {
match = currentValue();
} else if (token.equals(UPDATE_ID)) {
name = currentValue();
@@ -249,6 +250,7 @@ public class AdviceFileParser {
String namespace = null;
String name = null;
VersionRange range = null;
+ String matchExp = null;
String filter = null;
boolean optional = false;
boolean multiple = false;
@@ -277,22 +279,40 @@ public class AdviceFileParser {
min = Integer.valueOf(currentValue()).intValue();
} else if (token.equals(MAX)) {
max = Integer.valueOf(currentValue()).intValue();
+ } else if (token.equals(MATCH_EXP)) {
+ matchExp = currentValue();
} else {
// we ignore elements we do not understand
}
next();
}
IRequirement capability = null;
- if (min >= 0 && max >= 0) {
- capability = createRequirement(namespace, name, range, filter, min, max, greedy);
+ if (matchExp == null) {
+ if (min >= 0 && max >= 0) {
+ capability = createRequirement(namespace, name, range, filter, min, max, greedy);
+ } else {
+ capability = createRequirement(namespace, name, range, filter, optional, multiple, greedy);
+ }
} else {
- capability = createRequirement(namespace, name, range, filter, optional, multiple, greedy);
+ //When a match expression is specified, namespace, name and versionRange are ignored
+ if (optional && min == -1 && max == -1) {
+ min = 0;
+ max = 1;
+ }
+ capability = createRequirement(matchExp, filter, min, max, greedy, null);
}
if (capability != null) {
requires.add(capability);
}
}
+ protected IRequirement createRequirement(String requirement, String filter, int min, int max, boolean greedy, String description) {
+ IExpression expr = ExpressionUtil.parse(substituteVersionAndQualifier(requirement));
+ IMatchExpression<IInstallableUnit> requirementExp = ExpressionUtil.getFactory().matchExpression(expr);
+ IMatchExpression<IInstallableUnit> filterExp = InstallableUnit.parseFilter(filter);
+ return MetadataFactory.createRequirement(requirementExp, filterExp, min, max, greedy, description);
+ }
+
protected IRequirement createRequirement(String namespace, String name, VersionRange range, String filter, int min, int max, boolean greedy) {
IMatchExpression<IInstallableUnit> filterExpression = InstallableUnit.parseFilter(filter);
return MetadataFactory.createRequirement(namespace, name, range, filterExpression, min, max, greedy);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/AdviceFileParserTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/AdviceFileParserTest.java
index 9c752ba..20a9bc7 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/AdviceFileParserTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/AdviceFileParserTest.java
@@ -15,6 +15,8 @@ import junit.framework.TestCase;
import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
+import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
import org.eclipse.equinox.p2.publisher.AdviceFileParser;
import org.eclipse.equinox.p2.query.QueryUtil;
@@ -87,7 +89,7 @@ public class AdviceFileParserTest extends TestCase {
public void testUpdateDescriptorWithMatch() {
Map map = new HashMap();
- map.put("update.match", "providedCapabilities.exists(pc | pc.namespace == 'org.eclipse.equinox.p2.iu' && (pc.name == 'B' || pc.name == 'C'))");
+ map.put("update.matchExp", "providedCapabilities.exists(pc | pc.namespace == 'org.eclipse.equinox.p2.iu' && (pc.name == 'B' || pc.name == 'C'))");
map.put("update.severity", "10");
map.put("update.description", "Test Description");
@@ -245,6 +247,43 @@ public class AdviceFileParserTest extends TestCase {
assertEquals(1, reqs[1].getMin());
}
+ public void testRequireWithExpression() {
+ Map map = new HashMap();
+ String matchExp = "properties[abc] == 'def'";
+ map.put("requires.0.matchExp", matchExp);
+ map.put("requires.0.greedy", Boolean.TRUE.toString());
+ map.put("requires.0.min", "1");
+ map.put("requires.0.max", "1");
+
+ AdviceFileParser parser = new AdviceFileParser("id", Version.emptyVersion, map);
+ parser.parse();
+ IRequirement[] reqs = parser.getRequiredCapabilities();
+ reqs = parser.getRequiredCapabilities();
+ assertEquals(1, reqs.length);
+
+ IMatchExpression<IInstallableUnit> matchExpression = ExpressionUtil.getFactory().matchExpression(ExpressionUtil.parse(matchExp));
+ assertEquals(matchExpression, reqs[0].getMatches());
+ }
+
+ public void testRequireWithExpressionAndOptional() {
+ Map map = new HashMap();
+ String matchExp = "properties[abc] == 'def'";
+ map.put("requires.0.matchExp", matchExp);
+ map.put("requires.0.greedy", Boolean.TRUE.toString());
+ map.put("requires.0.optional", Boolean.TRUE.toString());
+
+ AdviceFileParser parser = new AdviceFileParser("id", Version.emptyVersion, map);
+ parser.parse();
+ IRequirement[] reqs = parser.getRequiredCapabilities();
+ reqs = parser.getRequiredCapabilities();
+ assertEquals(1, reqs.length);
+
+ IMatchExpression<IInstallableUnit> matchExpression = ExpressionUtil.getFactory().matchExpression(ExpressionUtil.parse(matchExp));
+ assertEquals(matchExpression, reqs[0].getMatches());
+ assertEquals(0, reqs[0].getMin());
+ assertEquals(1, reqs[0].getMax());
+ }
+
public void testMetaRequiresAdvice() {
Map map = new HashMap();
map.put("metaRequirements.0.namespace", "testNamespace1");