Skip to main content
summaryrefslogtreecommitdiffstats
blob: 049a097de7bf231749fb7d151f29bae3b96804bf (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
/*******************************************************************************
 * Copyright (c) 2008 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.metadata.generator;

import java.util.*;
import org.eclipse.equinox.internal.p2.metadata.generator.features.ProductFile;
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.internal.provisional.p2.metadata.generator.MetadataGeneratorHelper;
import org.eclipse.equinox.internal.provisional.p2.metadata.generator.Generator.GeneratorResult;
import org.eclipse.equinox.internal.provisional.p2.query.Query;
import org.eclipse.osgi.service.resolver.VersionRange;

public class ProductQuery extends Query {
	private static final String EQUINOX_LAUNCHER = "org.eclipse.equinox.launcher"; //$NON-NLS-1$

	private final ProductFile product;
	private final String flavor;
	private final Map children = new HashMap();

	public ProductQuery(ProductFile product, String flavor, Map configIUs) {
		this.product = product;
		this.flavor = flavor;
		initialize(configIUs);
	}

	private void initialize(Map configIUs) {
		boolean features = product.useFeatures();
		List contents = features ? product.getFeatures() : product.getPlugins();
		for (Iterator iterator = contents.iterator(); iterator.hasNext();) {
			String item = (String) iterator.next();
			if (features) // for features we want the group
				item = MetadataGeneratorHelper.getTransformedId(item, false, true);

			children.put(item, VersionRange.emptyRange);
			if (configIUs.containsKey(item)) {
				for (Iterator ius = ((Set) configIUs.get(item)).iterator(); ius.hasNext();) {
					IInstallableUnit object = (IInstallableUnit) ius.next();
					children.put(object.getId(), new VersionRange(object.getVersion(), true, object.getVersion(), true));
				}
			}
		}

		//also include the launcher CU fragments as a workaround to bug 218890
		String launcherPrefix = product.getId() + ".launcher"; //$NON-NLS-1$
		if (configIUs.containsKey(launcherPrefix)) {
			for (Iterator ius = ((Set) configIUs.get(launcherPrefix)).iterator(); ius.hasNext();) {
				IInstallableUnit object = (IInstallableUnit) ius.next();
				children.put(object.getId(), new VersionRange(object.getVersion(), true, object.getVersion(), true));
			}
		}

		//also add the launcher.jar
		if (!children.containsKey(EQUINOX_LAUNCHER)) {
			children.put(EQUINOX_LAUNCHER, VersionRange.emptyRange);
			children.put(flavor + EQUINOX_LAUNCHER, VersionRange.emptyRange);
		}

		// and launcher fragment CUs
		if (configIUs.containsKey(EQUINOX_LAUNCHER)) {
			for (Iterator ius = ((Set) configIUs.get(EQUINOX_LAUNCHER)).iterator(); ius.hasNext();) {
				IInstallableUnit object = (IInstallableUnit) ius.next();
				children.put(object.getId(), new VersionRange(object.getVersion(), true, object.getVersion(), true));
			}
		}

		// feature based product, individual bundle config CUs are under CONFIGURATION_CUS for convenience
		if (features && configIUs.containsKey(GeneratorResult.CONFIGURATION_CUS)) {
			for (Iterator ius = ((Set) configIUs.get(GeneratorResult.CONFIGURATION_CUS)).iterator(); ius.hasNext();) {
				IInstallableUnit object = (IInstallableUnit) ius.next();
				children.put(object.getId(), new VersionRange(object.getVersion(), true, object.getVersion(), true));
			}
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.equinox.internal.provisional.p2.query.Query#isMatch(java.lang.Object)
	 */
	public boolean isMatch(Object object) {
		if (!(object instanceof IInstallableUnit))
			return false;

		IInstallableUnit candidate = (IInstallableUnit) object;
		VersionRange range = (VersionRange) children.get(candidate.getId());
		if (range != null) {
			return range.isIncluded(candidate.getVersion());
		}

		return false;
	}
}

Back to the top