Skip to main content
summaryrefslogtreecommitdiffstats
blob: d88e0fd39c9fa98f156f1e7f634d2da0075dabf0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*******************************************************************************
 *  Copyright (c) 2009 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
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.planner;

import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;

import java.net.URI;
import java.util.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.director.SimplePlanner;
import org.eclipse.equinox.internal.provisional.p2.director.PlanExecutionHelper;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.*;
import org.eclipse.equinox.p2.metadata.*;
import org.eclipse.equinox.p2.planner.IPlanner;
import org.eclipse.equinox.p2.planner.ProfileInclusionRules;
import org.eclipse.equinox.p2.query.*;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;

public class SimulatedSharedInstallTest extends AbstractProvisioningTest {

	IInstallableUnit a1;
	IInstallableUnit b1;
	IInstallableUnit c1;

	IPlanner planner;
	IProfile profile;
	IEngine engine;

	protected void setUp() throws Exception {
		super.setUp();
		a1 = createIU("A", Version.parseVersion("1.0.0"), createRequiredCapabilities(IInstallableUnit.NAMESPACE_IU_ID, "B", new VersionRange("[1.0.0, 1.0.0]")));
		b1 = createIU("B", Version.parseVersion("1.0.0"));
		// Note: C has an "optional" dependency on "B"
		c1 = createIU("C", Version.parseVersion("1.0.0"), new IRequirement[] {MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "B", new VersionRange("[1.0.0, 1.0.0]"), null, true, false)});
		profile = createProfile(SimulatedSharedInstallTest.class.getName());
		planner = createPlanner();
		engine = createEngine();
	}

	public void testRemoveUnresolvedIU() {
		final ProvisioningContext context = new ProvisioningContext(getAgent());
		IProvisioningPlan plan = engine.createPlan(profile, context);
		plan.addInstallableUnit(a1);
		plan.setInstallableUnitProfileProperty(a1, SimplePlanner.INCLUSION_RULES, ProfileInclusionRules.createStrictInclusionRule(a1));
		context.setMetadataRepositories(new URI[0]);
		assertEquals(IStatus.OK, engine.perform(plan, new NullProgressMonitor()).getSeverity());
		assertContains(profile.query(QueryUtil.createIUAnyQuery(), null), a1);

		IProvisioningPlan plan2 = engine.createPlan(profile, context);
		plan2.removeInstallableUnit(a1);

		assertEquals(IStatus.OK, plan2.getStatus().getSeverity());
		assertEquals(IStatus.OK, PlanExecutionHelper.executePlan(plan2, engine, context, new NullProgressMonitor()).getSeverity());
		assertNotContains(profile.query(QueryUtil.createIUAnyQuery(), null), a1);
	}

	public void testAvailableVsQueryInProfile() {
		final ProvisioningContext context = new ProvisioningContext(getAgent());
		IProvisioningPlan plan = engine.createPlan(profile, context);
		plan.addInstallableUnit(c1);
		plan.setInstallableUnitProfileProperty(c1, SimplePlanner.INCLUSION_RULES, ProfileInclusionRules.createStrictInclusionRule(c1));
		context.setMetadataRepositories(new URI[0]);
		assertEquals(IStatus.OK, engine.perform(plan, new NullProgressMonitor()).getSeverity());
		assertContains(profile.query(QueryUtil.createIUAnyQuery(), null), c1);

		IProfile availableWrapper = new IProfile() {
			public IQueryResult<IInstallableUnit> available(IQuery<IInstallableUnit> query, IProgressMonitor monitor) {
				IQueryResult queryResult = profile.query(query, monitor);
				Collector collector = new Collector();
				collector.addAll(queryResult);

				Collection ius = new ArrayList();
				ius.add(b1);
				collector.addAll(query.perform(ius.iterator()));
				return collector;
			}

			// everything else is delegated
			public Map getInstallableUnitProperties(IInstallableUnit iu) {
				return profile.getInstallableUnitProperties(iu);
			}

			public String getInstallableUnitProperty(IInstallableUnit iu, String key) {
				return profile.getInstallableUnitProperty(iu, key);
			}

			public String getProfileId() {
				return profile.getProfileId();
			}

			public Map getProperties() {
				return profile.getProperties();
			}

			public String getProperty(String key) {
				return profile.getProperty(key);
			}

			public long getTimestamp() {
				return profile.getTimestamp();
			}

			public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor) {
				return profile.query(query, monitor);
			}

			public IProvisioningAgent getProvisioningAgent() {
				return profile.getProvisioningAgent();
			}
		};

		ProfileChangeRequest req = new ProfileChangeRequest(availableWrapper);
		req.addInstallableUnits(new IInstallableUnit[] {a1});
		IProvisioningPlan plan2 = planner.getProvisioningPlan(req, null, null);
		assertEquals(IStatus.OK, plan2.getStatus().getSeverity());

		//expect to have both (a1+inclusion rule) and b1 added
		assertEquals(2, countPlanElements(plan2));
	}
}

Back to the top