Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTodor Boev2017-12-11 07:40:13 -0500
committerAlexander Kurtakov2017-12-12 09:59:14 -0500
commitcf04c14fb70f9579577a5dcd3df5a71366cbeb97 (patch)
treef3674511c107a32c0d69c9b46b35eeb7a61303d6
parentbca37abc53dfd293c1b750c5c9844f7cd905ddf8 (diff)
downloadrt.equinox.p2-cf04c14fb70f9579577a5dcd3df5a71366cbeb97.tar.gz
rt.equinox.p2-cf04c14fb70f9579577a5dcd3df5a71366cbeb97.tar.xz
rt.equinox.p2-cf04c14fb70f9579577a5dcd3df5a71366cbeb97.zip
Bug 528408 - Extract the IRequirement impl from RequiredCapabilityI20171214-0120I20171213-2000I20171212-2000
- Fix p2 codebase to use MetadataFactory instead of new RequiredCapabiilty - Work around the implicit restriction that IRequiredCapability must always have maxCard > 1. This is due to the serialization format that does not support maxCard == 0 since it only has optional and multiple flags. Change-Id: Ia8f2c9abd4aee553020018032a22784f1af3b3ba Signed-off-by: Todor Boev <rinsvind@gmail.com>
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataParser.java19
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/.settings/org.eclipse.jdt.ui.prefs5
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/RequiredCapability.java241
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/Requirement.java161
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/MetadataFactory.java116
-rw-r--r--bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java3
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/.settings/org.eclipse.jdt.ui.prefs4
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/AllTests.java6
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/PersistNegation.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementParsingTest.java80
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementToString.java13
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java118
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/Bug311330.java17
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NegationTesting.java68
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PatchTestUsingNegativeRequirement.java15
15 files changed, 514 insertions, 362 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 90e27da4b..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
@@ -134,7 +134,7 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants {
private PropertiesHandler propertiesHandler = null;
private ProvidedCapabilitiesHandler providedCapabilitiesHandler = null;
- private RequiredCapabilitiesHandler requiredCapabilitiesHandler = null;
+ private RequirementsHandler requiredCapabilitiesHandler = null;
private HostRequiredCapabilitiesHandler hostRequiredCapabilitiesHandler = null;
private MetaRequiredCapabilitiesHandler metaRequiredCapabilitiesHandler = null;
private TextHandler filterHandler = null;
@@ -188,7 +188,7 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants {
}
} else if (REQUIREMENTS_ELEMENT.equals(name)) {
if (requiredCapabilitiesHandler == null) {
- requiredCapabilitiesHandler = new RequiredCapabilitiesHandler(this, attributes);
+ requiredCapabilitiesHandler = new RequirementsHandler(this, attributes);
} else {
duplicateElement(this, name, attributes);
}
@@ -369,7 +369,7 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants {
}
protected class ApplicabilityScopeHandler extends AbstractHandler {
- private RequiredCapabilitiesHandler children;
+ private RequirementsHandler children;
private List<IRequirement[]> scopes;
public ApplicabilityScopeHandler(AbstractHandler parentHandler, Attributes attributes, List<IRequirement[]> scopes) {
@@ -380,7 +380,7 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants {
@Override
public void startElement(String name, Attributes attributes) {
if (REQUIREMENTS_ELEMENT.equals(name)) {
- children = new RequiredCapabilitiesHandler(this, attributes);
+ children = new RequirementsHandler(this, attributes);
} else {
duplicateElement(this, name, attributes);
}
@@ -690,10 +690,10 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants {
}
}
- protected class RequiredCapabilitiesHandler extends AbstractMetadataHandler {
+ protected class RequirementsHandler extends AbstractMetadataHandler {
private List<IRequirement> requiredCapabilities;
- public RequiredCapabilitiesHandler(AbstractHandler parentHandler, Attributes attributes) {
+ public RequirementsHandler(AbstractHandler parentHandler, Attributes attributes) {
super(parentHandler, REQUIREMENTS_ELEMENT);
requiredCapabilities = new ArrayList<>(getOptionalSize(attributes, 4));
}
@@ -715,11 +715,15 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants {
protected class RequirementHandler extends AbstractHandler {
private List<IRequirement> capabilities;
+ // Expression based requirement
private String match;
private String matchParams;
+
+ // Simple requirement
private String namespace;
private String name;
private VersionRange range;
+
private int min;
private int max;
private boolean greedy;
@@ -783,8 +787,9 @@ public abstract class MetadataParser extends XMLParser implements XMLConstants {
if (match != null) {
IMatchExpression<IInstallableUnit> matchExpr = createMatchExpression(match, matchParams);
requirement = MetadataFactory.createRequirement(matchExpr, filter, min, max, greedy, description);
- } else
+ } else {
requirement = MetadataFactory.createRequirement(namespace, name, range, filter, min, max, greedy, description);
+ }
capabilities.add(requirement);
}
diff --git a/bundles/org.eclipse.equinox.p2.metadata/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.equinox.p2.metadata/.settings/org.eclipse.jdt.ui.prefs
index 38d7fa95e..75a73e924 100644
--- a/bundles/org.eclipse.equinox.p2.metadata/.settings/org.eclipse.jdt.ui.prefs
+++ b/bundles/org.eclipse.equinox.p2.metadata/.settings/org.eclipse.jdt.ui.prefs
@@ -1,12 +1,11 @@
-#Mon Nov 05 17:01:21 EST 2007
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_core
formatter_settings_version=11
org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=;
-org.eclipse.jdt.ui.ondemandthreshold=3
-org.eclipse.jdt.ui.staticondemandthreshold=3
+org.eclipse.jdt.ui.ondemandthreshold=99
+org.eclipse.jdt.ui.staticondemandthreshold=99
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates/>
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/RequiredCapability.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/RequiredCapability.java
index 984720c47..eee9b327b 100644
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/RequiredCapability.java
+++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/RequiredCapability.java
@@ -12,8 +12,13 @@
package org.eclipse.equinox.internal.p2.metadata;
import org.eclipse.core.runtime.Assert;
-import org.eclipse.equinox.p2.metadata.*;
-import org.eclipse.equinox.p2.metadata.expression.*;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.Version;
+import org.eclipse.equinox.p2.metadata.VersionRange;
+import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
+import org.eclipse.equinox.p2.metadata.expression.IExpression;
+import org.eclipse.equinox.p2.metadata.expression.IExpressionFactory;
+import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
/**
* A required capability represents some external constraint on an {@link IInstallableUnit}.
@@ -28,21 +33,7 @@ import org.eclipse.equinox.p2.metadata.expression.*;
*
* @see IInstallableUnit#NAMESPACE_IU_ID
*/
-public class RequiredCapability implements IRequiredCapability, IMemberProvider {
- private final IMatchExpression<IInstallableUnit> filter;
- private final IMatchExpression<IInstallableUnit> matchExpression;
-
- public static final String MEMBER_FILTER = "filter"; //$NON-NLS-1$
- public static final String MEMBER_MIN = "min"; //$NON-NLS-1$
- public static final String MEMBER_MAX = "max"; //$NON-NLS-1$
- public static final String MEMBER_GREEDY = "greedy"; //$NON-NLS-1$
- public static final String MEMBER_MATCH = "match"; //$NON-NLS-1$
-
- private final boolean greedy;
- private final int min;
- private final int max;
- private String description;
-
+public class RequiredCapability extends Requirement implements IRequiredCapability {
private static final IExpression allVersionsExpression;
private static final IExpression range_II_Expression;
private static final IExpression range_IN_Expression;
@@ -81,171 +72,93 @@ public class RequiredCapability implements IRequiredCapability, IMemberProvider
}
/**
- * TODO replace booleans with int options flag.
+ * TODO Remove. This is a private impl class. Users must call the analogous MetadataFactory.createRequirement()
+ * @deprecated To be removed once CBI is fixed.
+ * @noreference This constructor is not intended to be referenced by clients.
*/
+ @Deprecated
public RequiredCapability(String namespace, String name, VersionRange range, String filter, boolean optional, boolean multiple) {
this(namespace, name, range, filter, optional, multiple, true);
}
- public RequiredCapability(IMatchExpression<IInstallableUnit> requirement, IMatchExpression<IInstallableUnit> filter, int min, int max, boolean greedy, String description) {
- this.matchExpression = requirement;
- this.filter = filter;
- this.min = min;
- this.max = max;
- this.greedy = greedy;
- this.description = description;
- }
-
+ /**
+ * TODO Remove. This is a private impl class. Users must call the analogous MetadataFactory.createRequirement()
+ * @deprecated To be removed once CBI is fixed.
+ * @noreference This constructor is not intended to be referenced by clients.
+ */
+ @Deprecated
public RequiredCapability(String namespace, String name, VersionRange range, String filter, boolean optional, boolean multiple, boolean greedy) {
- this(namespace, name, range, filter == null ? (IMatchExpression<IInstallableUnit>) null : InstallableUnit.parseFilter(filter), optional ? 0 : 1, multiple ? Integer.MAX_VALUE : 1, greedy, null);
+ this(namespace, name, range, InstallableUnit.parseFilter(filter), optional ? 0 : 1, multiple ? Integer.MAX_VALUE : 1, greedy, null);
}
public RequiredCapability(String namespace, String name, VersionRange range, IMatchExpression<IInstallableUnit> filter, int min, int max, boolean greedy, String description) {
- Assert.isNotNull(namespace);
- Assert.isNotNull(name);
- IExpressionFactory factory = ExpressionUtil.getFactory();
- if (range == null || range.equals(VersionRange.emptyRange)) {
- matchExpression = factory.matchExpression(allVersionsExpression, name, namespace);
- } else {
- if (range.getMinimum().equals(range.getMaximum())) {
- // Explicit version appointed
- matchExpression = factory.matchExpression(strictVersionExpression, name, namespace, range.getMinimum());
- } else {
- if (range.getMaximum().equals(Version.MAX_VERSION)) {
- // Open ended
- matchExpression = factory.matchExpression(range.getIncludeMinimum() ? openEndedExpression : openEndedNonInclusiveExpression, name, namespace, range.getMinimum());
- } else {
- matchExpression = factory.matchExpression(//
- range.getIncludeMinimum() ? (range.getIncludeMaximum() ? range_II_Expression : range_IN_Expression) //
- : (range.getIncludeMaximum() ? range_NI_Expression : range_NN_Expression), //
- name, namespace, range.getMinimum(), range.getMaximum());
- }
- }
- }
- this.min = min;
- this.max = max;
- this.greedy = greedy;
- this.filter = filter;
- this.description = description;
+ super(createMatchExpressionFromRange(namespace, name, range), filter, min, max, greedy, description);
}
@Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
-
- if (!(obj instanceof IRequirement))
- return false;
-
- IRequirement other = (IRequirement) obj;
- if (filter == null) {
- if (other.getFilter() != null)
- return false;
- } else if (!filter.equals(other.getFilter()))
- return false;
-
- return min == other.getMin() && max == other.getMax() && greedy == other.isGreedy() && matchExpression.equals(other.getMatches());
+ public String getNamespace() {
+ return extractNamespace(matchExpression);
}
@Override
public String getName() {
- return (String) matchExpression.getParameters()[0];
- }
-
- @Override
- public String getNamespace() {
- return (String) matchExpression.getParameters()[1];
+ return extractName(matchExpression);
}
- /**
- * Returns the range of versions that satisfy this required capability. Returns
- * an empty version range ({@link VersionRange#emptyRange} if any version
- * will satisfy the capability.
- * @return the range of versions that satisfy this required capability.
- */
@Override
public VersionRange getRange() {
return extractRange(matchExpression);
}
@Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((filter == null) ? 0 : filter.hashCode());
- result = prime * result + matchExpression.hashCode();
- return result;
- }
-
- @Override
- public boolean isGreedy() {
- return greedy;
- }
-
- @Override
public String toString() {
- StringBuffer result = new StringBuffer();
- if (matchExpression.getParameters().length == 0)
- return matchExpression.toString();
+ StringBuilder result = new StringBuilder();
- if (!isSimpleRequirement(matchExpression)) {
- result.append(matchExpression.toString()).append(' ');
- for (int i = 0; i < matchExpression.getParameters().length; i++) {
- result.append(matchExpression.getParameters()[i]).append(' ');
- }
- return result.toString();
- }
+ // Namespace
+ result.append(getNamespace());
+ result.append(' ');
- if (IInstallableUnit.NAMESPACE_IU_ID.equals(getNamespace())) {
- //print nothing for an IU id dependency because this is the default (most common) case
- result.append(""); //$NON-NLS-1$
- } else if ("osgi.bundle".equals(getNamespace())) { //$NON-NLS-1$
- result.append("bundle"); //$NON-NLS-1$
- } else if ("java.package".equals(getNamespace())) { //$NON-NLS-1$
- result.append("package"); //$NON-NLS-1$
- } else {
- result.append(getNamespace());
- }
- if (result.length() > 0)
- result.append(' ');
+ // Name
result.append(getName());
result.append(' ');
+
+ // Version range
VersionRange range = getRange();
- //for an exact version match, print a simpler expression
- if (range.getMinimum().equals(range.getMaximum()))
- result.append('[').append(range.getMinimum()).append(']');
- else
- result.append(range);
+ result.append(range);
+
return result.toString();
}
- @Override
- public int getMin() {
- return min;
- }
+ public static IMatchExpression<IInstallableUnit> createMatchExpressionFromRange(String namespace, String name, VersionRange range) {
+ Assert.isNotNull(namespace);
+ Assert.isNotNull(name);
- @Override
- public int getMax() {
- return max;
- }
+ // Empty range - matches everything
+ IExpressionFactory factory = ExpressionUtil.getFactory();
+ if (range == null || range.equals(VersionRange.emptyRange)) {
+ return factory.matchExpression(allVersionsExpression, name, namespace);
+ }
- @Override
- public IMatchExpression<IInstallableUnit> getMatches() {
- return matchExpression;
- }
+ // Point range - matches exactly one version
+ if (range.getMinimum().equals(range.getMaximum())) {
+ return factory.matchExpression(strictVersionExpression, name, namespace, range.getMinimum());
+ }
- @Override
- public IMatchExpression<IInstallableUnit> getFilter() {
- return filter;
- }
+ // Semi-closed ranged - matches a minimum version
+ if (range.getMaximum().equals(Version.MAX_VERSION)) {
+ return factory.matchExpression(range.getIncludeMinimum() ? openEndedExpression : openEndedNonInclusiveExpression, name, namespace, range.getMinimum());
+ }
- @Override
- public boolean isMatch(IInstallableUnit candidate) {
- return matchExpression.isMatch(candidate);
+ // Closed range - matches version between a minimum and a maximum
+ return factory.matchExpression(//
+ range.getIncludeMinimum() ? (range.getIncludeMaximum() ? range_II_Expression : range_IN_Expression) //
+ : (range.getIncludeMaximum() ? range_NI_Expression : range_NN_Expression), //
+ name, namespace, range.getMinimum(), range.getMaximum());
}
- public static boolean isVersionStrict(IMatchExpression<IInstallableUnit> matchExpression) {
- return ExpressionUtil.getOperand(matchExpression) == strictVersionExpression;
+ public static String extractNamespace(IMatchExpression<IInstallableUnit> matchExpression) {
+ assertValid(matchExpression);
+ return (String) matchExpression.getParameters()[1];
}
public static String extractName(IMatchExpression<IInstallableUnit> matchExpression) {
@@ -253,62 +166,40 @@ public class RequiredCapability implements IRequiredCapability, IMemberProvider
return (String) matchExpression.getParameters()[0];
}
- public static String extractNamespace(IMatchExpression<IInstallableUnit> matchExpression) {
- assertValid(matchExpression);
- return (String) matchExpression.getParameters()[1];
- }
-
public static VersionRange extractRange(IMatchExpression<IInstallableUnit> matchExpression) {
IExpression expr = assertValid(matchExpression);
Object[] params = matchExpression.getParameters();
- if (params.length < 3)
+ if (params.length < 3) {
return VersionRange.emptyRange;
+ }
Version v = (Version) params[2];
if (params.length < 4) {
- if (expr.equals(strictVersionExpression))
+ if (expr.equals(strictVersionExpression)) {
return new VersionRange(v, true, v, true);
+ }
return new VersionRange(v, expr.equals(openEndedExpression), Version.MAX_VERSION, true);
}
Version h = (Version) params[3];
return new VersionRange(v, expr.equals(range_II_Expression) || expr.equals(range_IN_Expression), h, expr.equals(range_II_Expression) || expr.equals(range_NI_Expression));
}
+ public static boolean isVersionStrict(IMatchExpression<IInstallableUnit> matchExpression) {
+ return ExpressionUtil.getOperand(matchExpression) == strictVersionExpression;
+ }
+
public static boolean isSimpleRequirement(IMatchExpression<IInstallableUnit> matchExpression) {
return isPredefined(ExpressionUtil.getOperand(matchExpression));
}
private static IExpression assertValid(IMatchExpression<IInstallableUnit> matchExpression) {
IExpression expr = ExpressionUtil.getOperand(matchExpression);
- if (!isPredefined(expr))
+ if (!isPredefined(expr)) {
throw new IllegalArgumentException();
+ }
return expr;
}
private static boolean isPredefined(IExpression expr) {
return expr.equals(allVersionsExpression) || expr.equals(range_II_Expression) || expr.equals(range_IN_Expression) || expr.equals(range_NI_Expression) || expr.equals(range_NN_Expression) || expr.equals(strictVersionExpression) || expr.equals(openEndedExpression) || expr.equals(openEndedNonInclusiveExpression);
}
-
- @Override
- public Object getMember(String memberName) {
- // It is OK to use identity comparisons here since
- // a) All constant valued strings are always interned
- // b) The Member constructor always interns the name
- //
- if (MEMBER_FILTER == memberName)
- return filter;
- if (MEMBER_MIN == memberName)
- return Integer.valueOf(min);
- if (MEMBER_MAX == memberName)
- return Integer.valueOf(max);
- if (MEMBER_GREEDY == memberName)
- return Boolean.valueOf(greedy);
- if (MEMBER_MATCH == memberName)
- return matchExpression;
- throw new IllegalArgumentException("No such member: " + memberName); //$NON-NLS-1$
- }
-
- @Override
- public String getDescription() {
- return description;
- }
}
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/Requirement.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/Requirement.java
new file mode 100644
index 000000000..036721c5f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/Requirement.java
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2017 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * EclipseSource - ongoing development
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.metadata;
+
+import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
+import org.eclipse.equinox.p2.metadata.expression.IMemberProvider;
+
+/**
+ * A requirement represents some external constraint on an {@link IInstallableUnit}.
+ * Each requirement represents something an {@link IInstallableUnit} needs that
+ * it expects to be provided by another {@link IInstallableUnit}. Requirements are
+ * entirely generic, and are intended to be capable of representing anything that
+ * an {@link IInstallableUnit} may need either at install time, or at runtime.
+ * <p>
+ * Instances of this class are handle objects and do not necessarily
+ * reflect entities that exist in any particular profile or repository. These handle
+ * objects can be created using {@link MetadataFactory}.
+ * </p>
+ *
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @noextend This interface is not intended to be extended by clients.
+ * @since 2.0
+ * @see IProvidedCapability
+ * @see MetadataFactory#createRequirement(String, String, VersionRange, String, boolean, boolean, boolean)
+ */
+public class Requirement implements IRequirement, IMemberProvider {
+ public static final String MEMBER_FILTER = "filter"; //$NON-NLS-1$
+ public static final String MEMBER_MIN = "min"; //$NON-NLS-1$
+ public static final String MEMBER_MAX = "max"; //$NON-NLS-1$
+ public static final String MEMBER_GREEDY = "greedy"; //$NON-NLS-1$
+ public static final String MEMBER_MATCH = "match"; //$NON-NLS-1$
+
+ protected final IMatchExpression<IInstallableUnit> filter;
+ protected final IMatchExpression<IInstallableUnit> matchExpression;
+ protected final boolean greedy;
+ protected final int min;
+ protected final int max;
+ protected final String description;
+
+ public Requirement(IMatchExpression<IInstallableUnit> requirement, IMatchExpression<IInstallableUnit> filter, int min, int max, boolean greedy, String description) {
+ this.matchExpression = requirement;
+ this.filter = filter;
+ this.min = min;
+ this.max = max;
+ this.greedy = greedy;
+ this.description = description;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder result = new StringBuilder();
+
+ // Expression
+ result.append(matchExpression);
+
+ // Parameters
+ Object[] params = matchExpression.getParameters();
+ if (params.length > 0) {
+ result.append(' ');
+ for (int i = 0; i < params.length; i++) {
+ result.append(params[i]).append(' ');
+ }
+ }
+
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((filter == null) ? 0 : filter.hashCode());
+ result = prime * result + matchExpression.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (!(obj instanceof IRequirement)) {
+ return false;
+ }
+
+ IRequirement other = (IRequirement) obj;
+ if (filter == null) {
+ if (other.getFilter() != null) {
+ return false;
+ }
+ } else if (!filter.equals(other.getFilter())) {
+ return false;
+ }
+
+ return min == other.getMin() && max == other.getMax() && greedy == other.isGreedy() && matchExpression.equals(other.getMatches());
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public int getMin() {
+ return min;
+ }
+
+ @Override
+ public int getMax() {
+ return max;
+ }
+
+ @Override
+ public boolean isGreedy() {
+ return greedy;
+ }
+
+ @Override
+ public IMatchExpression<IInstallableUnit> getFilter() {
+ return filter;
+ }
+
+ @Override
+ public IMatchExpression<IInstallableUnit> getMatches() {
+ return matchExpression;
+ }
+
+ @Override
+ public boolean isMatch(IInstallableUnit candidate) {
+ return matchExpression.isMatch(candidate);
+ }
+
+ @Override
+ public Object getMember(String memberName) {
+ switch (memberName) {
+ case MEMBER_FILTER :
+ return filter;
+ case MEMBER_MIN :
+ return min;
+ case MEMBER_MAX :
+ return max;
+ case MEMBER_GREEDY :
+ return greedy;
+ case MEMBER_MATCH :
+ return matchExpression;
+ default :
+ throw new IllegalArgumentException("No such member: " + memberName); //$NON-NLS-1$
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/MetadataFactory.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/MetadataFactory.java
index ba460d3e6..e3f89b18d 100644
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/MetadataFactory.java
+++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/MetadataFactory.java
@@ -13,10 +13,31 @@
package org.eclipse.equinox.p2.metadata;
import java.net.URI;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
import org.eclipse.core.runtime.Assert;
-import org.eclipse.equinox.internal.p2.metadata.*;
-import org.eclipse.equinox.p2.metadata.expression.*;
+import org.eclipse.equinox.internal.p2.metadata.Copyright;
+import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
+import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
+import org.eclipse.equinox.internal.p2.metadata.InstallableUnitFragment;
+import org.eclipse.equinox.internal.p2.metadata.InstallableUnitPatch;
+import org.eclipse.equinox.internal.p2.metadata.License;
+import org.eclipse.equinox.internal.p2.metadata.ProvidedCapability;
+import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
+import org.eclipse.equinox.internal.p2.metadata.Requirement;
+import org.eclipse.equinox.internal.p2.metadata.RequirementChange;
+import org.eclipse.equinox.internal.p2.metadata.ResolvedInstallableUnit;
+import org.eclipse.equinox.internal.p2.metadata.TouchpointData;
+import org.eclipse.equinox.internal.p2.metadata.TouchpointInstruction;
+import org.eclipse.equinox.internal.p2.metadata.TouchpointType;
+import org.eclipse.equinox.internal.p2.metadata.UpdateDescriptor;
+import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
/**
* A factory class for instantiating various p2 metadata objects.
@@ -495,7 +516,17 @@ public final class MetadataFactory {
* @return the requirement
*/
public static IRequirement createRequirement(IMatchExpression<IInstallableUnit> requirement, IMatchExpression<IInstallableUnit> filter, int minCard, int maxCard, boolean greedy) {
- return new RequiredCapability(requirement, filter, minCard, maxCard, greedy, null);
+ // IRequiredCapability is simply a requirement with a match expression derived from a (namespace, name, version) tripet.
+ // However the xml format also requires that maxCard > 1 or it is serialized in the generic format.
+ // When parsing back from xml try to convert to an IRequiredCapability to retain the representation prior to serialization
+ if (RequiredCapability.isSimpleRequirement(requirement)) {
+ String namespace = RequiredCapability.extractNamespace(requirement);
+ String name = RequiredCapability.extractName(requirement);
+ VersionRange range = RequiredCapability.extractRange(requirement);
+ return new RequiredCapability(namespace, name, range, filter, minCard, maxCard, greedy, null);
+ }
+
+ return new Requirement(requirement, filter, minCard, maxCard, greedy, null);
}
/**
@@ -513,7 +544,7 @@ public final class MetadataFactory {
* @return the requirement
*/
public static IRequirement createRequirement(String namespace, String name, VersionRange range, String filter, boolean optional, boolean multiple, boolean greedy) {
- return new RequiredCapability(namespace, name, range, filter, optional, multiple, greedy);
+ return new RequiredCapability(namespace, name, range, InstallableUnit.parseFilter(filter), optional ? 0 : 1, multiple ? Integer.MAX_VALUE : 1, greedy, null);
}
/**
@@ -546,7 +577,17 @@ public final class MetadataFactory {
* @return the requirement
*/
public static IRequirement createRequirement(IMatchExpression<IInstallableUnit> requirement, IMatchExpression<IInstallableUnit> filter, int minCard, int maxCard, boolean greedy, String description) {
- return new RequiredCapability(requirement, filter, minCard, maxCard, greedy, description);
+ // IRequiredCapability is simply a requirement with a match expression derived from a (namespace, name, version) tripet.
+ // However the xml format also requires that maxCard > 1 or it is serialized in the generic format.
+ // When parsing back from xml try to convert to an IRequiredCapability to retain the representation prior to serialization
+ if (RequiredCapability.isSimpleRequirement(requirement)) {
+ String namespace = RequiredCapability.extractNamespace(requirement);
+ String name = RequiredCapability.extractName(requirement);
+ VersionRange range = RequiredCapability.extractRange(requirement);
+ return new RequiredCapability(namespace, name, range, filter, minCard, maxCard, greedy, description);
+ }
+
+ return new Requirement(requirement, filter, minCard, maxCard, greedy, description);
}
/**
@@ -725,71 +766,10 @@ public final class MetadataFactory {
*/
public static IUpdateDescriptor createUpdateDescriptor(String id, VersionRange range, int severity, String description, URI location) {
Collection<IMatchExpression<IInstallableUnit>> descriptors = new ArrayList<>(1);
- descriptors.add(createMatchExpressionFromRange(IInstallableUnit.NAMESPACE_IU_ID, id, range));
+ descriptors.add(RequiredCapability.createMatchExpressionFromRange(IInstallableUnit.NAMESPACE_IU_ID, id, range));
return createUpdateDescriptor(descriptors, severity, description, location);
}
- private static final IExpression allVersionsExpression;
- private static final IExpression range_II_Expression;
- private static final IExpression range_IN_Expression;
- private static final IExpression range_NI_Expression;
- private static final IExpression range_NN_Expression;
- private static final IExpression strictVersionExpression;
- private static final IExpression openEndedExpression;
- private static final IExpression openEndedNonInclusiveExpression;
-
- static {
- IExpressionFactory factory = ExpressionUtil.getFactory();
- IExpression xVar = factory.variable("x"); //$NON-NLS-1$
- IExpression nameEqual = factory.equals(factory.member(xVar, ProvidedCapability.MEMBER_NAME), factory.indexedParameter(0));
- IExpression namespaceEqual = factory.equals(factory.member(xVar, ProvidedCapability.MEMBER_NAMESPACE), factory.indexedParameter(1));
-
- IExpression versionMember = factory.member(xVar, ProvidedCapability.MEMBER_VERSION);
-
- IExpression versionCmpLow = factory.indexedParameter(2);
- IExpression versionEqual = factory.equals(versionMember, versionCmpLow);
- IExpression versionGt = factory.greater(versionMember, versionCmpLow);
- IExpression versionGtEqual = factory.greaterEqual(versionMember, versionCmpLow);
-
- IExpression versionCmpHigh = factory.indexedParameter(3);
- IExpression versionLt = factory.less(versionMember, versionCmpHigh);
- IExpression versionLtEqual = factory.lessEqual(versionMember, versionCmpHigh);
-
- IExpression pvMember = factory.member(factory.thisVariable(), InstallableUnit.MEMBER_PROVIDED_CAPABILITIES);
- allVersionsExpression = factory.exists(pvMember, factory.lambda(xVar, factory.and(nameEqual, namespaceEqual)));
- strictVersionExpression = factory.exists(pvMember, factory.lambda(xVar, factory.and(nameEqual, namespaceEqual, versionEqual)));
- openEndedExpression = factory.exists(pvMember, factory.lambda(xVar, factory.and(nameEqual, namespaceEqual, versionGtEqual)));
- openEndedNonInclusiveExpression = factory.exists(pvMember, factory.lambda(xVar, factory.and(nameEqual, namespaceEqual, versionGt)));
- range_II_Expression = factory.exists(pvMember, factory.lambda(xVar, factory.and(nameEqual, namespaceEqual, versionGtEqual, versionLtEqual)));
- range_IN_Expression = factory.exists(pvMember, factory.lambda(xVar, factory.and(nameEqual, namespaceEqual, versionGtEqual, versionLt)));
- range_NI_Expression = factory.exists(pvMember, factory.lambda(xVar, factory.and(nameEqual, namespaceEqual, versionGt, versionLtEqual)));
- range_NN_Expression = factory.exists(pvMember, factory.lambda(xVar, factory.and(nameEqual, namespaceEqual, versionGt, versionLt)));
- }
-
- private static IMatchExpression<IInstallableUnit> createMatchExpressionFromRange(String namespace, String name, VersionRange range) {
- IMatchExpression<IInstallableUnit> resultExpression = null;
- IExpressionFactory factory = ExpressionUtil.getFactory();
- if (range == null || range.equals(VersionRange.emptyRange)) {
- resultExpression = factory.matchExpression(allVersionsExpression, name, namespace);
- } else {
- if (range.getMinimum().equals(range.getMaximum())) {
- // Explicit version appointed
- resultExpression = factory.matchExpression(strictVersionExpression, name, namespace, range.getMinimum());
- } else {
- if (range.getMaximum().equals(Version.MAX_VERSION)) {
- // Open ended
- resultExpression = factory.matchExpression(range.getIncludeMinimum() ? openEndedExpression : openEndedNonInclusiveExpression, name, namespace, range.getMinimum());
- } else {
- resultExpression = factory.matchExpression(//
- range.getIncludeMinimum() ? (range.getIncludeMaximum() ? range_II_Expression : range_IN_Expression) //
- : (range.getIncludeMaximum() ? range_NI_Expression : range_NN_Expression), //
- name, namespace, range.getMinimum(), range.getMaximum());
- }
- }
- }
- return resultExpression;
- }
-
private static ITouchpointType getCachedTouchpointType(String id, Version version) {
for (int i = 0; i < typeCache.length; i++) {
if (typeCache[i] != null && typeCache[i].getId().equals(id) && typeCache[i].getVersion().equals(version))
diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java
index f8885db4a..b3dd86965 100644
--- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java
+++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java
@@ -19,7 +19,6 @@ import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.*;
import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
import org.eclipse.equinox.internal.p2.extensionlocation.Constants;
-import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
import org.eclipse.equinox.internal.provisional.configurator.Configurator;
import org.eclipse.equinox.internal.provisional.p2.directorywatcher.RepositoryListener;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
@@ -131,7 +130,7 @@ public class ProfileSynchronizer {
if (!request.getRemovals().isEmpty()) {
Collection<IRequirement> requirements = new ArrayList<>();
for (IInstallableUnit unit : request.getRemovals()) {
- RequiredCapability req = new RequiredCapability(IInstallableUnit.NAMESPACE_IU_ID, unit.getId(), new VersionRange(unit.getVersion(), true, unit.getVersion(), true), null, 0, 0, false, null);
+ IRequirement req = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, unit.getId(), new VersionRange(unit.getVersion(), true, unit.getVersion(), true), null, 0, 0, false);
requirements.add(req);
}
request.addExtraRequirements(requirements);
diff --git a/bundles/org.eclipse.equinox.p2.tests/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.equinox.p2.tests/.settings/org.eclipse.jdt.ui.prefs
index 04ec8c288..3d1eb862a 100644
--- a/bundles/org.eclipse.equinox.p2.tests/.settings/org.eclipse.jdt.ui.prefs
+++ b/bundles/org.eclipse.equinox.p2.tests/.settings/org.eclipse.jdt.ui.prefs
@@ -4,8 +4,8 @@ formatter_profile=_core
formatter_settings_version=11
org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=;
-org.eclipse.jdt.ui.ondemandthreshold=3
-org.eclipse.jdt.ui.staticondemandthreshold=3
+org.eclipse.jdt.ui.ondemandthreshold=99
+org.eclipse.jdt.ui.staticondemandthreshold=99
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates/>
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/AllTests.java
index 0a4facfe9..05bf2f2df 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/AllTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/AllTests.java
@@ -11,7 +11,10 @@
*******************************************************************************/
package org.eclipse.equinox.p2.tests.metadata;
-import junit.framework.*;
+import junit.framework.JUnit4TestAdapter;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
/**
* Performs all metadata tests.
@@ -32,6 +35,7 @@ public class AllTests extends TestCase {
suite.addTestSuite(PersistFragment.class);
suite.addTestSuite(ProvidedCapabilityTest.class);
suite.addTestSuite(RequirementToString.class);
+ suite.addTest(new JUnit4TestAdapter(RequirementParsingTest.class));
return suite;
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/PersistNegation.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/PersistNegation.java
index a98a347a5..dd431635a 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/PersistNegation.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/PersistNegation.java
@@ -15,9 +15,13 @@ import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.equinox.internal.p2.metadata.ProvidedCapability;
-import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
import org.eclipse.equinox.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IProvidedCapability;
+import org.eclipse.equinox.p2.metadata.IRequirement;
+import org.eclipse.equinox.p2.metadata.MetadataFactory;
+import org.eclipse.equinox.p2.metadata.Version;
+import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
@@ -29,7 +33,7 @@ public class PersistNegation extends AbstractProvisioningTest {
iud1.setId("NegateRWT");
iud1.setVersion(Version.create("1.0.0"));
- RequiredCapability req1 = new RequiredCapability(IInstallableUnit.NAMESPACE_IU_ID, "org.eclipse.rap.rwt", new VersionRange("[1.0.0, 2.0.0)"), null, 0, 0, false, null);
+ IRequirement req1 = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "org.eclipse.rap.rwt", new VersionRange("[1.0.0, 2.0.0)"), null, 0, 0, false, null);
Collection<IRequirement> requirements = new ArrayList<>();
requirements.add(req1);
iud1.addRequirements(requirements);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementParsingTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementParsingTest.java
new file mode 100644
index 000000000..8e09111ae
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementParsingTest.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2017 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * EclipseSource - ongoing development
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.metadata;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
+import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IRequirement;
+import org.eclipse.equinox.p2.metadata.MetadataFactory;
+import org.eclipse.equinox.p2.metadata.VersionRange;
+import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
+import org.eclipse.equinox.p2.metadata.expression.IExpression;
+import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
+import org.junit.Test;
+
+public class RequirementParsingTest {
+
+ @Test
+ public void testIRequirementType() {
+ String namespace = "osgi.ee";
+ String ldap = "(&(osgi.ee=JavaSE)(version=1.7))";
+ String match = "providedCapabilities.exists(pc | pc.namespace == '" + namespace + "' && pc.attributes ~= filter('" + ldap + "'))";
+
+ IExpression expr = ExpressionUtil.parse(match);
+ IMatchExpression<IInstallableUnit> matchExpr = ExpressionUtil.getFactory().matchExpression(expr);
+
+ IRequirement req = MetadataFactory.createRequirement(matchExpr, (IMatchExpression<IInstallableUnit>) null, 0, 1, false);
+ assertFalse(req instanceof IRequiredCapability);
+ }
+
+ @Test
+ public void testIRquiredCapabilityType() {
+ String namespace = "java.package";
+ String name = "org.example";
+ VersionRange range = VersionRange.create("[1, 2)");
+
+ IRequirement req = null;
+
+ req = MetadataFactory.createRequirement(namespace, name, range, (IMatchExpression<IInstallableUnit>) null, 0, 1, false);
+ assertTrue(req instanceof IRequiredCapability);
+
+ req = MetadataFactory.createRequirement(namespace, name, range, (IMatchExpression<IInstallableUnit>) null, 0, 1, false, null);
+ assertTrue(req instanceof IRequiredCapability);
+
+ req = MetadataFactory.createRequirement(namespace, name, range, (IMatchExpression<IInstallableUnit>) null, false, false);
+ assertTrue(req instanceof IRequiredCapability);
+
+ req = MetadataFactory.createRequirement(namespace, name, range, (String) null, false, false, false);
+ assertTrue(req instanceof IRequiredCapability);
+ }
+
+ @Test
+ public void testIRquiredCapabilityDetection() {
+ String namespace = "java.package";
+ String name = "org.example";
+ VersionRange range = VersionRange.create("[1, 2)");
+
+ IMatchExpression<IInstallableUnit> matchExpr = RequiredCapability.createMatchExpressionFromRange(namespace, name, range);
+
+ IRequirement req = null;
+
+ req = MetadataFactory.createRequirement(matchExpr, (IMatchExpression<IInstallableUnit>) null, 0, 1, false);
+ assertTrue(req instanceof IRequiredCapability);
+
+ req = MetadataFactory.createRequirement(matchExpr, (IMatchExpression<IInstallableUnit>) null, 0, 1, false, null);
+ assertTrue(req instanceof IRequiredCapability);
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementToString.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementToString.java
index f0a36b170..1ccc188bf 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementToString.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementToString.java
@@ -3,21 +3,24 @@
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
+ *
+ * Contributors:
* Ericsson AB - initial API and implementation
******************************************************************************/
package org.eclipse.equinox.p2.tests.metadata;
-import org.eclipse.equinox.p2.metadata.*;
+import junit.framework.TestCase;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IRequirement;
+import org.eclipse.equinox.p2.metadata.MetadataFactory;
+import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
-import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
//These tests are not here to force the toString of a requirement.
//They are here to ensure that the toString of a requirement does not become unreadable because this ends up being presented in the p2 UI and in the tycho build.
//As such if there are better ways present all this information, by all mean change the test.
-public class RequirementToString extends AbstractProvisioningTest {
+public class RequirementToString extends TestCase {
public void testRequirementWithEmptyRange() {
IRequirement req = MetadataFactory.createRequirement("expectedNameSpace", "expectedName", VersionRange.emptyRange, null, false, false);
assertEquals("expectedNameSpace expectedName 0.0.0", req.toString());
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java
index 6f067c02f..022b6549f 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java
@@ -18,14 +18,38 @@ import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.equinox.internal.p2.metadata.*;
+import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
+import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
+import org.eclipse.equinox.internal.p2.metadata.ProvidedCapability;
+import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
import org.eclipse.equinox.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.IArtifactKey;
+import org.eclipse.equinox.p2.metadata.ICopyright;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IInstallableUnitFragment;
+import org.eclipse.equinox.p2.metadata.IInstallableUnitPatch;
+import org.eclipse.equinox.p2.metadata.ILicense;
+import org.eclipse.equinox.p2.metadata.IProvidedCapability;
+import org.eclipse.equinox.p2.metadata.IRequirement;
+import org.eclipse.equinox.p2.metadata.IRequirementChange;
+import org.eclipse.equinox.p2.metadata.ITouchpointData;
+import org.eclipse.equinox.p2.metadata.ITouchpointInstruction;
+import org.eclipse.equinox.p2.metadata.ITouchpointType;
+import org.eclipse.equinox.p2.metadata.IUpdateDescriptor;
+import org.eclipse.equinox.p2.metadata.MetadataFactory;
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitPatchDescription;
-import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
+import org.eclipse.equinox.p2.metadata.Version;
+import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.MatchQuery;
@@ -57,32 +81,29 @@ public class SPIMetadataRepositoryTest extends AbstractProvisioningTest {
super.tearDown();
}
- class SPIRequiredCapability extends MatchQuery<IInstallableUnit> implements IRequiredCapability {
- IMatchExpression<IInstallableUnit> filter;
- String name;
- String namespace;
- VersionRange versionRange;
- boolean isGreedy;
- int min;
- int max;
- private String description;
+ class SPIRequiredCapability implements IRequiredCapability {
+ private final IMatchExpression<IInstallableUnit> filter;
+ private final String name;
+ private final String namespace;
+ private final VersionRange versionRange;
+ private final boolean isGreedy;
+ private final int min;
+ private final int max;
+
+ public SPIRequiredCapability(String namespace, String name, VersionRange versionRange) {
+ this(namespace, name, versionRange, null, true, false, false);
+ }
public SPIRequiredCapability(String namespace, String name, VersionRange versionRange, String filter, boolean isGreedy, boolean isMultiple, boolean isOptional) {
this.namespace = namespace;
this.name = name;
this.versionRange = versionRange;
- setFilter(filter);
+ this.filter = filter == null ? null : InstallableUnit.parseFilter(filter);
this.isGreedy = isGreedy;
this.min = isOptional ? 0 : 1;
this.max = isMultiple ? Integer.MAX_VALUE : 1;
}
- public SPIRequiredCapability(String namespace, String name, VersionRange versionRange) {
- this.namespace = namespace;
- this.name = name;
- this.versionRange = versionRange;
- }
-
@Override
public IMatchExpression<IInstallableUnit> getFilter() {
return this.filter;
@@ -108,40 +129,28 @@ public class SPIMetadataRepositoryTest extends AbstractProvisioningTest {
return isGreedy;
}
- public void setFilter(String filter) {
- this.filter = filter == null ? null : InstallableUnit.parseFilter(filter);
- }
-
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
+ }
- if (!(obj instanceof IRequirement))
+ if (!(obj instanceof IRequirement)) {
return false;
+ }
IRequirement other = (IRequirement) obj;
if (filter == null) {
- if (other.getFilter() != null)
+ if (other.getFilter() != null) {
return false;
- } else if (!filter.equals(other.getFilter()))
+ }
+ } else if (!filter.equals(other.getFilter())) {
return false;
+ }
return min == other.getMin() && max == other.getMax() && isGreedy == other.isGreedy() && getMatches().equals(other.getMatches());
}
- public boolean isNegation() {
- return false;
- }
-
- public boolean satisfiedBy(IProvidedCapability cap) {
- if (getName() == null || !getName().equals(cap.getName()))
- return false;
- if (getNamespace() == null || !getNamespace().equals(cap.getNamespace()))
- return false;
- return getRange().isIncluded(cap.getVersion());
- }
-
@Override
public int getMin() {
return min;
@@ -154,30 +163,23 @@ public class SPIMetadataRepositoryTest extends AbstractProvisioningTest {
@Override
public boolean isMatch(IInstallableUnit candidate) {
- if (!candidate.satisfies(this))
- return false;
- return true;
- }
-
- public boolean isVersionStrict() {
- // TODO Auto-generated method stub
- return false;
+ return candidate.satisfies(this);
}
@Override
public IMatchExpression<IInstallableUnit> getMatches() {
- return ExpressionUtil.getFactory().matchExpression(ExpressionUtil.parse("providedCapabilities.exists(x | x.name == $0 && x.namespace == $1 && x.version ~= $2)"), name, namespace, versionRange);
+ return RequiredCapability.createMatchExpressionFromRange(namespace, name, versionRange);
}
@Override
public String getDescription() {
- return description;
+ return "";
}
}
class SPIProvidedCapability implements IProvidedCapability {
- String namespace;
- Map<String, Object> attributes;
+ private final String namespace;
+ private final Map<String, Object> attributes;
public SPIProvidedCapability(String namespace, String name, Version version) {
this.namespace = namespace;
@@ -189,13 +191,17 @@ public class SPIMetadataRepositoryTest extends AbstractProvisioningTest {
@Override
public boolean equals(Object other) {
- if (!(other instanceof IProvidedCapability))
+ if (!(other instanceof IProvidedCapability)) {
return false;
+ }
+
IProvidedCapability otherCapability = (IProvidedCapability) other;
- if (!(namespace.equals(otherCapability.getNamespace())))
+ if (!(namespace.equals(otherCapability.getNamespace()))) {
return false;
- if (!(attributes.equals(otherCapability.getAttributes())))
+ }
+ if (!(attributes.equals(otherCapability.getAttributes()))) {
return false;
+ }
return true;
}
@@ -221,7 +227,7 @@ public class SPIMetadataRepositoryTest extends AbstractProvisioningTest {
@Override
public Map<String, Object> getAttributes() {
- return attributes;
+ return Collections.unmodifiableMap(attributes);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/Bug311330.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/Bug311330.java
index 4fc13ce00..ce3dca66b 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/Bug311330.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/Bug311330.java
@@ -13,10 +13,17 @@ package org.eclipse.equinox.p2.tests.planner;
import java.net.URI;
import java.util.ArrayList;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
-import org.eclipse.equinox.p2.core.*;
-import org.eclipse.equinox.p2.engine.*;
-import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;
+import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.engine.IProfileRegistry;
+import org.eclipse.equinox.p2.engine.IProvisioningPlan;
+import org.eclipse.equinox.p2.engine.ProvisioningContext;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IRequirement;
+import org.eclipse.equinox.p2.metadata.MetadataFactory;
+import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.planner.IPlanner;
import org.eclipse.equinox.p2.planner.IProfileChangeRequest;
import org.eclipse.equinox.p2.query.QueryUtil;
@@ -32,7 +39,7 @@ public class Bug311330 extends AbstractProvisioningTest {
assertFalse("rap.jface not found", sdkProfile.available(QueryUtil.createIUQuery("org.eclipse.rap.jface"), null).isEmpty());
// Force negation of rwt.
- RequiredCapability req1 = new RequiredCapability(IInstallableUnit.NAMESPACE_IU_ID, "org.eclipse.rap.jface", new VersionRange("[1.1.0, 1.4.0)"), null, 0, 0, false, null);
+ IRequirement req1 = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "org.eclipse.rap.jface", new VersionRange("[1.1.0, 1.4.0)"), null, 0, 0, false, null);
ArrayList<IRequirement> reqs = new ArrayList<>();
reqs.add(req1);
request.addExtraRequirements(reqs);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NegationTesting.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NegationTesting.java
index 28189d0bc..6862f1216 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NegationTesting.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NegationTesting.java
@@ -10,17 +10,24 @@
*******************************************************************************/
package org.eclipse.equinox.p2.tests.planner;
-import java.util.*;
+import static org.eclipse.equinox.p2.metadata.IInstallableUnit.NAMESPACE_IU_ID;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
import org.eclipse.equinox.internal.p2.director.Slicer;
import org.eclipse.equinox.internal.p2.engine.ProvisioningPlan;
-import org.eclipse.equinox.internal.p2.metadata.ProvidedCapability;
-import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
import org.eclipse.equinox.internal.provisional.p2.director.PlannerStatus;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProvisioningPlan;
-import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IProvidedCapability;
+import org.eclipse.equinox.p2.metadata.IRequirement;
+import org.eclipse.equinox.p2.metadata.MetadataFactory;
+import org.eclipse.equinox.p2.metadata.Version;
+import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.planner.IPlanner;
import org.eclipse.equinox.p2.planner.IProfileChangeRequest;
import org.eclipse.equinox.p2.query.IQueryable;
@@ -56,14 +63,14 @@ public class NegationTesting extends AbstractProvisioningTest {
MetadataFactory.InstallableUnitDescription iud1 = new MetadataFactory.InstallableUnitDescription();
iud1.setId("TestNegation4");
iud1.setVersion(Version.create("1.0.0"));
- RequiredCapability req1 = new RequiredCapability(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false, null);
- RequiredCapability req2 = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 2.0.0)"), null, false, false);
+ IRequirement req1 = MetadataFactory.createRequirement(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false);
+ IRequirement req2 = MetadataFactory.createRequirement(NS, N, new VersionRange("[1.0.0, 2.0.0)"), null, false, false);
Collection<IRequirement> requirements = new ArrayList<>();
requirements.add(req1);
requirements.add(req2);
iud1.addRequirements(requirements);
Collection<IProvidedCapability> capabilities = new ArrayList<>();
- capabilities.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
+ capabilities.add(MetadataFactory.createProvidedCapability(NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
iud1.addProvidedCapabilities(capabilities);
IInstallableUnit iu1 = MetadataFactory.createInstallableUnit(iud1);
@@ -80,7 +87,7 @@ public class NegationTesting extends AbstractProvisioningTest {
iud3.setVersion(Version.create("1.0.0"));
Collection<IProvidedCapability> capabilities3 = new ArrayList<>();
capabilities3.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.1.1")));
- capabilities3.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "ProviderOf1_1_1", Version.create("1.0.0")));
+ capabilities3.add(MetadataFactory.createProvidedCapability(NAMESPACE_IU_ID, "ProviderOf1_1_1", Version.create("1.0.0")));
iud3.addProvidedCapabilities(capabilities3);
IInstallableUnit iu3 = MetadataFactory.createInstallableUnit(iud3);
@@ -114,14 +121,14 @@ public class NegationTesting extends AbstractProvisioningTest {
MetadataFactory.InstallableUnitDescription iud1 = new MetadataFactory.InstallableUnitDescription();
iud1.setId("TestNegation4");
iud1.setVersion(Version.create("1.0.0"));
- RequiredCapability req1 = new RequiredCapability(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false, null);
- RequiredCapability req2 = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 1.1.0)"), null, false, false);
+ IRequirement req1 = MetadataFactory.createRequirement(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false);
+ IRequirement req2 = MetadataFactory.createRequirement(NS, N, new VersionRange("[1.0.0, 1.1.0)"), null, false, false);
Collection<IRequirement> requirements = new ArrayList<>();
requirements.add(req1);
requirements.add(req2);
iud1.addRequirements(requirements);
Collection<IProvidedCapability> capabilities = new ArrayList<>();
- capabilities.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
+ capabilities.add(MetadataFactory.createProvidedCapability(NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
iud1.addProvidedCapabilities(capabilities);
IInstallableUnit iu1 = MetadataFactory.createInstallableUnit(iud1);
@@ -138,7 +145,7 @@ public class NegationTesting extends AbstractProvisioningTest {
iud3.setVersion(Version.create("1.0.0"));
Collection<IProvidedCapability> capabilities3 = new ArrayList<>();
capabilities3.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.1.1")));
- capabilities3.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "ProviderOf1_1_1", Version.create("1.0.0")));
+ capabilities3.add(MetadataFactory.createProvidedCapability(NAMESPACE_IU_ID, "ProviderOf1_1_1", Version.create("1.0.0")));
iud3.addProvidedCapabilities(capabilities3);
IInstallableUnit iu3 = MetadataFactory.createInstallableUnit(iud3);
@@ -155,14 +162,14 @@ public class NegationTesting extends AbstractProvisioningTest {
MetadataFactory.InstallableUnitDescription iud1 = new MetadataFactory.InstallableUnitDescription();
iud1.setId("TestNegation4");
iud1.setVersion(Version.create("1.0.0"));
- RequiredCapability req1 = new RequiredCapability(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false, null);
- RequiredCapability req2 = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 1.1.0)"), null, false, false);
+ IRequirement req1 = MetadataFactory.createRequirement(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false);
+ IRequirement req2 = MetadataFactory.createRequirement(NS, N, new VersionRange("[1.0.0, 1.1.0)"), null, false, false);
Collection<IRequirement> requirements = new ArrayList<>();
requirements.add(req1);
requirements.add(req2);
iud1.addRequirements(requirements);
Collection<IProvidedCapability> capabilities = new ArrayList<>();
- capabilities.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
+ capabilities.add(MetadataFactory.createProvidedCapability(NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
iud1.addProvidedCapabilities(capabilities);
IInstallableUnit iu1 = MetadataFactory.createInstallableUnit(iud1);
@@ -197,14 +204,14 @@ public class NegationTesting extends AbstractProvisioningTest {
MetadataFactory.InstallableUnitDescription iud1 = new MetadataFactory.InstallableUnitDescription();
iud1.setId("TestNegation4");
iud1.setVersion(Version.create("1.0.0"));
- RequiredCapability req1 = new RequiredCapability(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false, null);
- RequiredCapability req2 = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 2.0.0)"), null, false, false);
+ IRequirement req1 = MetadataFactory.createRequirement(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false);
+ IRequirement req2 = MetadataFactory.createRequirement(NS, N, new VersionRange("[1.0.0, 2.0.0)"), null, false, false);
Collection<IRequirement> requirements = new ArrayList<>();
requirements.add(req1);
requirements.add(req2);
iud1.addRequirements(requirements);
Collection<IProvidedCapability> capabilities = new ArrayList<>();
- capabilities.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
+ capabilities.add(MetadataFactory.createProvidedCapability(NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
iud1.addProvidedCapabilities(capabilities);
IInstallableUnit iu1 = MetadataFactory.createInstallableUnit(iud1);
@@ -221,7 +228,7 @@ public class NegationTesting extends AbstractProvisioningTest {
iud3.setVersion(Version.create("1.0.0"));
Collection<IProvidedCapability> capabilities3 = new ArrayList<>();
capabilities3.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.1.1")));
- capabilities3.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "ProviderOf1_1_1", Version.create("1.0.0")));
+ capabilities3.add(MetadataFactory.createProvidedCapability(NAMESPACE_IU_ID, "ProviderOf1_1_1", Version.create("1.0.0")));
iud3.addProvidedCapabilities(capabilities3);
Collection<IRequirement> requirements3 = new ArrayList<>();
requirements3.add(MetadataFactory.createRequirement("DOES-NOT-EXIST", "NEVER", new VersionRange("[1.0.0, 2.0.0)"), null, false, false));
@@ -258,14 +265,14 @@ public class NegationTesting extends AbstractProvisioningTest {
MetadataFactory.InstallableUnitDescription iud1 = new MetadataFactory.InstallableUnitDescription();
iud1.setId("TestNegation4");
iud1.setVersion(Version.create("1.0.0"));
- RequiredCapability req1 = new RequiredCapability(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false, null);
- RequiredCapability req2 = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 2.0.0)"), null, false, false);
+ IRequirement req1 = MetadataFactory.createRequirement(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false);
+ IRequirement req2 = MetadataFactory.createRequirement(NS, N, new VersionRange("[1.0.0, 2.0.0)"), null, false, false);
Collection<IRequirement> requirements = new ArrayList<>();
requirements.add(req1);
requirements.add(req2);
iud1.addRequirements(requirements);
Collection<IProvidedCapability> capabilities = new ArrayList<>();
- capabilities.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
+ capabilities.add(MetadataFactory.createProvidedCapability(NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
iud1.addProvidedCapabilities(capabilities);
IInstallableUnit iu1 = MetadataFactory.createInstallableUnit(iud1);
@@ -282,7 +289,7 @@ public class NegationTesting extends AbstractProvisioningTest {
iud3.setVersion(Version.create("1.0.0"));
Collection<IProvidedCapability> capabilities3 = new ArrayList<>();
capabilities3.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.1.1")));
- capabilities3.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "ProviderOf1_1_1", Version.create("1.0.0")));
+ capabilities3.add(MetadataFactory.createProvidedCapability(NAMESPACE_IU_ID, "ProviderOf1_1_1", Version.create("1.0.0")));
iud3.addProvidedCapabilities(capabilities3);
IInstallableUnit iu3 = MetadataFactory.createInstallableUnit(iud3);
@@ -290,10 +297,10 @@ public class NegationTesting extends AbstractProvisioningTest {
iud4.setId("AnotherRoot");
iud4.setVersion(Version.create("1.0.0"));
Collection<IProvidedCapability> capabilities4 = new ArrayList<>();
- capabilities4.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "AnotherRoot", Version.create("1.0.0")));
+ capabilities4.add(MetadataFactory.createProvidedCapability(NAMESPACE_IU_ID, "AnotherRoot", Version.create("1.0.0")));
iud4.addProvidedCapabilities(capabilities4);
Collection<IRequirement> reqs4 = new ArrayList<>();
- reqs4.add(new RequiredCapability(NS, N, new VersionRange("[1.1.1, 1.1.1]"), null, false, false));
+ reqs4.add(MetadataFactory.createRequirement(NS, N, new VersionRange("[1.1.1, 1.1.1]"), null, false, false));
iud4.addRequirements(reqs4);
IInstallableUnit iu4 = MetadataFactory.createInstallableUnit(iud4);
@@ -336,7 +343,7 @@ public class NegationTesting extends AbstractProvisioningTest {
IProfileChangeRequest request = planner.createChangeRequest(profile);
request.add(iu);
- IRequirement req1 = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, iu.getId(), new VersionRange(iu.getVersion(), true, iu.getVersion(), true), null, 0, 0, false, null);
+ IRequirement req1 = MetadataFactory.createRequirement(NAMESPACE_IU_ID, iu.getId(), new VersionRange(iu.getVersion(), true, iu.getVersion(), true), null, 0, 0, false, null);
ArrayList<IRequirement> reqs = new ArrayList<>();
reqs.add(req1);
request.addExtraRequirements(reqs);
@@ -350,15 +357,15 @@ public class NegationTesting extends AbstractProvisioningTest {
MetadataFactory.InstallableUnitDescription iud1 = new MetadataFactory.InstallableUnitDescription();
iud1.setId("TestNegation4");
iud1.setVersion(Version.create("1.0.0"));
- RequiredCapability req1 = new RequiredCapability(NS, N, new VersionRange("[0.0.0, 1.1.1)"), null, 0, 0, false, null);
- RequiredCapability req2 = new RequiredCapability(NS, N, new VersionRange(Version.create("1.1.1"), false, Version.MAX_VERSION, false), null, 0, 0, false, null);
+ IRequirement req1 = MetadataFactory.createRequirement(NS, N, new VersionRange("[0.0.0, 1.1.1)"), null, 0, 0, false);
+ IRequirement req2 = MetadataFactory.createRequirement(NS, N, new VersionRange(Version.create("1.1.1"), false, Version.MAX_VERSION, false), null, 0, 0, false);
Collection<IRequirement> requirements = new ArrayList<>();
requirements.add(req1);
requirements.add(req2);
iud1.addRequirements(requirements);
Collection<IProvidedCapability> capabilities = new ArrayList<>();
- capabilities.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
- capabilities.add(new ProvidedCapability(NS, N, Version.create("1.1.1")));
+ capabilities.add(MetadataFactory.createProvidedCapability(NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
+ capabilities.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.1.1")));
iud1.addProvidedCapabilities(capabilities);
IInstallableUnit iu1 = MetadataFactory.createInstallableUnit(iud1);
@@ -383,6 +390,5 @@ public class NegationTesting extends AbstractProvisioningTest {
changeRequest2.add(iu2);
ProvisioningPlan plan2 = (ProvisioningPlan) planner.getProvisioningPlan(changeRequest2, null, null);
assertNotOK(plan2.getStatus());
-
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PatchTestUsingNegativeRequirement.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PatchTestUsingNegativeRequirement.java
index 6b457c84d..9db3c0e77 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PatchTestUsingNegativeRequirement.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PatchTestUsingNegativeRequirement.java
@@ -13,9 +13,16 @@ package org.eclipse.equinox.p2.tests.planner;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
-import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
-import org.eclipse.equinox.p2.engine.*;
-import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.engine.IEngine;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.engine.IProvisioningPlan;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IInstallableUnitPatch;
+import org.eclipse.equinox.p2.metadata.IRequirement;
+import org.eclipse.equinox.p2.metadata.IRequirementChange;
+import org.eclipse.equinox.p2.metadata.MetadataFactory;
+import org.eclipse.equinox.p2.metadata.Version;
+import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.planner.IPlanner;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
@@ -37,7 +44,7 @@ public class PatchTestUsingNegativeRequirement extends AbstractProvisioningTest
a1 = createIU("A", Version.create("1.0.0"), new IRequirement[] {MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "B", new VersionRange("[1.0.0, 1.1.0)"), null, false, true), MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "C", new VersionRange("[1.0.0, 1.0.0]"), null, false, true)});
b1 = createIU("B", Version.createOSGi(1, 2, 0), true);
c1 = createIU("C", Version.createOSGi(1, 0, 0), true);
- RequiredCapability negativeRequirementForPatch = new RequiredCapability(IInstallableUnit.NAMESPACE_IU_ID, "B", VersionRange.emptyRange, null, 0, 0, false, null);
+ IRequirement negativeRequirementForPatch = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "B", VersionRange.emptyRange, null, 0, 0, false, null);
IRequirementChange change = MetadataFactory.createRequirementChange(MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "B", VersionRange.emptyRange, null, false, false, false), negativeRequirementForPatch);
p1 = createIUPatch("P", Version.create("1.0.0"), true, new IRequirementChange[] {change}, new IRequirement[][] {{MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "A", VersionRange.emptyRange, null, false, false)}}, null);

Back to the top