Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[p2-dev] New Query API Questions; Migrating from my own ContextQuery

Hey, all. I'm working on a tool that adds bundles, features, packages
(essentially IUs) to your target platform from a p2 repository (via
quickfix and a new fancy search dialog). In the past, I was able to do
something like this via a custom ContextQuery. How would I do
something similar now using the new query API and searching for
particular java packages? I essentially need to search for a specific
package and know what IU it belongs too (in the simplest case).

public class IUNameMatchingQuery extends ContextQuery {

	/**
	 * Performs this query on the given iterator, passing all objects in
the iterator
	 * that match the criteria of this query to the given result.
	 */
	public final IQueryResult perform(Iterator iterator) {
		Collector result = new Collector();
		while (iterator.hasNext()) {
			Object candidate = iterator.next();
			if (candidate instanceof IInstallableUnit) {
				result.accept(candidate);
				addPackages(candidate, result);
			}
		}
		return result;
	}

	private void addPackages(Object candidate, Collector result) {
		if (candidate instanceof IInstallableUnit) {
			IInstallableUnit iu = (IInstallableUnit) candidate;
			Collection providedCapabilities = iu.getProvidedCapabilities();
			Iterator iterator = providedCapabilities.iterator();
			while (iterator.hasNext()) {
				IProvidedCapability providedCapability = (IProvidedCapability)
iterator.next();
				if (providedCapability.getNamespace().equals("java.package")) {
//$NON-NLS-1$
					result.accept(new IUPackage(iu, providedCapability.getName(),
providedCapability.getVersion()));
				}
			}
		}
	}
}

Cheers,

-- 
Chris Aniszczyk | EclipseSource Austin | +1 860 839 2465
http://twitter.com/eclipsesource | http://twitter.com/caniszczyk


Back to the top