Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c8bb15f62d02847b7bcd082481a2981d4db6124b (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*******************************************************************************
 *  Copyright (c) 2010, 2017 IBM Corporation 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:
 *      IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.planner;

import java.io.File;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
import org.eclipse.equinox.p2.core.*;
import org.eclipse.equinox.p2.engine.*;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.planner.IPlanner;
import org.eclipse.equinox.p2.planner.ProfileInclusionRules;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;

public class Bug300104 extends AbstractProvisioningTest {
	String profileLoadedId = "SDKProfile";
	IMetadataRepository repo = null;
	IProvisioningAgent agent = null;
	private IProfileRegistry profileRegistry;

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		File reporegistry1 = getTestData("test data bug 300104", "testData/bug300104/p2");
		File tempFolder = new File(getTempFolder(), "p2");
		copy("0.2", reporegistry1, tempFolder);

		IProvisioningAgentProvider provider = getAgentProvider();
		agent = provider.createAgent(tempFolder.toURI());
		profileRegistry = ((IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME));
		assertNotNull(profileRegistry.getProfile(profileLoadedId));
	}

	IInstallableUnit getIU(IMetadataRepository source, String id, String version) {
		IQueryResult<IInstallableUnit> c = repo.query(QueryUtil.createIUQuery(id, Version.create(version)), new NullProgressMonitor());
		assertEquals(1, queryResultSize(c));
		return c.iterator().next();
	}

	public void testInstallPatchesInOrder() throws ProvisionException {

		// generated metadata was massaged to remove artifact aspects which would require tests to also
		// provide artifacts.

		boolean optional = true;
		installHello(optional);

		applyHelloPatch1();

		applyHelloPatch2();

	}

	public void testInstallPatchesInOrderStricy() throws ProvisionException {

		// generated metadata was massaged to remove artifact aspects which would require tests to also
		// provide artifacts.

		boolean optional = false;
		installHello(optional);

		applyHelloPatch1();

		applyHelloPatch2();

	}

	public void testInstallOnlyLaterPatch() throws ProvisionException {
		boolean optional = true;
		installHello(optional);

		applyHelloPatch2();
	}

	private void installHello(boolean optional) throws ProvisionException {
		// install hello 1.0 and related feature.
		repo = loadMetadataRepository(getTestData("Repository for 300104", "testData/bug300104/hello1.0").toURI());
		ProfileChangeRequest installFeature1 = new ProfileChangeRequest(profileRegistry.getProfile(profileLoadedId));
		IInstallableUnit featureGroup = getIU(repo, "hellofeature.feature.group", "1.0.0.200911201237");
		IInstallableUnit featureJar = getIU(repo, "hellofeature.feature.jar", "1.0.0.200911201237");
		IInstallableUnit helloIU = getIU(repo, "hello", "1.0.0.200911201237");

		installFeature1.addInstallableUnits(new IInstallableUnit[] {featureGroup, featureJar, helloIU});

		installFeature1.setInstallableUnitInclusionRules(featureGroup, createInclusionRule(featureGroup, optional));
		installFeature1.setInstallableUnitInclusionRules(featureJar, ProfileInclusionRules.createOptionalInclusionRule(featureJar));
		installFeature1.setInstallableUnitInclusionRules(helloIU, ProfileInclusionRules.createOptionalInclusionRule(helloIU));

		IProvisioningPlan feature1Plan = getPlannerService().getProvisioningPlan(installFeature1, new ProvisioningContext(getAgent()), null);
		assertOK("installation of feature1", getEngineService().perform(feature1Plan, new NullProgressMonitor()));
		assertEquals(1, queryResultSize(profileRegistry.getProfile(profileLoadedId).query(QueryUtil.createIUQuery("hello", Version.create("1.0.0.200911201237")), new NullProgressMonitor())));
	}

	private IEngine getEngineService() {
		return ((IEngine) agent.getService(IEngine.SERVICE_NAME));
	}

	private IPlanner getPlannerService() {
		return ((IPlanner) agent.getService(IPlanner.SERVICE_NAME));
	}

	private String createInclusionRule(IInstallableUnit unit, boolean optional) {
		return optional ? ProfileInclusionRules.createOptionalInclusionRule(unit) : ProfileInclusionRules.createStrictInclusionRule(unit);
	}

	private void applyHelloPatch1() throws ProvisionException {
		// install first feature patch which updates hello to version 1.0.1
		/*
		    <unit id='hellopatch.feature.group' version='1.0.0' singleton='false'>
		    <unit id='hellopatch.feature.jar' version='1.0.0'>
		    <unit id='hello' version='1.0.1.200911201237'>
		*/

		repo = loadMetadataRepository(getTestData("Repository for 300104", "testData/bug300104/hellopatch1").toURI());

		ProfileChangeRequest installFeature1 = new ProfileChangeRequest(profileRegistry.getProfile(profileLoadedId));
		IInstallableUnit featureGroup = getIU(repo, "hellopatch.feature.group", "1.0.0");
		IInstallableUnit featureJar = getIU(repo, "hellopatch.feature.jar", "1.0.0");
		IInstallableUnit helloIU = getIU(repo, "hello", "1.0.1.200911201237");

		installFeature1.addInstallableUnits(new IInstallableUnit[] {featureGroup, featureJar, helloIU});

		installFeature1.setInstallableUnitInclusionRules(featureGroup, ProfileInclusionRules.createOptionalInclusionRule(featureGroup));
		installFeature1.setInstallableUnitInclusionRules(featureJar, ProfileInclusionRules.createOptionalInclusionRule(featureJar));
		installFeature1.setInstallableUnitInclusionRules(helloIU, ProfileInclusionRules.createOptionalInclusionRule(helloIU));

		IProvisioningPlan feature1Plan = getPlannerService().getProvisioningPlan(installFeature1, new ProvisioningContext(getAgent()), null);
		assertOK("installation of feature1", getEngineService().perform(feature1Plan, new NullProgressMonitor()));
		assertEquals(0, queryResultSize(profileRegistry.getProfile(profileLoadedId).query(QueryUtil.createIUQuery("hello", Version.create("1.0.0.200911201237")), new NullProgressMonitor())));
		assertEquals(1, queryResultSize(profileRegistry.getProfile(profileLoadedId).query(QueryUtil.createIUQuery("hello", Version.create("1.0.1.200911201237")), new NullProgressMonitor())));
	}

	private void applyHelloPatch2() throws ProvisionException {
		// install newer version of feature patch which updates
		// hello to version 1.0.1 with later qualifier and
		// adds unit hello2 1.0.0
		/*
		    <unit id='hellopatch.feature.group' version='1.0.1.200911201358' singleton='false'>
		    <unit id='hellopatch.feature.jar' version='1.0.1.200911201358'>
			<unit id='hello' version='1.0.1.200911201358'>
			<unit id='hello2' version='1.0.0.200911201358'>
		*/

		repo = loadMetadataRepository(getTestData("Repository for 300104", "testData/bug300104/hellopatch2").toURI());

		ProfileChangeRequest installFeature1 = new ProfileChangeRequest(profileRegistry.getProfile(profileLoadedId));
		IInstallableUnit featureGroup = getIU(repo, "hellopatch.feature.group", "1.0.1.200911201358");
		IInstallableUnit featureJar = getIU(repo, "hellopatch.feature.jar", "1.0.1.200911201358");
		IInstallableUnit helloIU = getIU(repo, "hello", "1.0.1.200911201358");
		IInstallableUnit hello2IU = getIU(repo, "hello2", "1.0.0.200911201358");

		installFeature1.addInstallableUnits(new IInstallableUnit[] {featureGroup, featureJar, helloIU, hello2IU});

		installFeature1.setInstallableUnitInclusionRules(featureGroup, ProfileInclusionRules.createOptionalInclusionRule(featureGroup));
		installFeature1.setInstallableUnitInclusionRules(featureJar, ProfileInclusionRules.createOptionalInclusionRule(featureJar));
		installFeature1.setInstallableUnitInclusionRules(helloIU, ProfileInclusionRules.createOptionalInclusionRule(helloIU));
		installFeature1.setInstallableUnitInclusionRules(hello2IU, ProfileInclusionRules.createOptionalInclusionRule(hello2IU));

		IProvisioningPlan feature1Plan = getPlannerService().getProvisioningPlan(installFeature1, new ProvisioningContext(getAgent()), null);
		assertOK("installation of feature1", getEngineService().perform(feature1Plan, new NullProgressMonitor()));
		assertEquals(1, queryResultSize(profileRegistry.getProfile(profileLoadedId).query(QueryUtil.createIUQuery("hello2", Version.create("1.0.0.200911201358")), new NullProgressMonitor())));

		assertEquals(0, queryResultSize(profileRegistry.getProfile(profileLoadedId).query(QueryUtil.createIUQuery("hello", Version.create("1.0.0.200911201237")), new NullProgressMonitor())));
		assertEquals(0, queryResultSize(profileRegistry.getProfile(profileLoadedId).query(QueryUtil.createIUQuery("hello", Version.create("1.0.1.200911201237")), new NullProgressMonitor())));
		assertEquals(1, queryResultSize(profileRegistry.getProfile(profileLoadedId).query(QueryUtil.createIUQuery("hello", Version.create("1.0.1.200911201358")), new NullProgressMonitor())));
	}
}

Back to the top