Discussion:
Advice: OSGi'fy jars into target platform or Classpath and included in bundle?
(too old to reply)
Barrie Treloar
2012-05-29 08:49:11 UTC
Permalink
I have an RCP application that makes use of maven dependencies that
are no OSGi'fied.

Previously I had all the jars in the plugin's lib/ directory courtesy
of maven-dependency-plugin.
The downside of this approach is that every time we go to create a
release we have to manually edit MANIFEST.MF, .classpath and
build.properties to change all -SNAPSHOT versions to released version.
We can then tag a baseline and deploy a release.
And then we upgrade to the next -SNAPSHOT version, modifying the same
files as before.

This is a tedious and error prone process.

I think a better option would be to OSGi'fy these jars (or source ones
already from Orbit or Spring repositories).
But I am left with a few jars that no one else has already OSGi'fied,
plus all our internal ones.

I'm not familiar enough with class path resolution rules in Eclipse,
but I dimly recall that its an all or nothing approach.
I have to make everything OSGi'fied as transitive dependencies need to
get loaded correctly.

I know this is a niche area, as most people are probably writing
Eclipse plugins so they don't have this issue.

Is anyway writing an Eclipse RCP and have given this scenario some
thought and can share any advice?
Igor Fedorenko
2012-05-29 11:23:33 UTC
Permalink
I use maven-bundle-plugin Embed-Dependency feature [1] to "wrap"
thirdpary dependencies in OSGi bundles and pomDependencies=consider [2]
Tycho target platform configuration parameter to use these wrapper
bundles from Tycho builds. See m2e embedded maven runtime, for example [3].

The only real caveat here is that wrapper bundles must be built
separately, before building any tycho project that uses them.


[1] http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
[2]
https://docs.sonatype.org/display/TYCHO/Dependency+on+pom-first+artifacts
[3]
http://git.eclipse.org/c/m2e/m2e-core.git/tree/?id=milestones/1.1/1.1.0.20120505-1126

--
Regards,
Igor
Post by Barrie Treloar
I have an RCP application that makes use of maven dependencies that
are no OSGi'fied.
Previously I had all the jars in the plugin's lib/ directory courtesy
of maven-dependency-plugin.
The downside of this approach is that every time we go to create a
release we have to manually edit MANIFEST.MF, .classpath and
build.properties to change all -SNAPSHOT versions to released version.
We can then tag a baseline and deploy a release.
And then we upgrade to the next -SNAPSHOT version, modifying the same
files as before.
This is a tedious and error prone process.
I think a better option would be to OSGi'fy these jars (or source ones
already from Orbit or Spring repositories).
But I am left with a few jars that no one else has already OSGi'fied,
plus all our internal ones.
I'm not familiar enough with class path resolution rules in Eclipse,
but I dimly recall that its an all or nothing approach.
I have to make everything OSGi'fied as transitive dependencies need to
get loaded correctly.
I know this is a niche area, as most people are probably writing
Eclipse plugins so they don't have this issue.
Is anyway writing an Eclipse RCP and have given this scenario some
thought and can share any advice?
_______________________________________________
tycho-user mailing list
https://dev.eclipse.org/mailman/listinfo/tycho-user
Barrie Treloar
2012-05-30 00:52:14 UTC
Permalink
Post by Igor Fedorenko
I use maven-bundle-plugin Embed-Dependency feature [1] to "wrap"
thirdpary dependencies in OSGi bundles and pomDependencies=consider [2]
Tycho target platform configuration parameter to use these wrapper
bundles from Tycho builds. See m2e embedded maven runtime, for example [3].
The only real caveat here is that wrapper bundles must be built
separately, before building any tycho project that uses them.
[1] http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
[2]
https://docs.sonatype.org/display/TYCHO/Dependency+on+pom-first+artifacts
[3]
http://git.eclipse.org/c/m2e/m2e-core.git/tree/?id=milestones/1.1/1.1.0.20120505-1126
Thanks for the links to m2e-core, cloning now.

