Jump to: navigation, search

Sapphire Modeling Tycho build support

This page is for adopters of Sapphire framework that also use Tycho to build their eclipse plugins.

For any users that are trying to use tycho to build their eclipse plugins that use sapphire's model annotations, you will be required to configure tycho to generate the model classes as part of the maven build. In the sample Sapphire plugins this is done with a customBuildCallbacks.xml which is a facility for PDE build. Tycho doesn't support this ability out of the box but it can be easily configured by making some changes to your pom.xml and a edited version of the customBuildCallbacks.xml sample. Here is a link to the customBuildCallbacks.xml sample in CVS

In the pom.xml for any plugin that has sapphire generated models you need to have the pom run an ant script during the generate-sources phase. To do this requires both changes to pom.xml and also changes to the customBuildCallbacks.xml provided in the sapphire samples.

  1. In your pom.xml used snippet [1] to launch the ant script during generate-sources
  2. In customBuildCallback.xml, set the default ant target to be pre.@dot [2]
  3. modify the location of ant-contrib.jar for my build environment
  4. Change the <safe-apt /> task [3] to reference classpath refs provided by maven3/tycho
  5. Change the <taskdef /> element [4] for how to find the sapphire SDK ant task
  6. In plugin.xml you need to add optional dependencies these bundles [5], so that when maven/tycho generates the classpath references it will include those two jars on the classpath. There are other ways to do this in maven/tycho that are more elegant.


[1]

<build>
     <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.6</version>
        <executions>
          <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
              <target>
                <ant antfile="customBuildCallbacks.xml" inheritRefs="true" />
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

[2]

<project name="Build specific targets and properties" default="pre.@dot">

[3]

<safe-apt srcdir="src"
      destdir=".apt_generated"
      preprocessdir=".apt_generated"
      classpathref="maven.compile.classpath"
      factorypathref="maven.compile.classpath"
      compile="false"/>

[4]

<taskdef 
          resource="org/eclipse/sapphire/sdk/build/antlib.xml"
          classpathref="maven.compile.classpath"/>

[5] Optional dependencies in MANIFEST.MF

org.eclipse.sapphire.sdk;bundle-version="0.3.0";resolution:=optional,
org.eclipse.sapphire.sdk.build.processor;bundle-version="0.3.0";resolution:=optional

Alternative Using Codehaus APT Plugin

Instead of using the Ant invocation specified above, you may use the Codehaus APT plugin. This simplifies the build process a bit. To configure your project:

  1. Follow step [5] above, adding the sdk plugins as optional dependencies to your plugin manifest.
  2. Configure the APT plugin in the build section of your pom as follows:
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>apt-maven-plugin</artifactId>
        <version>1.0-alpha-4</version>
        <executions>
          <execution>
            <goals>
              <goal>process</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <factory>org.eclipse.sapphire.sdk.build.processor.internal.APFactory</factory>
        </configuration>
      </plugin>
    </plugins>
  </build>