Wednesday, August 25, 2010

Headless Build for Beginners - part V

Headless building Update Site

There is no easy way to achieve this. There have been some discussions in past and the Build and Test Automation article too touched it in brief. But its all hacky. I tried various stuff but the closest I could get was build features and plug-ins using (mentioned in) a site.xml and generating the metadata for them. The site.xml can be placed with them manually but I could not find a way to (automatically) update the site.xml with the feature and plug-ins build qualifiers. (There are always hacks like having a dummy site.xml and do a find-replace in it. Or write a custom ant task that emits XML for ste.xml - none of the hack is very maintainable or scalable)

After more investigation I realized may be I was trying to solve the wrong problem. We really don't need the update site (not if you are using Eclipse 3.4 or later). A p2 repository is not only easy to generate but is also the recommended way of distributing features and plug-ins.

Headless building a p2 repository

Now a p2 repo can be generated either from a bunch of features and plug-ins or directly from a product configuration. Both explained in Eclipse help. We will here take a product configuration and build a p2 repository for it. The setup will be same as discussed before. However this time, we will copy all the files from /org.eclipse.pde.build/templates/headless-build folder to our build configuration folder (build\buildConfiguration). Thus, the build structure will now looks like this

<buildConfigurationDirectory>
       allElements.xml
       build.properties
       customAssembly.xml
       customTargets.xml
<buildDirectory>
       plugins/
              com.example.helloworld
              com.example.product
                     example.product
       features/
              com.example.helloworld.feature

The current setup will generate the product when build. We now need to add a hook for repository generation. This can be done in customAssembly.xml. Open it in Eclipse or your favorite text editor and make the following changes in post.gather.bin.parts target.

<target name="post.gather.bin.parts">
 <p2.publish.featuresAndBundles
  repository="file:/${buildDirectory}/repository"
  source="${buildDirectory}/tmp/${archivePrefix}" 
  compress="true"
 >
 </p2.publish.featuresAndBundles>
</target>       

Note that p2.publish.featuresAndBundles is just of the of ant task that can be used to generate metadata. There are more for different situations. The idea here was more to see how to add custom call in ant scripts.

Run the build as before
java -jar c:\eclipse\plugins\org.eclipse.equinox.launcher_1.1.0.v20100507.jar -application org.eclipse.ant.core.antRunner -buildfile c:\eclipse\plugins\org.eclipse.pde.build_3.6.0.v20100603\scripts\productBuild\productBuild.xml -Dbuilder=c:\build\buildConfiguration

This will create a p2 metadata repository in file:/${buildDirectory}/repository folder. You can control the location using repository property.

Tuesday, August 24, 2010

Headless Build for Beginners - part IV

Customizing the build

Not always we want the build to happen according to the out-of-the-box scripts.In fact, customizations are almost always needed - be it fetching the sources or the way we wish to assemble them. PDE Build provides a set of templates which can be used to hook in the customize (add to and/or override) the default behavior.

These templates are available in PDE Build plug-in (inside templates\headless-build folder of org.eclipse.pde.build_<version><qualifier>). The scripts and templates are one the main reason why PDE Build plug-in is a directory and not a jar.

The purpose and usage of these templates have been explained nicely in Eclipse help under the topic Customizing a Headless Build.

These templates are
  • customTargets,xml
  • allElements.xml
  • customAssembly.xml
In short, the customTargets.xml have various pre- and post- ant targets that build.xml (or productBuild.xml - in case you are building a product) calls before and after each process (like setup, source fetch, build, assemble, package, etc). Similarly, the targets in allElements.xml and customAssembly.xml gets delegated for various jobs.

To use these templates we need to copy them in the build configuration directory (c:\build\buildConfiguration in our example) where we stored build.properties file in previous steps. And then modify the appropriate targets. This is what we will do for building an update site in next step.

Tuesday, August 17, 2010

e4 Talk by Boris

Boris Bokowski (@bokowski) will be talking about e4 at IBM EGL Campus on Friday, August 20, 2010 (3 to 4 PM). See the details on the Bangalore Eclipse Developer's Groups.