www.BrettDaniel.com

Testing a Testing Tool Part Two: Build and Deploy Local Eclipse Plugin

In my previous post, I discussed the first of several challenges I encountered when testing ReAssert. In this, the second of three articles in the series, I will describe how I automatically deployed the tool for my own use.

Build and Deploy Local Eclipse Plugin

When developing software tools, it is good practice to eat one's own dog food by using the tool oneself. It is one of the easiest ways to uncover bugs and improve usability. I ate ReAssert's dog food by using it to repair tests in other research projects and (as I'll describe in the next post) ReAssert itself.

ReAssert is implemented as an Eclipse plugin. The easiest way to deploy such a plugin is to include it in Eclipse's plugins directory1. When Eclipse starts, it automatically loads all plugins in the directory. If there is more than one version of a particular plugin, Eclipse loads the most recent.

To keep from having to install ReAssert's plugin manually, I made it such that the normal build process automatically updates version numbers and copies the plugin to the appropriate place. A single Ant build script handles the entire process.

The main challenge lies in accessing Eclipse's build metadata in the script. Each Eclipse plugin holds the metadata in a file called MANIFEST.MF. It contains things like the plugin's name, it's version number, and the other plugins it depends on. For example, here is part of ReAssert's:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: edu.illinois.reassert.plugin
Bundle-SymbolicName: edu.illinois.reassert.plugin;singleton:=true
Bundle-Version: 0.3.0.201002231921
Bundle-Activator: edu.illinois.reassert.plugin.ReAssertPlugin
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 ...
Bundle-Vendor: University of Illinois at Urbana-Champaign

ReAssert's build script first updates this file with the build number (based on the current date and time). Then, it reads the version and build number by converting MANIFEST.MF into a Ant property file. Finally, it bundles the plugin using the values.

Here are the relevant pieces of the script that implements this process:

  1. Set the date and time with tstamp, then replace the build number in the manifest with the date and time.
    <tstamp /> <!-- set ${DSTAMP} and ${TSTAMP} -->
    <replaceregexp 
        file="META-INF/MANIFEST.MF" 
        match="Bundle\-Version: ([0-9]+\.[0-9]+\.[0-9]+)\.([0-9]+)"
        replace="Bundle-Version: \1.${DSTAMP}${TSTAMP}" />
  2. Convert MANIFEST.MF into manifest.properties that Ant can read.2
    <copy file="META-INF/MANIFEST.MF" tofile="manifest.properties" />
    <replace file="manifest.properties">
      <replacefilter token=":=" value="=" />
      <replacefilter token=":" value="=" />
      <replacefilter token=";" value="" />
    </replace>
    <property file="manifest.properties"/>
  3. Set plugin name using the properties and bundle the plugin's JAR file.
    <property 
        name="plugin.jar" 
        value="${dist.dir}/${Bundle-Name}_${Bundle-Version}.jar" />
    <jar 
        destfile="${plugin.jar}"
        manifest="META-INF/MANIFEST.MF">
      <fileset dir="${bin.dir}" />
      <fileset dir="." includes="${lib.dir}/**/*" />
      <fileset dir="." includes="META-INF/MANIFEST.MF" />
      <fileset dir="." includes="plugin.xml" />
    </jar>
  4. Copy the JAR to Eclipse's plugins directory. The eclipse.home variable is set when the script is run within Eclipse.
    <copy file="${plugin.jar}" todir="${eclipse.home}/plugins/" />
    <echo>Restart Eclipse to enable plugin</echo>

It is a pretty straightforward process but useful to keep my installed version of ReAssert up to date.

I have also seen a similar process scaled up to an entire enterprise. The company had an automated nightly build process that would post the plugin to an Eclipse Update Site on the local intranet. Every morning developers would update to the latest plugin. Any bugs they found while using the tool went straight into the bug tracking system.

Notes

  1. One can also install plugins through Eclipse's Update Manager with a plugin update site, but I felt this was overkill for ReAssert since it was such a simple plugin.
  2. Adapted from this article describing how to build a simple plugin.

No Comments

Leave a Comment

Allowed Tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">