Usage of Maven tycho-p2-plugin with SWT
Asked Answered
D

3

7

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

Deville answered 27/6, 2010 at 18:9 Comment(4)
I'd like to see this as well - good luck with an answer though :)Cobwebby
I can't find the detail of your problem. Need more information.Exempt
@Kane: What causes the error message "Could not determine SWT implementation fragment bundle"? Which information is missing in my POM?Dictionary
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?Progressive
E
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"/>
Exempt answered 2/11, 2011 at 9:12 Comment(1)
I'm building a plugin (<packaging>eclipse-plugin</packaging>) 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.Dictionary
P
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...

Progressive answered 1/11, 2011 at 10:54 Comment(6)
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.Dictionary
+1, the RCP example of tycho demonstrates how to build an application for multiple environments, such as Windows and Linux.Exempt
@Kane: I'm not building an RCP product but a bundle which depends on SWT.Dictionary
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, alistairisrael.wordpress.com/2009/07/15/… 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 :-)Progressive
No, I'm building an Xtext editor plugin. It's a simple OSGi plugin which depends on org.eclipse.swt.Dictionary
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.Progressive
D
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.

Dictionary answered 2/11, 2011 at 14:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.