Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of Maven tycho-p2-plugin with SWT

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

like image 996
msshapira Avatar asked Jun 27 '10 18:06

msshapira


2 Answers

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"/>
like image 73
Kane Avatar answered Sep 22 '22 22:09

Kane


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.

like image 26
Aaron Digulla Avatar answered Sep 25 '22 22:09

Aaron Digulla