My Home Page

Materializing and Provisioning your Target Platform as local p2 site with Buckminster

This post was inspired by another blog post I had found on the web when trying to build a p2 site corresponding to a target platform defined for my projects. For an year I’ve been using Buckminster for building my Eclipse projects (especially when I had problems building my Xtext projects with Maven/Tycho, so that I decided to switch to Buckminster).

Having a p2 site for the current platform has some advantages, I guess:

Building RCP products will be easier (Buckminster relies on p2 directory, and all the bundles for building the product will be searched for in p2 sites);

It represents a (local) mirror for the target platform (for easier access).

This tutorial will show how to materialize the target platform and build the p2 sites

in the IDE,

headlessly from the command line through ant, and

headlessly in Jenkins.

For the IDE you will need to install Buckminster main features in Eclipse, using the update site http://download.eclipse.org/tools/buckminster/updates-4.2.

NOTE: sometimes Buckminster’s cache in the IDE becomes stale, and you might experience errors about missing components; you might want to restart Eclipse and usually this makes the problem go away.

Why not the Target Editor?

I experienced many problems when using Eclipse Target Editor (based on p2 sites); I found it quite unreliable, especially for modifying a target definition, for updating a target definition (the Update button works 1 time out of 10); moreover, it takes some time for the target to be resolved (every time you reopen a target definition with the editor).

Furthermore, when you define a target for building RCP products, then you usually want to be able to build for several platforms, not only the current one; in these cases you have a checkbox to select (“Include all environments“):

But in that case, you must give up on “Include required software”, and this might get you into troubles about missing bundles, when building your product, if it needs to include more involved features (besides the standard “Eclipse RCP SDK” and “Eclipse Platform Launcher Executables”); for instance, if your product needs also EMF Eclipse Modeling Framework SDK (which is required when using Eclipse RCP 4.2).

Defining a target platform the “Buckminster way” does not have this limitation (and, honestly, once you get familiar with that, it’s much faster than using the target editor).

Defining a Target Platform with Buckminster

Although Buckminster is able to materialize a target platform starting from a standard target definition, it also provides an alternative way:

Define a component which represents all the target features by creating a project and a custom CSPEC; this CSPEC basically declares the target features as dependencies

Define a resource map (RMAP) which tells Buckminster where to find these dependencies; we will use of course official Eclipse p2 site repositories for these dependencies

Define a component query (CQUERY) which materializes the component representing the target platform

In our example, this project is called bucky.example.rcpemf.target (it is a generic project without any nature). This is the project where we will define all Buckminster files (CSPEC, CQUERY and RMAP). In this project we define the component specification: buckminster.cspec

Here we use the name of the features for our target platform. (NOTE: org.eclipse.rcp and org.eclipse.rcp.source, together, correspond to Eclipse RCP SDK.)

The rmap (which we call target-platform.rmap) is defined as follows:

XHTML

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

<?xml version="1.0"encoding="UTF-8"?>

<rm:rmap xmlns:rm="http://www.eclipse.org/buckminster/RMap-1.0"

xmlns:bc="http://www.eclipse.org/buckminster/Common-1.0">

<rm:property key="projects.location"value="${workspace.root}" />

<rm:searchPath name="juno-releases">

<rm:provider componentTypes="osgi.bundle,eclipse.feature"

readerType="p2"source="false"mutable="false">

<rm:uri format="http://download.eclipse.org//releases/juno" />

</rm:provider>

</rm:searchPath>

<rm:searchPath name="juno-updates">

<rm:provider componentTypes="osgi.bundle,eclipse.feature"

readerType="p2"source="false"mutable="false">

<rm:uri format="http://download.eclipse.org/eclipse/updates/4.2" />

</rm:provider>

</rm:searchPath>

<rm:searchPath name="local-source">

<rm:provider componentTypes="eclipse.feature,osgi.bundle,buckminster"

readerType="local"mutable="false">

<rm:property key="buckminster.mutable"value="false" />

<rm:uri format="{0}/{1}">

<bc:propertyRef key="projects.location" />

<bc:propertyRef key="buckminster.component" />

</rm:uri>

</rm:provider>

</rm:searchPath>

<rm:locator searchPathRef="local-source"failOnError="false" />

<rm:locator searchPathRef="juno-releases"failOnError="false" />

<rm:locator searchPathRef="juno-updates"failOnError="true" />

</rm:rmap>

In our case we use the two main Eclipse p2 repositories (if the features you need are available from other p2 repositories, you will need to provide p2 reader types for these repositories as well). We will not use regular expressions for specifying the source p2 repositories, since there are no ambiguities in this example; instead, we simply specify the locators in the order we desire (preferring juno release site to juno updates). Note that we also have a search path for local sources. This is useful for building headlessly, so that Buckminster is able to find, resolve and bind to the workspace our own projects.

Finally, the component query (which we call target-platform.cquery) is defined as

Thus we request the component corresponding to our project bucky.example.rcpemf.target. Note that we specify that we are not interested in any specific architecture, so that we will have a target platform for all platforms/environments/architectures. Note also that in the cquery we reference the above defined rmap.

