Skip to main content
summaryrefslogtreecommitdiffstats
blob: 41460f283b2490f0dd0b9d894a5d8dcf276db155 (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
/*******************************************************************************
 *  Copyright (c) 2008, 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.internal.p2.director;

import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnitPatch;
import org.eclipse.equinox.internal.provisional.p2.metadata.query.MatchQuery;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;

/**
 * A query that accepts any patch that applies to a given installable unit.
 */
public class ApplicablePatchQuery extends MatchQuery<IInstallableUnit> {
	IInstallableUnit iu;

	/**
	 * Creates a new patch query on the given installable unit. Patches that can
	 * be applied to this unit will be accepted as matches by the query.
	 * @param iu The unit to compare patches against
	 */
	public ApplicablePatchQuery(IInstallableUnit iu) {
		this.iu = iu;
	}

	public boolean isMatch(IInstallableUnit candidate) {
		if (!(candidate instanceof IInstallableUnitPatch))
			return false;
		IInstallableUnitPatch patchIU = (IInstallableUnitPatch) candidate;
		IRequirement[][] scopeDescription = patchIU.getApplicabilityScope();
		if (scopeDescription.length == 0)
			return true;

		for (int i = 0; i < scopeDescription.length; i++) {
			int matchedScopeEntry = scopeDescription[i].length;
			for (int j = 0; j < scopeDescription[i].length; j++) {
				if (iu.satisfies(scopeDescription[i][j]))
					matchedScopeEntry--;
			}
			if (matchedScopeEntry == 0)
				return true;
		}
		return false;
	}
}

Back to the top