7

How do I build an SWT application using the Eclipse P2 repository and the Maven tycho-p2-plugin?

Lii
  • 11,553
  • 8
  • 64
  • 88
msshapira
  • 257
  • 1
  • 4
  • 12
  • I'd like to see this as well - good luck with an answer though :) – javamonkey79 Jun 28 '10 at 05:11
  • I can't find the detail of your problem. Need more information. – Kane Nov 02 '11 at 05:10
  • @Kane: What causes the error message "Could not determine SWT implementation fragment bundle"? Which information is missing in my POM? – Aaron Digulla Nov 02 '11 at 08:17
  • 1
    can you upload your project (or a small example with the same structure and the same error) so we can understand what is the problem and help you to solve it? – Matteo Nov 02 '11 at 12:21

3 Answers3

5

You can define the target environments for 'target-platform-configuration' plugin. Whatever you are building RCP or features for multiple environments, you can let your feature to include the fragments of swt for these hosts.

        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>target-platform-configuration</artifactId>
            <version>${tycho-version}</version>
            <configuration>
                <resolver>p2</resolver>
                <environments>
                    <environment>
                        <os>linux</os>
                        <ws>gtk</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>solaris</os>
                        <ws>gtk</ws>
                        <arch>sparc</arch>
                    </environment>
                </environments>
            </configuration>
        </plugin>

Snippet in feature.xml

   <plugin
         id="org.eclipse.swt"
         download-size="0"
         install-size="0"
         version="0.0.0"
         unpack="false"/>

   <plugin
         id="org.eclipse.swt.gtk.linux.x86"
         os="linux"
         ws="gtk"
         arch="x86"
         download-size="0"
         install-size="0"
         version="0.0.0"
         fragment="true"
         unpack="false"/>

   <plugin
         id="org.eclipse.swt.win32.win32.x86"
         os="win32"
         ws="win32"
         arch="x86"
         download-size="0"
         install-size="0"
         version="0.0.0"
         fragment="true"
         unpack="false"/>
Kane
  • 8,035
  • 7
  • 46
  • 75
  • I'm building a plugin (`eclipse-plugin`) I do have the `environments` entry and I have the necessary plugins in my local p2 repo but Tycho can't decide which one to pick. – Aaron Digulla Nov 02 '11 at 09:24
2

Tycho allows you to build & compile eclipse-based stuff, including plugins, features, and RCP applications. On the official project page there are a tons of good tutorial, but in my case I used the sample project ( http://git.eclipse.org/c/tycho/org.eclipse.tycho-demo.git/tree/itp04-rcp ).

However, if you do not need to build some plugins or a RCP application, I think you do not need tycho: you just can import SWT as a normal maven dependency and build your app that way...

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
Matteo
  • 1,367
  • 7
  • 25
  • That example looks good but that doesn't explain how it works. My problem is that I get an error message (`Could not determine SWT implementation fragment bundle`) and I have no idea how to get rid of it. It's probably some detail that I'm missing since all the obvious settings in my project are the same as in the demo. – Aaron Digulla Nov 01 '11 at 17:12
  • +1, the RCP example of tycho demonstrates how to build an application for multiple environments, such as Windows and Linux. – Kane Nov 02 '11 at 05:11
  • @Kane: I'm not building an RCP product but a bundle which depends on SWT. – Aaron Digulla Nov 02 '11 at 08:19
  • sorry, but I'm a little confused... are you creating a normal java application that needs SWT? in this case, you do not need tycho, and you can import swt as "normal" maven dependency... see, for example, http://alistairisrael.wordpress.com/2009/07/15/writing-eclipse-swt-apps-using-maven/ Conversely, if you are creating an eclipse plugin (which may or may not be used to create an RCP), you can follow the aforementioned tutorial. Notice that beside your plugin, you also need a feature. If you are not creating an RCP, skip the part related to the RCP or follow one of the other 3 tutorials :-) – Matteo Nov 02 '11 at 12:19
  • No, I'm building an Xtext editor plugin. It's a simple OSGi plugin which depends on `org.eclipse.swt`. – Aaron Digulla Nov 02 '11 at 14:28
  • Ok, so I suggest you to follow the first three tycho tutorials... I use them to build the plugins and features (some of whom depend on EMF, XText, and Graphiti). In my case, I had to follow also the fourth tutorial so I was able to pack everything in a RCP app. – Matteo Nov 02 '11 at 15:39
2

I found the problem. Background: I'm building the editor plugin which Xtext generates for DSLs.

The plugin depends on org.eclipse.swt;version=3.7.0. The packaging is eclipse-plugin. I'm listing all the necessary environments in my parent POM.

The p2 repository is a local mirror on my hard disk which I fill by exporting a Target Definition (*.target file).

The problem is that exporting a Target Definition will create something that looks a lot like a p2 repo but there are subtle differences.

For example, you have to define a target environment (Linux/Windows/Mac, x86/x86_64, win32/cocoa/gtk) in the Target Definition file. If you don't specify anything, Eclipse will use the current platform. If you use "*", all SWT fragments will be omitted.

This means: The export contains all the SWT fragments (30 plugins in the plugins/ folder), they are mentioned in the contents.jar but the artifact.jar only lists the single SWT fragment which matches your current platform (i.e. the bundle plus the sources).

This is not enough for Tycho.

Solution: Create a proper p2 repo using this small script:

# Where you exported the Target Definition
dir="$HOME/3.7.1-from-target-platform"

# Where the result should be written. Must be != dir
dest="$HOME/3.7.1-from-target-platform-fixed"

# Make sure subsequent invocations don't try to merge old stuff
rm -rf "$dest"

# Prepend "file:" to create a URL from the path
dest="file:$dest"

echo "Merging $dir..."
./eclipse -nosplash \
    -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher \
    -metadataRepository "$dest" \
    -artifactRepository "$dest" \
    -repositoryName "3.7.1 Indigo Repository" \
    -source "$dir" \
    -compress -append -publishArtifacts

Run this inside of a working Eclipse installation.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820