Developers, Developers, Developers! Maksim Sorokin IT Blog

14Dec/10Off

Running P2 Ant Tasks in Eclipse

If you have the following when executing p2 ant tasks in Eclipse:

Buildfile: C:\projects\p2\build.xml
run:

BUILD FAILED
C:\projects\p2\build.xml:6: Problem: failed to create task or type p2.mirror
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

Make sure that you run this task in the same JRE as workspace.

How to do that? Go to "Externals Tools Configuration". Choose your ant script. Go to "JRE" tab and select "Run in the same JRE as the workspace".

Tagged as: , , 1 Comment
8Dec/10Off

Hints on Depending on Online P2 Repositories in the Target Platform

Depending on online P2 repositories in the target platform is not that bad, is it may look like. In Eclipse world there is no such thing as a released stuff. Everything is released when it is built. However, when a bundle is built with the same version, then it still has different timestamp.

Assume you have a target platform, in which you depend on a specific feature in online p2 repository of Helios. If you open file with a text editor, you will see something like the following:

<location includeAllPlatforms="false" includeMode="slicer"
    type="InstallableUnit"> <unit
            id="org.eclipse.emf.sdk.feature.group"
            version="2.6.1.v20100914-1218" /> <repository
            location="http://download.eclipse.org/releases/helios" />
</location>

So even if a new release of "org.eclipse.emf.sdk.feature.group" with the same 2.6.1 version is done, it will have different timestamp! So no problems in that.

However, the problem is, that when you update the software site in your target platform in order to choose another dependency, it may update the version of previous feature to the newest one, which may break your build. The solution is to depend on different feature of the same p2 repository in different software update sites. So instead of:

Have:

In this case, when you will update the version of one feature, the other one will remain.

Of course, there is still a problem on depending on online p2 repositories since one day they may die. But you can mirror those on your servers and depend on mirrored ones, instead of untrusted remote ones.

28Nov/10Off

Having Different Versions of the same Feature in p2 Repository

In one of the posts I talked about creating a p2 repository from plugins and features. In other one I showed how to make Tycho create a deployable feature. You can combine them both in order to have several versions of the same feature in p2 repository.

This works in the following way. First, you build a feature with Tycho. Then you merge it with existing p2 repository (it can also be used to create one) using p2 publisher, about which I talked in previous post. -append option ensures, that you add and not delete rewrite old ones.

26Nov/10Off

Creating a p2 Repository from Features and Plugins

So you have some features and plugins and you want to publish those to the p2 repository. There is a nice page on eclipse.org describing this procedure.

Here is a recepie.

First, you will need to have to create a folder, which be a source folder for p2 repository. Let's
name it src:

-- src

In this src folder create two other folders called features and plugins:

-- src
     features
     plugins

Copy your features to features folder and plugins to the plugins folder.
And what you do next is just running

$ECLIPSE -debug -consolelog -nosplash -verbose -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher -metadataRepository file:$DEST -artifactRepository file:$DEST -source %SRC% -compress -append -publishArtifacts

where $ECLIPSE is a path to eclipse executable, $DEST is where p2 repository will be created and $SRC is the path to src folder.

That is it.

If you want your plugins be visible on p2 repository, you would need to run additional step. In this case, you would need to create a category.xml file. This file provides information about the categories of your bundles, so they could be seen. If you do not care about nice naming, you can just have a dummy category.xml with which bundles will have category name the same as bundle name:

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

And then run another command:

$ECLIPSE -debug -consolelog -nosplash -verbose -application org.eclipse.equinox.p2.publisher.CategoryPublisher -metadataRepository file:$DEST -categoryDefinition file:PATH_TO/category.xml

Then you can point your eclipse to location of installed p2 repository. If you want to switch feature/bundle view, toggle "Group items by category"

Eclipse, p2, update site

Deployable Feature with Tycho

When building a feature with Tycho, you can define it to be "deployable":

<plugin>
  <groupId>org.sonatype.tycho</groupId>
  <artifactId>maven-osgi-packaging-plugin</artifactId>
  <version>${tycho-version}</version>
  <configuration>
    <deployableFeature>true</deployableFeature>
  </configuration>
</plugin>

In this case, when Tycho will build it, it will also create a p2 site for this feature including all the plugins and dependencies.