Materializing the Target Platform

We can now materialize the target platform so defined by opening the target-platform.cquery with Buckminster corresponding editor:

WAIT: If you pressed the “Resolve and Materialize” now, Buckminster would materialize the target platform in the directory tp of a hidden project in your workspace (.buckminster). Moreover, by default, the created target platform is based on the configuration of the currently running Eclipse instance. If you want to start from a plain and empty platform (just like you do with a standard target definition with the target editor), there are a few more steps to perform:

Create an empty target platform manually that contains one single and empty directory.

Set this target platform active.

A subsequent resolution/materialization will use that platform.

You can specify any directory of your filesystem, in any case, make sure the directory you choose already exists.

Click on “Variables…” scroll down and select “workspace_loc” and then type TP in the Argument: field

This procedure is shown by the following screenshots.

NOTE: these additional steps are not required when building headlessly

Once you pressed Finish and set this new target as the active target platform, you’re ready to materialize the cquery from the cquery editor. Of course, it might take some time for downloading all the features. Once the materialization is finished, if you followed the above procedure and created a general project TP in your workspace, you can see the materialized target platform

Create a feature for the p2 site for your target platform

Once the target platform is resolved (you can also have a look at the current new target platform from the Eclipse preferences), we are ready to create a feature that we use to create the p2 site corresponding to our target platform.

We thus create a new feature project, that we call bucky.example.rcpemf.target.site, and we initialize it with all the bundles (plugins and fragments) of the current target platform (if you have other bundle projects in your workspace, make sure to unselect such additional workspace projects)

Before creating the p2 site, you may want to create a buckminster.properties (e.g., in the main project bucky.example.rcpemf.target) where we set some properties for Buckminster (e.g., that we want to build a site for all environments, and that we want the site to be created in a specific folder, in this example /tmp/bucky):

1

2

3

4

5

6

7

8

9

10

# Where all the output should go

buckminster.output.root=/tmp/bucky/build

# Where the temp files should go

buckminster.temp.root=/tmp/bucky

# How .qualifier in versions should be replaced

qualifier.replacement.*=generator:lastRevision

target.os=*

target.ws=*

target.arch=*

We are now ready to build a p2 site for this feature with Buckminster:

If you used the same property file, you can find the site.p2 in /tmp/bucky/build/bucky.example.rcpemf.target.site_1.0.0-eclipse.feature/site.p2/ .

The p2 site you’ve just created could already be used, for instance, for building your RCP product with Buckminster through the p2 director. However, as it is, it contains only bundles, no (installable) features, thus it cannot be used, for instance, as a mirror for your target platform… see the next section

Create a feature for the p2 MIRROR site for your target platform

We create a new feature project bucky.example.rcpemf.target.mirror.site, and, as before, we initialize it with all the bundles (plugins and fragments) of the current target platform (if you have other bundle projects in your workspace, make sure to unselect such additional workspace projects); but this time, once the feature project is created, we also add to the feature.xml all the features that we used to create our target platform:

Let’s run the action site.p2 (using the same buckminster.properties file) on this new feature project. This time, we will end up with a p2 site with all the installable features of our target platform! You can verify this by using the Eclipse install new features menu and using as repository the one just created (if you used the same output directory it will be located at /tmp/bucky/build/bucky.example.rcpemf.target.mirror.site_1.0.0-eclipse.feature/site.p2/).

Even more, you might create a target definition file, open it with the Eclipse target editor, and create a target definition using your local mirror!

Headless execution from the command line

If you want to materialize the target platform and build the p2 site from the command line, you need to install the headless version of Buckminster.

Note we reuse the same rmap we saw before. This way, during the materialization of the mirror site feature, possible additional dependencies will be resolved by Buckminster and added to the target platform;

perform the site.p2 action (before we also perform a buckminster.clean) on the component of the mirror site

We then write an ANT file, build.ant, in the project bucky.example.rcpemf.target, as follows (this was inspired by the one generated by the Xtext wizard, developed by Dennis Hübner – I’ve blogged about that, and from the one that can be found here):

XHTML

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

<?xml version="1.0"encoding="UTF-8"?>

<!--

Buckminster Headless - build

buckminster.home must be specified on the command line, e.g.,

ant -Dbuckminster.home=/home/bettini/buckminster -f build.ant

Properties:

WORKSPACE Eclipse workspace location, or hudson job workspace

build.root Where to build? WARNING: This folder will be cleaned up, so do not point to user.home or something important

You need to execute Buckminster twice because of some conflicting bundles (see the discussion here) which cause problems if you attempt to run everything in one shot; if you did not separate the steps, you would get something like

Hi Vlad, glad you liked it
usually for non-RCP stuff it is easier: you do not need the executable features and the site.p2 usually is not architecture dependent… so I would say, no, there should be no difference… are you experiencing problems in your context?

No, I don’t have any problems directly, but I got it working in an ad-hoc fashion for a year or so ago and since then didn’t dared to change anything for fear that it will start misbehaving. I’m using a static target platform, manually installed, and I would like very much to automate that. Hopefully I can get it to work with the walkthrough above.