Question

p2 has a query language that allows to run queries on the content of a p2 repository. However all examples in the documentation assume that the query language is used from within Java, e.g.

IQuery<IInstallableUnit> q = QueryUtil.createMatchQuery("this.id == $0", id);
metadataRepository.query(q);

How can I execute a query from the command line (without writing my own Java application)?

Was it helpful?

Solution

The p2 director application has an option to list or query the content of the given p2 repositories. With -list you'd get all units, and with -list Q:<p2 QL collection query> you can query for a subset.

The expression needs to be a collection query, so instead of the match query in the example given above, you need to use the equivalent collection query. Also, placeholders like $1 must be replaced by the actual values.

Example: The command line to look for the all org.eclipse.sdk.ide units in the Juno release train repository would be

eclipse -application org.eclipse.equinox.p2.director \
   -repository http://download.eclipse.org/releases/juno \
   -list 'Q:everything.select(x | x.id == "org.eclipse.sdk.ide")'

As a more useful example, you could use this command to find all units which are shown in categories in the p2 user interface (although I wouldn't try a large repository, the query seems to be quite slow):

eclipse -application org.eclipse.equinox.p2.director \
   -repository <URL of some small repository> \
   -list 'Q:everything.select(y | everything.select(x | x.properties ~= filter("(org.eclipse.equinox.p2.type.category=true)")).collect(x | x.requirements).flatten().exists(r | y ~= r))'

OTHER TIPS

p2diff tool written by Ian Bull is is well worth mentioning. His article provides an overview of the p2 API and introduces some of the key concepts that should be understood to work with the p2 API.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top