Nexus OSGi Experimental Features - P2 Repository Plugin

Skip to end of metadata
Go to start of metadata

Title: Nexus OSGi Experimental Features - P2 Repository Plugin

Author: Alin Dreghciu

Tags: nexus, osgi, plugins

Categories: Nexus, Sonatype, OSGi

JIRA: https://issues.sonatype.org/browse/BLOG-199


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 git@github.com: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 git@github.com:sonatype/nexus-p2-bridge-plugin.git or download it from Sonatype repository
  • Nexus P2 Repository Plugin. You can build it by yourself from git@github.com: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.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Oct 14, 2011

    Anonymous says:

    Hi, this is pretty clever. Unfortunately it doesn't support features. Generate...

    Hi,

    this is pretty clever.

    Unfortunately it doesn't support features. Generated P2 repository holds only bundles.

    Regards,

  2. Dec 07, 2011

    JBert says:

    I wanted to add that the newest plugin snapshots require Nexus version 1.10.0-SN...

    I wanted to add that the newest plugin snapshots require Nexus version 1.10.0-SNAPSHOT.

    Since this version is not available on Sonatype's download page, you can look for it here:https://repository.sonatype.org/index.html#nexus-search;gav~org.sonatype.nexus~nexus-oss-webapp~~~bundle

    EDIT2: the 1.10.0-SNAPSHOT with timestamp 2011-12-06.23:38:16 works for me.

  3. Feb 15, 2012

    Anonymous says:

    We just tried to install the nexus-p2-repository-plugin to our Nexus OSS 2....

    We just tried to install the nexus-p2-repository-plugin to our Nexus OSS 2.0. We did it exactly as described in 'How do I get it running in Nexus'.

    We used Nexus 2.0 because the two plugins (both as xxx.jar Files) are only available in version 2.0 on Sonatype Repository beside of snapshots

    versions.

    Unfortunately we got some errors as we restarted Nexus saying that the System is not able to find 'org.codehaus.plexus.plexus-io.1.0-alpha-4', a very old

    version.....

    We did download the File manually and placed it into the /lib directory of Nexus but the failure still exists.

    Is there anything i could do?

    thanks

    Mario Widmer

    (We use Nexus Pro too at the moment with a 50 seats license)

  4. Apr 02, 2012

    Anonymous says:

    This wasn't as easy as I'd hoped. nexus-p2-bridge-plugin-2.0.2 also need the p2...

    This wasn't as easy as I'd hoped.

    nexus-p2-bridge-plugin-2.0.2 also need the p2-runtime files. I obtained these by cloning the git repository.

    Obtaining the dependencies requires you to open the jar files and to pull out the pom file buried at META-INF\maven\org.sonatype.nexus.plugins_<plugin-name>_\pom.xml.  You then can run mvn dependency:copy-dependencies.

    Dont forget to add http://repository.sonatype.org/content/groups/forge as a repository.  I did this by editing settings.xml and adding a profile.

    The layout of nexus plugins doesn't appear to be documented, the layout was guessed from webapps\nexus\WEB-INF\optional-plugins.

    These plugins should be installed with the following structure:

    • plugin-repository\
      • nexus-p2-bridge-plugin-2.0.2\
        • nexus-p2-bridge-plugin-2.0.2.jar
        • dependencies\
          • (Just move and rename target\dependency created by running mvn dependency:copy-dependencies)
        • p2-runtime
          • (Obtained from the git clone)

    I did the same for nexus-p2-repository-plugin-2.0.3, but p2-runtime is not needed.

    dependency:copy-dependencies

  5. Apr 02, 2012

    Barrie Treloar says:

    You need to download the zip files, not the jar files.

    You need to download the zip files, not the jar files.

  6. Apr 04, 2012

    Barrie Treloar says:

    What about bundles that already exist, can I force generation of the metadata? ...
    What about bundles that already exist, can I force generation of the metadata?

    In Nexus > Administration > Scheduled Tasks > Add:

    Task Type: Rebuild P2 metadata

    Schedule: Manual

    Once created you can then run this task and the metadata for the repositories OSGi artifacts should be generated (look for the p2Artifacts.xml and p2Content.xml beside the artifacts).

    I think you can then delete this task, since the capability "P2 Metadata Generator capability" will take care of generating these when future artifacts are deployed.

    How do I aggregate the p2 repository

    In Nexus > Administration > Scheduled Tasks > Add:

    Task Type: Rebuild P2 repository

    Schedule: Manual

    Once created you can then run this task and the .meta/p2 artifacts.xml and contents.xml will get updated.

    I'm not sure if this task can also be deleted, I'm assuming the capability "P2 Repository Aggregator capability" will take care of this in the future.

  7. Apr 04, 2012

    Anonymous says:

    I have a small problem understanding how I can get eclipse to access the p2 repo...

    I have a small problem understanding how I can get eclipse to access the p2 repository. 

    I have installed the plugins. And if I deploy a osgi-maven project I can see the generated p2Artifact.xml and the p2Content.xml files in the Nexus-web-page.

    However when I go into eclipse and start up the "Install new software" and set the adress to: http://nexus/content/repositories/snapshot/.meta/p2 nothing shows up. If I change the adress I get an error. So I asume that the adress is correct, but nothing is showing up?

    Does anyone have any ideas?

    1. Apr 04, 2012

      JBert says:

      I can only give the following pointer: the Eclipse .target file editor and softw...

      I can only give the following pointer: the Eclipse .target file editor and software install only look for "features".
      You can make feature projects in Eclipse, but I have never tried deploying them to a Nexus repository, so I don't know if these P2 plugins would actually expose it.

      1. Apr 04, 2012

        Anonymous says:

        but how can I then download a bundle from my p2-nexus? Can I do it with tycho?

        but how can I then download a bundle from my p2-nexus?

        Can I do it with tycho?

        1. Jun 19, 2012

          Anonymous says:

          I have the same problem.  I have Nexus configured as outlined above.  ...

          I have the same problem.  I have Nexus configured as outlined above.  When I create a Target Platform in Eclipse using the Software Site source, there doesn't appear to be any content available.  Not that the URL I'm entering is http://rd-nexus.mks.com:8081/nexus/content/repositories/thirdparty/.meta/p2/. Any help would be greatly appreciated.

    2. Jun 19, 2013

      Frank says:

      I've the same problem with Nexus 2.5.0-04, nexus-p2-bridge-plugin-2.1.1,&nb...

      I've the same problem with Nexus 2.5.0-04, nexus-p2-bridge-plugin-2.1.1, nexus-p2-repository-plugin-2.3.2.

      I've added the capabilities p2 metadata Aggregator/Generator to my maven repo and in my storage the ".meta/p2" looks nice, artifacts.xml, contents.xml, features, plugins, populated with the correct jars. It looks like a nice p2 repo ;)

      Though, neither by web-browser nor by eclipse p2 browser I can access this location, it seem like Nexus was not serving "http://my.server/myrepo/.meta/p2/".

      Is there something amiss?

      1. Jan 15

        Tamar Cohen says:

        I have the same problem as well; even though I have built and deployed, rebuilt ...

        I have the same problem as well; even though I have built and deployed, rebuilt and redeployed myriad Eclipse artifacts, the p2 site shows no content.  Has anyone gotten this to work?  We're of course using tycho to build the p2 site.  I will cross post to the tycho users group as well.  Thanks for any help, this is obviously a key / needed feature so that Eclipse can resolve the built artifacts.

  8. Apr 12, 2012

    Barrie Treloar says:

    MD5 hash is not as expected. If you are getting this error, then check what ver...

    MD5 hash is not as expected.

    If you are getting this error, then check what versions are deployed into Nexus.

    It's probably safest to stick with X.Y.Z numbering scheme.

    I had the problem of using version 15.0.0 but in Nexus there was also a 15.0.0.1 which was then being mapped to the 15.0.0 version by P2.

    This may have something to do with the differing version numbering between OSGi and Maven.

    Don't use qualifers and you should be ok.

  9. May 11, 2012

    Anonymous says:

    Great features  Just a question, when I tested it, it seems that it is not...

    Great features 

    Just a question, when I tested it, it seems that it is not possible to retrieve a bundle from p2 directly without forcing it to be locally cached.

    For example, if I expose maven central as p2 using plugin, and I get some a dependence org.foo.bar using maven, I have the org.foo.bar automatically exposed as p2 as well.

    Now I try to retrieve org.other.foo using p2, it cannot be found unless I locally cache org.other.foo. 

    Is it the way it is supposed to work ? or do I missed something in my configuration ?

    Thanks again for this great feature

  10. May 23, 2012

    Anonymous says:

    Would anybody object to modifying this extension to recognize and publish eclips...

    Would anybody object to modifying this extension to recognize and publish eclipse "features" as well as osgi bundles in the p2 repository?  Eclipse target platform functionality doesn't recognize contents of p2 repositories without features. 

    Any thoughts?

    1. May 25, 2012

      Anonymous says:

      Yes, I agree. Feature support is a must for us.

      Yes, I agree. Feature support is a must for us.

    2. Jan 16, 2013

      Anonymous says:

      have you had any luck with this?

      have you had any luck with this?

  11. May 25, 2012

    Anonymous says:

    I followed along and extracted all the bundles and their dependencies but under ...

    I followed along and extracted all the bundles and their dependencies but under Capabilities I see only "outreach:management". What have I missed? BTW, what do I do with the Bridge plugin's p2-runtime folder? I've extracted it to the same plugin-repository folder but that doesn't seem right...

  12. Jul 10, 2012

    Barrie Treloar says:

    If you are contemplating enabling this plugin on a Snapshot repository, I'd reco...

    If you are contemplating enabling this plugin on a Snapshot repository, I'd recommend you think again.

    Allowing snapshots to be used means there must be a build server running on your latest code base, but the code you want included is likely not yet checked in, so it wont be available in a Snapshot repository.  Plus, anything you do check in will affect other developers so you will want to make sure that your changes are ready for that level of intergration.

    Instead of using this plugin on a Snapshot repository you probably want to configure tycho to consider pom dependencies on your target configuration, see http://wiki.eclipse.org/Tycho/How_Tos/Dependency_on_pom-first_artifacts

  13. Aug 13, 2012

    Frank Lyaruu says:

    Is there any progress on supporting Eclipse features? I have pretty much all my...

    Is there any progress on supporting Eclipse features?

    I have pretty much all my builds and CI in order using Jenkins/Tycho, but deploying Eclipse plugins and especially managing my target platform is pretty messy, its a bit frustrating to be this close to cleaning that up.

    Nexus works great but as long as it doesn't serve features Eclipse and PDE don't really want to talk to Nexus.

    1. Jan 16, 2013

      Anonymous says:

      I'm in the same situation. So close but still useless as a target platform updat...

      I'm in the same situation. So close but still useless as a target platform update site

  14. Feb 19, 2013

    Anonymous says:

    I think it would be great if this plugin were also able to convert any Maven sou...

    I think it would be great if this plugin were also able to convert any Maven sources.jars into OSGi bundles with the appropriate MANIFEST.MF headers set to make them appear like source bundles in Eclipse. I.e. the Eclipse-SourceBundle header and some of the required OSGi headers like Bundle-Vendor, Bundle-Version, Bundle-SymbolicName, and Bundle-ManifestVersion would be required. Is that out of scope?

Add Comment