It would be ideal if people published their jars OSGi compatible, but
that's not likely to happen any time soon.
For now I just want "lazy"-OSGification. Which is pretty much what
wrapping does.
Its at this point whether its worth working out whether I can write a
Nexus plugin to build these on the fly...

Will report back what I needed to do.
Maybe update some wiki links...
Barrie Treloar
2012-05-30 02:13:02 UTC
Permalink
On Wed, May 30, 2012 at 10:22 AM, Barrie Treloar <***@gmail.com> wrote:
[del]
Post by Barrie Treloar
Post by Igor Fedorenko
https://docs.sonatype.org/display/TYCHO/Dependency+on+pom-first+artifacts
[del]
Post by Barrie Treloar
Maybe update some wiki links...
Are these going to be migrated to the Eclipse wiki?

I've migrated that file over to
http://wiki.eclipse.org/Tycho/How_Tos/Dependency_on_pom-first_artifacts
I'm not happy that the file gets listed under T instead of D...
Barrie Treloar
2012-05-30 06:41:08 UTC
Permalink
I thought I would just try
http://www.lucamasini.net/Home/osgi-with-felix/creating-osgi-bundles-of-your-maven-dependencies
as that looked like I could just use my existing Maven dependencies
and spit out OSGi dependencies.
Maven bundle doesn't respect optional transitive dependencies so after
downloading crappy sun jars which are not available on central I
managed to get the thing building OSGi jars.

But on visually inspecting the manifests I dont think they are usable.
The Import-Package is too wide, there is stuff in there I dont use.
Same with the Export-Package, it seems to be re-exporting everything
instead of just the jar's contents.

I've had problems attempting to clone the m2e-core repo lots of
error: Unable to get pack index
http://git.eclipse.org/c/m2e/m2e-core.git/objects/pack/pack-e2befb213a0fbfb0179b688cb4c74d246b4e7a01.idx
error: Unable to find e7272b873d23f894be7c0642ae1ddc7b9f5d7c5c under
http://git.eclipse.org/c/m2e/m2e-core.git
Not sure what's up with that, I've cloned rt.equinox.p2.git in the past.

Looking at http://git.eclipse.org/c/m2e/m2e-core.git/tree/m2e-maven-runtime/org.jboss.netty/pom.xml
it appears you have manually selected each dependency and specified
how to wrap it, which is a lot more work but perhaps my only option.

I'm trying to take shortcuts as I've spent too much time on this
already, but the shortcuts aren't working so I better just hunker down
and do this step by step correctly.
Stephan Herrmann
2012-05-30 20:56:52 UTC
Permalink
Post by Barrie Treloar
...
I've migrated that file over to
http://wiki.eclipse.org/Tycho/How_Tos/Dependency_on_pom-first_artifacts
I'm not happy that the file gets listed under T instead of D...
fixed :)

Stephan
Barrie Treloar
2012-05-30 23:58:13 UTC
Permalink
On Thu, May 31, 2012 at 6:26 AM, Stephan Herrmann
Post by Stephan Herrmann
Post by Barrie Treloar
I've migrated that file over to
http://wiki.eclipse.org/Tycho/How_Tos/Dependency_on_pom-first_artifacts
I'm not happy that the file gets listed under T instead of D...
fixed :)
Thanks, can you explain how you fixed it so I can self-help if I move anymore?
Barrie Treloar
2012-05-30 23:59:47 UTC
Permalink
Post by Barrie Treloar
On Thu, May 31, 2012 at 6:26 AM, Stephan Herrmann
Post by Stephan Herrmann
Post by Barrie Treloar
I've migrated that file over to
http://wiki.eclipse.org/Tycho/How_Tos/Dependency_on_pom-first_artifacts
I'm not happy that the file gets listed under T instead of D...
fixed :)
Thanks, can you explain how you fixed it so I can self-help if I move anymore?
Ahh nevermind.
I self-helped myself.
Show History says
[[Category:Tycho|Dependency on pom-first
artifacts]][[Category:Tycho/How To|Dependency on pom-first artifacts]]
Barrie Treloar
2012-05-31 07:27:01 UTC
Permalink
Post by Igor Fedorenko
I use maven-bundle-plugin Embed-Dependency feature [1] to "wrap"
thirdpary dependencies in OSGi bundles and pomDependencies=consider [2]
Tycho target platform configuration parameter to use these wrapper
bundles from Tycho builds. See m2e embedded maven runtime, for example [3].
The only real caveat here is that wrapper bundles must be built
separately, before building any tycho project that uses them.
[1] http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
[2]
https://docs.sonatype.org/display/TYCHO/Dependency+on+pom-first+artifacts
[3]
http://git.eclipse.org/c/m2e/m2e-core.git/tree/?id=milestones/1.1/1.1.0.20120505-1126
How do target platforms fit into all this?

