Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 222157 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/p2/director/Projector.java (-6 / +20 lines)
Lines 378-386 Link Here
378
		if (!isApplicable(req))
378
		if (!isApplicable(req))
379
			return;
379
			return;
380
		List<IInstallableUnit> matches = getApplicableMatches(req);
380
		List<IInstallableUnit> matches = getApplicableMatches(req);
381
		if (isHostRequirement(iu, req)) {
382
			rememberHostMatches((IInstallableUnitFragment) iu, matches);
383
		}
384
		if (req.getMin() > 0) {
381
		if (req.getMin() > 0) {
385
			if (matches.isEmpty()) {
382
			if (matches.isEmpty()) {
386
				missingRequirement(iu, req);
383
				missingRequirement(iu, req);
Lines 439-444 Link Here
439
			//Patches are applicable to the IU
436
			//Patches are applicable to the IU
440
			expandRequirementsWithPatches(iu, applicablePatches, isRootIU);
437
			expandRequirementsWithPatches(iu, applicablePatches, isRootIU);
441
		}
438
		}
439
		determinePotentialHostsForFragment(iu);
440
	}
441
442
	/**
443
	 * Determines all potential hosts for a fragment.
444
	 * A potential host is an IU that satisfies requirements specified for fragment.
445
	 *  
446
	 * @param iu an eventual fragment. It does nothing if IU is not a fragment or is null
447
	 */
448
	private void determinePotentialHostsForFragment(IInstallableUnit iu) {
449
		// determine matching hosts only for fragments
450
		if (!(iu instanceof IInstallableUnitFragment))
451
			return;
452
453
		IInstallableUnitFragment fragment = (IInstallableUnitFragment) iu;
454
		// for each host requirement, find matches and remember them 
455
		for (IRequirement req : fragment.getHost()) {
456
			List<IInstallableUnit> matches = getApplicableMatches(req);
457
			rememberHostMatches((IInstallableUnitFragment) iu, matches);
458
		}
442
	}
459
	}
