Building Source Features with the PDE Build

Posted on January 30th, 2010 in Eclipse by Stefan

The PDE Build provides a pretty convenient way of automatically creating a source feature. The additional feature contains all source files and artefacts listed in the containing bundles’ build.properties files for a source build. There are only a few settings necessary.

Assume we have a feature com.foo.feature containing some bundles with binaries only.

First, we need to configure a source feature include for the feature. Simply add a line to the com.foo.feature feature’s feature.xml:
<includes id="com.foo.feature.source" />

The linked feature com.foo.feature.source does not exist yet, it will be created by the PDE Build later on.

To get the PDE Build actually creating the source feature, we have to edit the com.foo.feature features’s build.properties by adding another line to it:
generate.feature@com.foo.feature.source = com.foo.feature

The PDE Build will now build the linked source feature com.foo.feature.source including a bundle containing all sources of all binary bundles included in the com.foo.feature feature. Since Eclipse 3.4, we can tell the PDE Build to create an individual source bundle for each bundle by setting a PDE Build property individualSourceBundles to true.

Fragments vs. Buddy Classloading

Posted on January 27th, 2010 in Eclipse, Software Architecture by Stefan

Classloading is a serious issue when creating OSGi based applications. As each bundle is bound to it’s own classpath, sometimes the reflection mechanism will not work as expected. So, there are basicly two ways of solving the problem of extending a bundle’s classpath (when using Equinox…), either create a feature or use Buddy Classloading. But which solutions fits best for what problem?

Fragments

A fragment is an OSGi mechanism to allow a dynamic extension of a bundle at runtime. The fragment itself is not a true component as other bundles may not define a dependency on the fragment. It is used for different purposes such as testing, internationalisation or logging configuration. You can add system dependent code or configuration files to a generic implementation. The good thing is, that the extended code has no dependency on the fragment i.e. does not necessarily require the fragment for running (for example testing fragments).

How to
A fragment is structured as a common bundle. It may be created using a wizard (in Eclipse) or by adding a line to the manifest.mf of a common bundle defining the so called fragment host:
Fragment-Host: bundleSymbolic-Name
This advises the runtime to merge the fragment’s content with it’s host at runtime.

What’s good
Fragments are pure OSGi and provide the flexibility of extending a component dynamicly at runtime without breaking the component architecture. Some third party classpath requirements can be solved this way, for example providing a logging configuration.

What’s bad
Some third party classpath requirements cannot be matched using fragments.

Buddy Classloading

Buddy Cassloading is somewhat a hack (in my opinion), as it adds a bundle’s classpath to another’s – you could call it ‘reverse-dependency’. In OSGi terms, this is explicitly not wanted as a bundle should be treated as a component. But since many Java libraries got used to a single classloader environment, they still expect an exclusive access to any class of the application using reflection. So, in some situations, you can’t really avoid using Buddy Classloading in an Equinox environment.

How to
The manifest.mf of the bundle to be extended receives an additional line to define a Buddy Policy:
Eclipse-BuddyPolicy: registered
This defines the bundle to be aware of registered bundles which entend the classpath.

The manifest.mf of the bundle to extend receives two additional lines:
Eclipse-RegisterBuddy: bundleSymbolic-Name
Require-Bundle: bundleSymbolic-Name

This defines the bundle to extend the classpath of the listed bundles. Additionally, the registered Buddy Policy requires the extending bundle to have a dependency on the extended bundle.

What’s good
Buddy Classloading easily enables using common reliable libraries without any problems. Additionally, the extending bundle can still be treated as a ‘normal’ bundle, other bundles may have a dependency on the bundle and use the exported packages as provided.

What’s bad
Buddy Classloading is not ‘the OSGi way’ as it corrupts the idea of having a component based application with clearly separated bundles defining an interface and dependencies. Buddy Classloading is an answer to a technical problem and should not be used for application design.

Wicked Shell Docs

Posted on December 31st, 2009 in Eclipse, Personal by Stefan

I have updated the Wicked Shell page with the contents of the Wicked Shell documentation. It is not that detailed, so if there are any questions, please let me know via mail.

White Christmas

Posted on December 21st, 2009 in Personal by Stefan

Unbelievably 3 days before Christmas Eve it is freezing cold outside (we had -11,7 °C) and everything is covered with snow. So there really is a chance for a white Christmas around here, which is pretty special.  I can’t really remember the last time we had snow for Christmas.

Programmatic Command Contributions

Posted on December 16th, 2009 in Eclipse by Stefan

Have you ever faced the task of programmatically adding commands to a given menu? It is not that difficult – when you finally found out ;) .
First of all, you need a target menu, whether it is declared or programmatically created does not matter. What you actually need is the menu’s location URI. You may the create an AbstractContributionFactory with the menu’s location URI:

