How to create a p2 repository from an existing osgi bundle?
Asked Answered
S

3

6

I try to use my legacy code in my Eclipe-RCP Application. I took all my old maven projects with dependencies and used the maven-bundle-plugin to create an osgi bundle.

Now i have everything wrapped up in a new osgi jar.

How to create a p2 update site from this OSGi jar to use with Tycho and the Eclipse target platform?

I tried: https://docs.sonatype.org/display/TYCHO/How+to+make+existing+OSGi+bundles+consumable+by+Tycho (see web archive)

Publishing a P2 Repository

Prerequisites:

  1. First of all we copy all bundle jars into a <BUNDLE_ROOT>/plugins directory
  2. Then we execute
  %ECLIPSE_HOME%\eclipsec.exe -debug -consolelog -nosplash -verbose -application
        org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher
        -metadataRepository file:/<BUNDLE_ROOT>/repo
        -artifactRepository file:<BUNDLE_ROOT>/repo
        -source <BUNDLE_ROOT> -compress -publishArtifacts
  1. The result is a P2 repository with all OSGi bundles under <BUNDLE_ROOT>/repo. Note the generated P2 metadata files artifacts.jar and content.jar in the repo directory.

Making the New P2 Repository Available via HTTP

The P2 repository in <BUNDLE_ROOT>/repo is complete, we just need to make it available via HTTP so it can be globally referenced.

This could be done using any HTTP server such as Apache. In our case we chose to deploy it on Tomcat as we already have a tomcat running for other purposes such as Hudson etc.

On the host running tomcat, copy the contents of <BUNDLE_ROOT>/repo to <TOMCAT_HOME>/webapps/<YOUR_REPO_DIR>

From now on you could reference this P2 repository in pom.xml as

<repository>
  <id>tomcat-p2</id>
  <layout>p2</layout>
  <url>http://<TOMCAT_HOST>:<TOMCAT_PORT>/<YOUR_REPO_DIR></url>
</repository>

If i put the resulting files on a web server eclipse is not recognizing it as "Software Site".

How to create a p2 Software Site from existing osgi bundles without using the Eclipse UI, the process has to run in background on my build-server.

Is there a way to use Maven (Tycho)/ Gradle to automatically create a p2 update site from an existing osgi bundle?

Selfjustifying answered 16/8, 2013 at 13:40 Comment(0)
S
5

I always use these two commands to generate a p2 repository:

java -jar %ECLIPSE_HOME%\plugins\org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher -metadataRepository file:/C:/repository -artifactRepository file:/C:/destination -source /C:/source -configs gtk.linux.x86 -compress -publishArtifacts

where c:/source are stored my bundles, and then

%ECLIPSE_HOME%/eclipse -debug -consolelog -nosplash -verbose -application org.eclipse.equinox.p2.publisher.CategoryPublisher -metadataRepository file:C:/destination -categoryDefinition file:C:/source/category.xml

the C:/source tree is like this

source
 -- feaures
 -- plugins
 -- category.xml

and you'll need this category.xml file to group your bundles into categories. This is the category's content

<?xml version="1.0" encoding="UTF-8"?>
<site>
   <category-def name="all" label="P2 Repo"/>
   <iu>
      <category name="all"/>
      <query><expression type="match">providedCapabilities.exists(p | p.namespace == 'osgi.bundle')</expression></query>
   </iu>
</site>

depending on your eclipse version, maybe you'll need to change the version of this file org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar

Shawm answered 16/8, 2013 at 13:59 Comment(5)
if use the first command a artifacts.jar, content.jar and plugin directory with my bundles is created. if i use the second command after the first nothing happends if i delete everything in the destination directory the second command generates a content.xml wich is not created i a use the first command first? I think i miss something? And how to prevent the windows from closing i can't read a thing?Selfjustifying
yes, this is your p2 repository. eclipse will open and read the content.jar. You need to run both commands and nothing more. The second command will "publish" your artifacts. there is no need to delete everythingShawm
why is the content.xml not generated if artifacts.jar, content.jar and plugin directory are present? If i put the artifacts.jar, content.jar and plugin directory with my bundles on my webserver eclipse won't find anything :(Selfjustifying
You dont need content.xmlShawm
My web server had some kind of problem.. Now its working. Thank you very much :)Selfjustifying
R
2

You could also drop these OSGi bundles (and maven source attachments) to Package Drone, an open source OSGi repository I am currently working on.

It allows you deploy or manually upload OSGi artifacts from Maven Tycho, plain Maven or manually and let it create OSGi metadata from it. It also allows accessing this repository using P2 so it an be used from Eclipse PDE or again from Maven Tycho.

Reiff answered 6/1, 2015 at 11:43 Comment(1)
I know this reply is old, but do you happen to know if it's possible to use package drone to create a p2-repository consisting of several other p2-repositories (e.g. Subclipse + JRebel + DBeaver P2-repositories all bundled into one single p2-repository that I can stick into artifactory)?Osteogenesis
M
0

Using this approach, the content of the p2-repository does not become visible due to a lacking property. Add a p2.inf to the META-INF containing: properties.0.name = org.eclipse.equinox.p2.type.group properties.0.value = true

Then the generated content.xml contains this property and the IUGroupQuery returns this unit.

Maraca answered 11/3, 2017 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.