Steven Cherry’s Blog

Random ranting and musing

Automating Eclipse Headless Builds with Zed Builds and Bugs

I was reading through the Zed Documentation and found a nice guide on how to use Zed to implement Eclipse headless builds using Zed. We’ve been using Eclipse since the start of the Shadow Studio, and this looked like a nice solution since we also use Zed to manage our automated builds. So, I decided to give it a shot.

Our application consists of roughly 27 Eclipse plugins, and since this was going to be a change to our existing config/build system I decided to start with a small subset of our application to test the theory with. We have a new Web Services Consumption component that is under development and looked to be a perfect candidate to run the test with.

Some key points for the application that made it a good fit:

  • It was new, so changing things wouldn’t break any existing builds
  • It was nicely self-contained with its own feature definition, and just a few dependencies on the main plugin that defines our product
  • It is not enormous – only about 11 plugins in total, so very manageable

With this small project we easily met the recommended prerequisites from Hericus, so I started to proceed.

First I updated our existing source tag and checkout to include the WSC modules:

svn checkout file:///var/svn/studio/eclipse/tags/${BUILD_TAG}/com.shadowstudio.wsc
svn checkout file:///var/svn/studio/eclipse/tags/${BUILD_TAG}/com.shadowstudio.wsc.doc
...

Next I added the following steps to our build definition:

Create genbuildxml file. Following the guidelines this is a simple Ant build XML file that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project name="buildBuildFiles" default="all" basedir=".">
        <target name="all">
                <eclipse.buildScript elements="feature@com.shadowstudio.wsc.feature"
                        buildDirectory="${WORKDIR}"
                        baseLocation="c:/eclipse34/"
                />
        </target>
</project>

The ability to use the Zed replacement variables like “${WORKDIR}” comes in very handy for creating files on the fly like this.

Generate build.xml files. Now we use the above created build file to use the eclipse Ant task to automatically create the required build.xml files for the feature. Here’s the command:

c:\jdk1.5.0_05\bin\java -cp c:\eclipse34\plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar org.eclipse.core.launcher.Main -application org.eclipse.ant.core.antRunner -Dws=win32 -v -file ${WORKDIR}/genbuildxml.xml

Looking at it, I really should have defined an build environment variable for the location of the eclipse launcher so that when (not if!) it changes we only have to do it in one place. Note to self – do this. TODO.

Fix autogenerated defaults. The eclipse ant tasks that create the build.xml files have some defaults that they inject into the build.xml files that I don’t like. It’s trivial with Zed to go through these and update them to what I want them to be:

  • Change javacFailOnError from “false” to “true” – I like builds to fail when the compiles fail.
  • Change javacSource from “1.3” to “1.5” – we require a 1.5 JDK for our product.
  • Change javacTarget from “1.2” to “1.5” – same reason.
  • Also look for our version number eye-catcher and update it to the correct setting using ${BUILD_FULL_VERSION}

Run the feature build. At this point, I’m ready to run the feature build, so I added a command step with the following:

c:\jdk1.5.0_05\bin\java -cp c:\eclipse34\plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar org.eclipse.core.launcher.Main -application org.eclipse.ant.core.antRunner -Dws=win32  -file ${WORKDIR}/com.shadowstudio.wsc.feature/build.xml clean build.jars

Again, here’s where that environment variable would have come in handy so I don’t have the eclipse launcher hard-coded in each step. TODO.

Build the WSC Package. Now, this really could have been done in the step above, but there are a hand-full of things that we add in after eclipse has built all of the jars but before the final package is assembled. These typically have to do with native libraries or DLL’s that we need to add to the package that eclipse isn’t aware of. So the final command is:

c:\jdk1.5.0_05\bin\java -cp c:\eclipse34\plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar org.eclipse.core.launcher.Main -application org.eclipse.ant.core.antRunner -file ${WORKDIR}/com.shadowstudio.wsc.feature/build.xml zip.distribution

And with that, we have a nice WSC feature jar file all packaged up and ready for inclusion in our final packaging steps.

Following the guide from the Hericus documentation made things really a snap. I just need to circle back and get that eclipse launcher reference out of each of the commands and use a single environment variable to make it easy to maintain.

May 15, 2009 Posted by | Uncategorized | 1 Comment