Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Dufour2019-03-21 08:35:14 -0400
committerGuillaume Dufour2019-03-26 09:11:49 -0400
commit26419f854298994e7b0dc0f877e2341ca22ca0ff (patch)
tree334351d40c78d2e2a2e377cdc93da42f411b51fe
parentf8826cbd2118a82aa411e3618be87949383b703e (diff)
downloadrt.equinox.p2-26419f854298994e7b0dc0f877e2341ca22ca0ff.tar.gz
rt.equinox.p2-26419f854298994e7b0dc0f877e2341ca22ca0ff.tar.xz
rt.equinox.p2-26419f854298994e7b0dc0f877e2341ca22ca0ff.zip
Change-Id: Ide139d91c50befe7eab1b16f7e3a549358ea09d8 Signed-off-by: Guillaume Dufour <guillaume.duff@gmail.com>
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/InstallableUnitPatch.java17
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/AllTests.java1
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/InstallableUnitPatchTest.java59
3 files changed, 75 insertions, 2 deletions
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/InstallableUnitPatch.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/InstallableUnitPatch.java
index ce3e5acbf..2c5135ac9 100644
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/InstallableUnitPatch.java
+++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/InstallableUnitPatch.java
@@ -13,6 +13,7 @@
******************************************************************************/
package org.eclipse.equinox.internal.p2.metadata;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
import org.eclipse.equinox.p2.metadata.*;
@@ -32,8 +33,20 @@ public class InstallableUnitPatch extends InstallableUnit implements IInstallabl
IRequirement[] result = new IRequirement[currSize + toAdd.length];
for (int i = 0; i < currSize; ++i)
result[i] = current.get(i);
- System.arraycopy(toAdd, 0, result, current.size(), toAdd.length);
- setRequiredCapabilities(result);
+ System.arraycopy(toAdd, 0, result, currSize, toAdd.length);
+ super.setRequiredCapabilities(result);
+ }
+
+ @Override
+ public void setRequiredCapabilities(IRequirement[] capabilities) {
+ IRequirement[] result = capabilities;
+ if(lifeCycle != null && !Arrays.asList(capabilities).contains(lifeCycle)) {
+ int currSize = capabilities.length;
+ result = new IRequirement[currSize + 1];
+ System.arraycopy(capabilities, 0, result, 0, capabilities.length);
+ result[currSize]=lifeCycle;
+ }
+ super.setRequiredCapabilities(result);
}
@Override
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 df8db6349..50726068a 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
@@ -30,6 +30,7 @@ public class AllTests extends TestCase {
suite.addTestSuite(FragmentMethodTest.class);
suite.addTestSuite(FragmentTest.class);
suite.addTestSuite(InstallableUnitTest.class);
+ suite.addTestSuite(InstallableUnitPatchTest.class);
suite.addTestSuite(IUPersistenceTest.class);
suite.addTestSuite(LatestIUTest.class);
suite.addTestSuite(LicenseTest.class);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/InstallableUnitPatchTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/InstallableUnitPatchTest.java
new file mode 100644
index 000000000..ed71aa610
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/InstallableUnitPatchTest.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Guillaume Dufour and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Guillaume Dufour - test lifecycle requirement overwrite
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.metadata;
+
+import java.util.Arrays;
+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.MetadataFactory;
+import org.eclipse.equinox.p2.metadata.Version;
+import org.eclipse.equinox.p2.metadata.VersionRange;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+
+/**
+ * Black box tests for API of {@link org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnitPatch}.
+ */
+public class InstallableUnitPatchTest extends AbstractProvisioningTest {
+ /**
+ * Tests for {@link org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit#satisfies(org.eclipse.equinox.internal.provisional.p2.metadata.RequiredCapability)}.
+ */
+ public void testLifeCycleRequirement() {
+
+ org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitPatchDescription iu = new MetadataFactory.InstallableUnitPatchDescription();
+ iu.setId("P");
+ iu.setVersion(Version.create("1.0.0"));
+ iu.setApplicabilityScope(new IRequirement[][] {{MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "A", VersionRange.emptyRange, null, false, false)}});
+ IRequirement lRequirement = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "L", VersionRange.emptyRange, null, false, false);
+ iu.setLifeCycle(lRequirement);
+ iu.setRequirements(NO_REQUIRES);
+ IInstallableUnitPatch p1 = MetadataFactory.createInstallableUnitPatch(iu);
+
+ assertEquals("patch requirement must contains the lifecycle, so size must be equal to 1", 1, p1.getRequirements().size());
+ assertEquals("patch requirement must contains the lifecycle", lRequirement, p1.getRequirements().iterator().next());
+
+ org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitPatchDescription iu2 = new MetadataFactory.InstallableUnitPatchDescription();
+ iu2.setId("P2");
+ iu2.setVersion(Version.create("1.0.0"));
+ iu2.setApplicabilityScope(new IRequirement[][] {{MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "A2", VersionRange.emptyRange, null, false, false)}});
+ IRequirement l2Requirement = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "L2", VersionRange.emptyRange, null, false, false);
+ iu2.setLifeCycle(l2Requirement);
+ IRequirement r = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "R", VersionRange.emptyRange, null, false, false);
+ iu2.setRequirements(new IRequirement[] {r});
+ IInstallableUnitPatch p2 = MetadataFactory.createInstallableUnitPatch(iu2);
+
+ assertEquals("patch requirement must contains the lifecycle and the requirement, so size must be equal to 2", 2, p2.getRequirements().size());
+ assertContains("patch requirement must contains the lifecycle", p2.getRequirements().iterator(), Arrays.asList(l2Requirement, r));
+ }
+}

Back to the top