This stuff is making my head hurt, so I'm probably not very lucid in
explaining what I am trying to do.

I had hoped I could
* Wrap the bundles
* Generate P2 data for them
* Update my Target definition with extra <unit/>s for each new dependency
* Update my plugin's MANIFEST.MF to include each new new dependency

Again, perhaps because I am trying to take a shortcut, I thought I
would just grab the already OSGi'fied bundles at
http://ebr.springsource.com/repository/app/faq#q8
But that won't have P2 data.
I tried proxying these in Nexus and use the P2 metadata generator but
that doesn't seem to be working (probably because I don't really
understand what its doing, I think it generates the data on insertion
into the repository so probably doesn't work on proxied repositories)

So instead I have managed to get rid of one embedded dependency by:
* Create a pom that specifies the spring repository and a dependency
to an OSGi'fied jar available there.
* Use maven-dependency-plugin to copy the dependencies to lib/
* Manually upload this dependency into our local Nexus, into a
repository that has the Experimental P2 plugins enabled on it. This
will generate the p2 meta data required. (I used a different group to
keep them separate from the spring stuff)
* Delete the use of an embedded jar from .classpath, build.properties,
MANIFEST.MF and bin.includes.
* Add the dependency to the target platform (and reload if necessary)
* Add the dependency to the Required-Bundle of the plugin
* Rebuild plugin in Eclipse (should work)
* Rebuild application with Maven and validate product.zip file runs correctly.

So I will keep going and removing other dependencies.

I'm not sure what is going to happen with these:
1) SNAPSHOT dependencies on other projects we develop
2) SNAPSHOT dependencies within the current maven build

My target platform file uses remote http locations, which obviously
wont have the latest SNAPSHOT versions.
Barrie Treloar
2012-06-14 07:01:23 UTC
Permalink
Post by Igor Fedorenko
I use maven-bundle-plugin Embed-Dependency feature [1] to "wrap"
thirdpary dependencies in OSGi bundles and pomDependencies=consider [2]
Tycho target platform configuration parameter to use these wrapper
bundles from Tycho builds. See m2e embedded maven runtime, for example [3].
The only real caveat here is that wrapper bundles must be built
separately, before building any tycho project that uses them.
[1] http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
[2]
https://docs.sonatype.org/display/TYCHO/Dependency+on+pom-first+artifacts
[3]
http://git.eclipse.org/c/m2e/m2e-core.git/tree/?id=milestones/1.1/1.1.0.20120505-1126
Thanks [3] was a big help.
Pity something is wrong on my end that made cloning the repo
impossible... Stupid firewalls.

I'll also add some advice for google.

If you find maven-bundle-plugin doesn't embed your jars, make sure you
have <instructions> after <configuration>.
I wasted a good 30 minutes trying out different black magic
instructions trying to work out why the classpath details from -X
looked fine in log output but nothing was in the jar file,
only to finally notice I had missed "instructions". Oops.

Then I had to back out all those hacks.
At least I got to understand what Embed-Dependency and ;inline=true
meant and why I should be using _exportcontents insteads (so that it
doesn't include the jar AND a copy of the class extracted from the jar
for everything listed in Export-Package).

Its late in the day so I will do some more wrapping tomorrow and see
what other problems I need resolve.

Loading...