Author: Alin Dreghciu
Tags: nexus, osgi, plugins
Categories: Nexus, Sonatype, OSGi
Back in 2009 we added support for P2 repositories as part of Sonatype Pro™ for Nexus that allowed proxing and grouping of P2 repositories. Now we added a new major feature: Expose OSGi bundles from a Maven repository as a standard P2 repository. In addition we are now open sourcing the Nexus P2 Repository plugin, under AGPL license, so you can use it with Nexus OSS.
So, what is this new feature?
If you are doing Maven based OSGi development, as for example by using Maven Bundle Plugin, you are creating OSGi bundles that gets deployed to Maven repositories. Up till now there was no way to use this bundles in a P2 enabled tool such as Eclipse itself or Tycho. Thats no longer the case, as the new feature introduced by Nexus P2 Repository plugin will automatically create a P2 repository that include this bundles.
How does it work?
As soon as an OSGi bundle gets deployed to a Nexus Maven repository, P2 metadata will be automatically generated and stored alongside the bundle using classifiers. Then this P2 metadata, corresponding to deployed bundle will be aggregated into an P2 repository containing all the bundles from that Maven repository. The aggregate P2 repository will be available from root of Maven repository plus "/.meta/p2".
Lets take as example our test Nexus instance available at http://grid.sonatype.org:9000/nexus. We have a proxy of Maven Central , that is also used by Nexus Bundle Maker plugin, at http://grid.sonatype.org:9000/nexus/content/repositories/central/. To access this repository as a P2 repository, the URL will be http://grid.sonatype.org:9000/nexus/content/repositories/central/.meta/p2.
|The Test Setup Is No Longer Running|
The test server is no longer running, but we will try to setup a new example infrastructure soon.
As explained above we are first generating P2 metadata. We do that in order to allow custom deployment of this metadata instead of automatic generating it. This allows developers to provide their own p2Artifacts/p2Metadata xmls. The files are standard P2 artifacts/content xmls that only contain one artifact/IU that should match the bundle they are deployed alongside.
Lets take for example a bundle with foo:bar:10:jar Maven coordinates. When this bundle gets deployed it will deploy two files /foo/bar/1.0/bar-1.0.pom and /foo/bar/1.0/bar-1.0.jar. Then the new plugin will read the manifest of bar-1.0.jar bundle and will automatically create /foo/bar/1.0/bar-1.0-p2Artifacts.xml (P2 artifacts.xml) and /foo/bar/1.0/bar-1.0-p2Content.xml (P2 content.xml). If this automatically generated will not suffice you can deploy your own ones that will override the automatically generated ones and be used in the aggregated P2 repository.
But what if I do not have OSGi bundles
If you are need of an standard non OSGi jar to be available via a P2 repository you can make use of Nexus Bundle Maker plugin which will automatically transform the jar into an OSGi bundle. Once that happens the newly created OSGi bundle will be available via P2 repository, using same process as explained above.
Where is the source code
You can clone the source code from our GitHub repository at firstname.lastname@example.org:sonatype/nexus-p2-repository-plugin.git or browse it at https://github.com/sonatype/nexus-p2-repository-plugin. If you wanna contribute just fork it and let us know about your changes with a pull request.
How do I build it?
Building the Nexus P2 Repository Plugin* is simple as mvn clean install.
Can I just download & use it?
Nexus P2 repository Plugin bundle is available in Sonatype repository as well as the other dependent plugins.
How do I get it running in Nexus
You will need Nexus 1.9.2 with the following plugins installed:
- Nexus Capability Plugin (available under optional plugins in your Nexus installation)
- Nexus P2 Bridge Plugin. You can build it by yourself from email@example.com:sonatype/nexus-p2-bridge-plugin.git or download it from Sonatype repository
- Nexus P2 Repository Plugin. You can build it by yourself from firstname.lastname@example.org:sonatype/nexus-p2-repository-plugin.git or download it from Sonatype repository
Then unpack and copy this plugins into sonatype-work/nexus/plugin-repository and (re)start Nexus.
Next steps are to configure the capabilities in top of repository you want to be exposed as P2 repository:
First, configure the P2 Metadata Generator Capability:
Second, configure the P2 Repository Aggregator Capability:
Note that this is an experimental feature which we hope will ease adoption of OSGi. Give it a try and let us know how we can improve it.