1 /******************************************************************************* 2 * Copyright (c) 2008, 2017 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.equinox.p2.tests.planner; 15 16 import java.util.Set; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.equinox.internal.p2.director.Explanation; 19 import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest; 20 import org.eclipse.equinox.internal.p2.engine.ProvisioningPlan; 21 import org.eclipse.equinox.internal.provisional.p2.director.PlannerStatus; 22 import org.eclipse.equinox.internal.provisional.p2.director.RequestStatus; 23 import org.eclipse.equinox.p2.engine.*; 24 import org.eclipse.equinox.p2.metadata.*; 25 import org.eclipse.equinox.p2.planner.IPlanner; 26 import org.eclipse.equinox.p2.planner.ProfileInclusionRules; 27 import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; 28 29 public class PatchTest12 extends AbstractProvisioningTest { 30 IInstallableUnit a1; 31 IInstallableUnit b1; 32 IInstallableUnit b2; 33 IInstallableUnitPatch p1; 34 35 IProfile profile1; 36 IPlanner planner; 37 IEngine engine; 38 39 @Override setUp()40 protected void setUp() throws Exception { 41 super.setUp(); 42 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, true)}); 43 b1 = createIU("B", Version.createOSGi(1, 0, 0), true); 44 b2 = createIU("B", Version.createOSGi(1, 2, 0), true); 45 IRequirementChange change = MetadataFactory.createRequirementChange(MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "B", VersionRange.emptyRange, null, false, false, false), MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "B", new VersionRange("[1.4.0, 1.5.0)"), null, false, true, true)); 46 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); 47 48 createTestMetdataRepository(new IInstallableUnit[] {a1, b1, b2, p1}); 49 50 profile1 = createProfile("TestProfile." + getName()); 51 planner = createPlanner(); 52 engine = createEngine(); 53 } 54 testInstallBogusInstallFilterInPatch()55 public void testInstallBogusInstallFilterInPatch() { 56 //Try to install a1 and p1 optionally 57 //p1 ends up being not installed because the new requirements that it sets on A for B can not be met (no B are matching). 58 //the only thing that ends up being installed are A 1.0.0 and B 1.0.0 59 ProfileChangeRequest req2 = new ProfileChangeRequest(profile1); 60 req2.addInstallableUnits(new IInstallableUnit[] {a1, p1}); 61 req2.setInstallableUnitInclusionRules(p1, ProfileInclusionRules.createOptionalInclusionRule(p1)); 62 IProvisioningPlan plan2 = planner.getProvisioningPlan(req2, null, null); 63 assertTrue(IStatus.ERROR != plan2.getStatus().getSeverity()); 64 assertNoOperand(plan2, p1); 65 assertNoOperand(plan2, b2); 66 assertNoOperand(plan2, p1); 67 assertInstallOperand(plan2, a1); 68 assertInstallOperand(plan2, b1); 69 70 //Try to install a1 and p1. This should fail because the patch adds an invalid filter 71 ProfileChangeRequest req3 = new ProfileChangeRequest(profile1); 72 req3.addInstallableUnits(new IInstallableUnit[] {a1, p1}); 73 IProvisioningPlan plan3 = planner.getProvisioningPlan(req3, null, null); 74 assertTrue(IStatus.ERROR == plan3.getStatus().getSeverity()); 75 76 } 77 testExplanation1()78 public void testExplanation1() { 79 ProfileChangeRequest req3 = new ProfileChangeRequest(profile1); 80 req3.addInstallableUnits(new IInstallableUnit[] {a1, p1}); 81 ProvisioningPlan plan3 = (ProvisioningPlan) planner.getProvisioningPlan(req3, null, null); 82 assertTrue(IStatus.ERROR == plan3.getStatus().getSeverity()); 83 final RequestStatus requestStatus = ((PlannerStatus) plan3.getStatus()).getRequestStatus(); 84 Set<IInstallableUnit> conflictRootIUs = requestStatus.getConflictsWithInstalledRoots(); 85 assertTrue(conflictRootIUs.contains(p1)); 86 assertEquals(Explanation.MISSING_REQUIREMENT, requestStatus.getShortExplanation()); 87 } 88 } 89