...
AbstractContributionFactory contribFactory = new AbstractContributionFactory ("menu:com.foo.targetmenu?after=targetGroup", null) {
@Override
public void createContributionItems(IServiceLocator locator, IContributionRoot additions) {
// add the contribution using it's source
additions.addContributionItem(createContributionItem(contribSource), null);
}
IMenuService menuService = (IMenuService)getViewSite().getService(IMenuService.class);
menuService.addContributionFactory(locator, contribFactory);
...

The items are added to the IContributionRoot within the factory’s createContributionItems() method. The factory is then registered at the IMenuService and your contributions show up.
For creating an IContributionItem for a given command, you may use the CommandContributionItem class, which takes an CommandContributionItemParameter as constructor parameter. A CommandContributionItemParameter basicly contains all the required data for a command contribution known from the org.eclipse.ui.menus extension point.


private IContributionItem createContributionItem(IServiceLocator locator, Object contribSource) {
CommandContributionItemParameter contributionItemParameter = new CommandContributionItemParameter(locator, null, "com.foo.the.command.id", SWT.PUSH);
// pimp the item using the contribSource
...
return new CommandContributionItem(contributionItemParameter);
}

There you go.

Cordless on telly is wicked…

Posted on December 9th, 2009 in Personal by Stefan

Not long ago, I got my brand new LCD television, which is really pretty cool. As my DVD player ‘unfortunately’ quited his job, I additionally needed to buy a BluRay player as well :)  - even more really pretty cool. Yesterday, my wife and me went to Hamburg’s main Christmas market right in front of the town hall. We had some time left before we had to go home – so we went looking for DVDs. We entered the shop and I remembered the VGA input slot of my telly – I bought a cable and a cordless keyboard/mouse for my notebook and here I go – cordless on telly!

Eclipse Demo Camp Hamburg – December 2009

Posted on December 5th, 2009 in Eclipse by Stefan

Yesterday the Eclipse Demo Camp in Hamburg took place. Awesome 110+ registrations and it felt as if everybody showed up and brought a friend. It was good fun listening to the talks. Jochen Krause from EclipseSource covered Tom Schindl who unfortunately could not attend. Jochen gave a brief overview about e4 which was pretty nice actually. I personally haven’t had the time yet to dive into e4 but it seems to be a very good idea to do so. A lot of things promise to ease the complexity of the 3.x Eclipse Workbench features. Jan Köhnlein then switched to the modeling context and spoke about combining textual and graphical editors for modeling, which was pretty interesting as well.  In order to stick to the EMF topic, Jochen with his RAP talk then demonstrated how to ‘webify’ the common EMF Editor using RAP – And despite the fact that setting up CDO did not really work, he said it really went fast to get that done. Gerd Wütherich and Nils Hartmann were really entertaining when they presented their very own version of Charles Dickens “A Christmas Carol” pointing out “Fifty ways to build your bundle”. Though Gerd and Nils as “Ghosts of Build-Management Past, Present and Future” really had some good input, Ebenezer significantly quited his job as a Build Manager in the end and became an Event Manager which seems to be far more relaxing ;) . Ekkehard Gentz had the thankless task of presenting last. But it was definitely worth waiting – Just take a look at the upcoming RedView project and you’ll get what I mean.

Wicked Shell 2.0.5 released

Posted on December 2nd, 2009 in Eclipse, Personal by Stefan

The Wicked Shell release 2.0.5 supporting Windows 7 is out now. You can get it via updatesite or as feature download from Sourceforge.net. Have fun!

Bundles & Libraries

Posted on November 12th, 2009 in Eclipse, General, Software Architecture by Stefan

I heard a talk about VIB – Very Important Bundles – today at the W-JAX here in Munich. The speaker pointed out some key features and services (and available solutions) necessary for developing applications in an enterprise context. He also discussed the way bundles should be designed in general. There were two mentioned aspects that made me wonder.

  • Bundles represent a deployment artefact only.
  • Bundles may contain libraries they need, if it is applicable.

For me, a bundle is explicitly not only a deployment artefact. Bundles represent a software component and are therefor an architectual element of the software. They are essential to be able to use public and private API, as Java Packages simply do not serve this need. No need to say that I prefer ‘Required Bundles’ instead of ‘Imported Packages’ :) . And turning to libraries, they should be encapsulated in a separate bundle and definetly not included in any bundle containing business code. A big advantage is the reusability of these individual so called ‘library bundles’, for instance logging frameworks or apache commons components. From my point of view, intergrating libraries in a bundle and even exporting them makes their management difficulter than necessary, at least within an enterprise context.

From OAW to MWE…

Posted on October 23rd, 2009 in Model Driven Development by Stefan

I’m currently migrating a model driven project from OAW to MWE. While changing all package declarations in the workflow and finding the right MWE counterpart elements is not too complicated, keeping the whole automated building thing working is not as easy as I thought though. The model export from UML to XMI is still bound to the OAW packages, so the export and generate steps need to be separated and executed back-to-back… pretty tricky but necessary… If you face the task of migrating an oaw project, maybe these blog entries from Karsten Thoms or Ekkehard Gentz help you a little.

Next Page »