2

I have a bunch of different p2 repositories I want to query for information programmatically. What types of bundles/features do they provide? What type of licenses (if any) are paired with the bundles? And I'd like to simply download jars.

In other words, I want to programmatically query and download just about any public information contained in a p2 repository, but I don't need to actually do anything OSGi-related with this information.

Is there a relatively simple way to do this?

I have already tried a few things and found them not adequate:

Solution 1: p2 director:

I know about the p2 director, however I want to query the information from within a non-eclipse application and adding eclipse to then trigger commands via the command line seems like a bit of a weird detour. Also, that would restrict me to the rather limited interface of the p2 director (for instance, I think I can't just download a jar, I can just install it, which also unpacks it and maybe does other stuff I'm not aware of).

Solution 2: Building OSGi container manually:

Browsing the Eclipse APIs, I thought that it should be sufficient to have instances of IArtifactRepository/IMetadataRepository (see for instance: https://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fequinox%2Fp2%2Frepository%2Fartifact%2Fclass-use%2FIArtifactRepository.html). However, it seems not exactly trivial to get the artifacts. If I start from scratch, using the information provided in this anser here: Programmatically Start OSGi (Equinox)? I then have to build and initialize a IProvisioningAgentProvider, then an IProvisioningEventBus, then I need a registry, etc. It's quite hard to understand exactly what is needed and lots of the stuff is equinox-internals, so this also doesn't really seem to be the way to go.

Do any of the many equinox-related bundles offer an "easy" gateway to do this?

Martin
  • 237
  • 2
  • 9
  • A non-[composite](https://wiki.eclipse.org/Equinox/p2/Composite_Repositories_%28new%29) p2 repository contains the files `content.jar` and `artifacts.jar` which are simply zipped XML files and containing all repository metadata which you're looking for. Does this answer your question? – howlger Jan 30 '19 at 16:34
  • @howlger I know, thanks, but that would mean I'd have to write a parser for these xml files and the format of neither repository nor the xml files seems to be standardised as far as I can see, so the format might just randomly change. – Martin Jan 30 '19 at 17:14

1 Answers1

4

The bnd code base has a P2 repository that might be useful. The bnd command line allows you to use it interactively. First create a bndrun file repo.bndrun:

-standalone  true
-plugin.p2 \
    aQute.bnd.repository.p2.provider.P2Repository; \
            url="https://bndtools.jfrog.io/bndtools/update/"

In the same directory in the shell you can then do:

$ bnd repo -w repo.bndrun list

biz.aQute.bnd.maven                      [4.2.0.201901301338-SNAPSHOT]
biz.aQute.bndlib                         [4.2.0.201901301338-SNAPSHOT]
biz.aQute.repository                     [4.2.0.201901301338-SNAPSHOT]
biz.aQute.resolve                        [4.2.0.201901301338-SNAPSHOT]
...
org.bndtools.templating.gitrepo          [4.2.0.201901301338-SNAPSHOT]
org.bndtools.versioncontrol.ignores.manager [4.2.0.201901301338-SNAPSHOT]
org.bndtools.versioncontrol.ignores.plugin.git [4.2.0.201901301338-SNAPSHOT]
org.slf4j.api                            [1.7.2.v20121108-1250]

This will show a list of bsns and versions available in the p2 repo. You can also generate an OSGi XML index for OBR from it:

bnd repo -w repo.bndrun index 

This index is very easy to parsed and has an OSGi standardized format.

If you need the version of an artifact:

$ bnd repo -w repo.bndrun versions bndtools.api
[4.2.0.201901301338-SNAPSHOT]

You can also get artifacts from it:

$ bnd repo -w repo.bndrun get bndtools.api
$ ls -1
bndtools.api-4.2.0.201901301338-SNAPSHOT.jar
repo.bndrun

If you include biz.aQute.bndlib and biz.aQute.bnd.repository from Maven Central then you can also use the P2 repository from your code.

You can install the latest of bnd from brew for MacOS. On other OS'es you can download the biz.aQute.bnd JAR from Maven Central from group biz.aQute.bnd.

https://repo1.maven.org/maven2/biz/aQute/bnd/biz.aQute.bnd/4.1.0/biz.aQute.bnd-4.1.0.jar

[I am a committer on this project]

Jmini
  • 9,189
  • 2
  • 55
  • 77
Peter Kriens
  • 15,196
  • 1
  • 37
  • 55