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

One more thing:

If you are willing to sacrifice the IUPackage collection and instead use the query to search for specific packages, you can probably gain a lot of performance since the actual capability name will be indexed, i.e.

IQuery query = QueryUtil.createMatchQuery("providedCapabilities.exists(p | p.name == $0 && p.namespace == 'java.package')", packageName);

OR, first create an expression that can be reused multiple times with different parameters, i.e.

IExpression expression = ExpressionUtil.parse("providedCapabilities.exists(p | p.name == $0 && p.namespace == 'java.package')");
for(<each packageName>) {
IQuery query = QueryUtil.createMatchQuery(expression, packageName);

- thomas

On 03/01/2010 06:56 PM, Thomas Hallgren wrote:
Hi Chris,
The query that you show here builds a complex result. At the time of writing, the ql evaluator cannot create and return instances of a class like IUPackage so I suggest you divide the query into two steps. First a query that selects all IU's that provides something in the "java.package" namespace, and then a step that collects the actual packages. Something like this (I assume no generics since your example didn't show any)

IQuery query = QueryUtil.createMatchQuery("providedCapabilities.exists(p | p.namespace == 'java.package')");
HashSet iuPackages = new HashSet();
Iterator iter = queryable.query(query, monitor).iterator();
while(iter.hasNext()) {
IInstallableUnit iu = (IInstallableUnit)iter.next();
Iterator pcIter = iu.getProvidedCapabilities().iterator();
while (pcIter.hasNext()) {
IProvidedCapability pc = (IProvidedCapability)pcIter.next();
if (pc.getNamespace().equals("java.package"))
iuPackages.add(new IUPackage(iu, pc.getName(), pc.getVersion()));

- thomas

On 03/01/2010 06:35 PM, Chris Aniszczyk wrote:
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) {
                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)
if (providedCapability.getNamespace().equals("java.package")) {
result.accept(new IUPackage(iu, providedCapability.getName(),


_______________________________________________ p2-dev mailing list p2-dev@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/p2-dev