443
460
444
	private Collection<IRequirement> getRequiredCapabilities(IInstallableUnit iu) {
461
	private Collection<IRequirement> getRequiredCapabilities(IInstallableUnit iu) {
Lines 499-507 Link Here
499
				if (isApplicable(reqs[i][1])) {
516
				if (isApplicable(reqs[i][1])) {
500
					IRequirement req = reqs[i][1];
517
					IRequirement req = reqs[i][1];
501
					List<IInstallableUnit> matches = getApplicableMatches(req);
518
					List<IInstallableUnit> matches = getApplicableMatches(req);
502
					if (isHostRequirement(iu, req)) {
503
						rememberHostMatches((IInstallableUnitFragment) iu, matches);
504
					}
505
					if (req.getMin() > 0) {
519
					if (req.getMin() > 0) {
506
						if (matches.isEmpty()) {
520
						if (matches.isEmpty()) {
507
							missingRequirement(patch, req);
521
							missingRequirement(patch, req);
(-)src/org/eclipse/equinox/internal/p2/metadata/InstallableUnitFragment.java (-14 lines)
Lines 11-17 Link Here
11
package org.eclipse.equinox.internal.p2.metadata;
11
package org.eclipse.equinox.internal.p2.metadata;
12
12
13
import java.util.Collection;
13
import java.util.Collection;
14
import java.util.List;
15
import org.eclipse.equinox.p2.metadata.IInstallableUnitFragment;
14
import org.eclipse.equinox.p2.metadata.IInstallableUnitFragment;
16
import org.eclipse.equinox.p2.metadata.IRequirement;
15
import org.eclipse.equinox.p2.metadata.IRequirement;
17
16
Lines 27-45 Link Here
27
		if (hostRequirements == null)
26
		if (hostRequirements == null)
28
			return;
27
			return;
29
		this.hostRequirements = hostRequirements;
28
		this.hostRequirements = hostRequirements;
30
		addRequiredCapability(hostRequirements);
31
	}
32
33
	private void addRequiredCapability(Collection<IRequirement> toAdd) {
34
		List<IRequirement> current = super.getRequirements();
35
		int currSize = current.size();
36
		IRequirement[] result = new IRequirement[currSize + toAdd.size()];
37
		int i = 0;
38
		for (; i < currSize; ++i)
39
			result[i] = current.get(i);
40
		for (IRequirement requirement : toAdd)
41
			result[i++] = requirement;
42
		setRequiredCapabilities(result);
43
	}
29
	}
44
30
45
	public Collection<IRequirement> getHost() {
31
	public Collection<IRequirement> getHost() {
(-)src/org/eclipse/equinox/p2/tests/metadata/FragmentTest.java (+60 lines)
Lines 13-18 Link Here
13
import java.util.*;
13
import java.util.*;
14
import junit.framework.AssertionFailedError;
14
import junit.framework.AssertionFailedError;
15
import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest;
15
import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest;
16
import org.eclipse.equinox.p2.engine.IProvisioningPlan;
16
import org.eclipse.equinox.p2.metadata.*;
17
import org.eclipse.equinox.p2.metadata.*;
17
import org.eclipse.equinox.p2.query.QueryUtil;
18
import org.eclipse.equinox.p2.query.QueryUtil;
18
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
19
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
Lines 96-101 Link Here
96
		throw new AssertionFailedError("No capability for the iu id");
97
		throw new AssertionFailedError("No capability for the iu id");
97
	}
98
	}
98
99
100
	/**
101
	 * Test that fragments does not affect the solution when the fragments do not have requirements.
102
	 * This mean that having a fragment that has a host requirement that cannot be satisfied it will not determine solver to fail to find a solution.
103
	 * This case is valid only in the context that bug #222157 is solved, meaning that host requirements are not supposed to be expressed also 
104
	 * as requirements (which was the case described also in #222158) 
105
	 * 
106
	 * This test does not include the host IU in request or metadata repository.
107
	 */
108
	public void testFragmentsOptionality1() {
109
		testFragmentsOptionality(false);
110
	}
111
112
	/**
113
	 * Test that fragments does not affect the solution when the fragments do not have requirements.
114
	 * This mean that having a fragment that has a host requirement that cannot be satisfied it will not determine solver to fail to find a solution.
115
	 * This case is valid only in the context that bug #222157 is solved, meaning that host requirements are not supposed to be expressed also 
116
	 * as requirements (which was the case described also in #222158) 
117
	 * 
118
	 * This test does not include the host IU in request but it includes it in metadata repository.
119
	 */
120
	public void testFragmentsOptionality2() {
121
		testFragmentsOptionality(true);
122
	}
123
124
	private void testFragmentsOptionality(boolean includeHostIUInRepository) {
125
		String ID1 = "iu.test1";
126
		String ID2 = "iu.test2";
127
		String ID3 = "iuFragment.test3";
128
		IInstallableUnit iu1 = createEclipseIU(ID1);
129
		IInstallableUnit iu2 = createEclipseIU(ID2);
130
		IInstallableUnit iu3 = createIUFragment(iu1, ID3, DEFAULT_VERSION);
131
132
		ProfileChangeRequest req = new ProfileChangeRequest(createProfile(getName()));
133
		req.addAll(Arrays.asList(iu2, iu3));
134
135
		if (includeHostIUInRepository) {
136
			createTestMetdataRepository(new IInstallableUnit[] {iu1, iu2, iu3});
137
		} else {
138
			createTestMetdataRepository(new IInstallableUnit[] {iu2, iu3});
139
		}
140
141
		IProvisioningPlan provisioningPlan = createPlanner().getProvisioningPlan(req, null, null);
142
143
		{
144
			Iterator<IInstallableUnit> iterator = provisioningPlan.getAdditions().query(QueryUtil.createIUQuery(ID1), null).iterator();
145
			assertTrue("IU " + ID1 + " not expected as part of solution", !iterator.hasNext());
146
		}
147
		{
148
			Iterator<IInstallableUnit> iterator = provisioningPlan.getAdditions().query(QueryUtil.createIUQuery(ID2), null).iterator();
149
			assertTrue("IU " + ID2 + " expected as part of solution", iterator.hasNext());
150
			assertEquals("Number of fragments", 0, iterator.next().getFragments().size());
151
		}
152
		{
153
			Iterator<IInstallableUnit> iterator = provisioningPlan.getAdditions().query(QueryUtil.createIUQuery(ID3), null).iterator();
154
			assertTrue("IU " + ID3 + " expected as part of solution", iterator.hasNext());
155
			assertEquals("Number of fragments", 0, iterator.next().getFragments().size());
156
		}
157
	}
158
99
	public static void assertContains(Object[] objects, Object searched) {
159
	public static void assertContains(Object[] objects, Object searched) {
100
		for (int i = 0; i < objects.length; i++) {
160
		for (int i = 0; i < objects.length; i++) {
101
			if (objects[i] == searched)
161
			if (objects[i] == searched)

Return to bug 222157