Jump to: navigation, search

JET FAQ How to I compile JET templates in a headless build

Revision as of 14:52, 15 September 2008 by Pelder.ca.ibm.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

JET includes an ANT task for compiling JET templates. It is intended for use with PDE-build, but see below for an important #Caveat

Let's start with the ANT task. Here's an example:

<jet.compile project="my.jet.project" destdir="jet2java" >
    <srcdir dir="." includes="templates/**/*.jet"/>
</jet.compile>

The task requires the Eclipse ANT runner (you typically are using this for PDE build). The Eclipse instance being used for the build must have JET and EMF installed (JET requires EMF). The best way to get PDE build to invoke the ant task is to use a 'custom Build Callbacks' file. Do the following:

Modify build.properties to include the following line:

customBuildCallbacks=customBuildCallbacks.xml

This tells PDE build to use customBuildCallbacks.xml (an ANT build file) for call packs. The path to the file is relative to the project.

The org.eclipse.pde.build includes template for customBuildCallbacks.xml located in the the templates/plugins directory.

There are lots of stub tasks in the template. If you're doing the 'normal' JET project, where PDE is building a JAR'd plugin, then you want to add the following to the template:

<!-- Steps to do before the compilation target                        -->
<!-- Available parameters                                             -->
<!--   source.foldern : n = 1 ... N, the source                       -->
<!--   target.folder  : where the results of the compilation          -->
<!--   @dot.classpath : name = name of the compilation target.        -->
<!--                      reference to the classpath                  -->
<!-- ================================================================ -->
<target name="pre.@dot">
  <jet.compile project="your project name" destdir="jet2java" >
    <srcdir dir="." includes="templates/**/*.jet"/>
  </jet.compile>
</target>
 
<!--  =============================================================== -->
<!-- Steps to do during the compilation target @dot, after the compile-->
<!-- but before                                                       -->
<!-- Available parameters                                             -->
<!--   source.foldern : n = 1 ... N, the source                       -->
<!--   target.folder  : where the results of the compilation          -->
<!--   @dot.classpath : name = name of the compilation target.        -->
<!--                      reference to the classpath                  -->
<!--  =============================================================== -->
<target name="post.compile.@dot">
</target>
 
<!--  =============================================================== -->
<!-- Steps to do after the compilation target                         -->
<!-- Available parameters                                             -->
<!--   jar.location - the location of the compilation                 -->
<!--   @dot.classpath : name = name of the compilation target.        -->
<!--                      reference to the classpath                  -->
<!--  =============================================================== -->
<target name="post.@dot">
</target>

You can test all of this from the workspace by changing using something other than jet2java for destdir, and then using the Export deployable plug-in wizard. After the build, you should see the generated Java classes in the destdir folder.

Caveat

Now here's the important Caveat. The jet.compile ANT task has an important design flaw - it assumes that PDE build is compiling plug-ins that are located in a workspace. In the real world, a typical PDE build script checks out project source into a directory that is not part of a workspace. See bug 210447 for the details.

The bottom line is that if you want this to work, you have to:

  1. make sure that your build somehow gets the JET projects into the workspace being used by the PDE ANT runner.
  2. make sure that any custom JET tags used by the JET projects are also projects in that workspace.

I would certainly welcome ideas/help on getting this to work. There are two possible routes:

  1. Fix it the right way, which means me making some changes to how the JET compiler, the jet.compile ant task and perhaps the projects 'manifest' information. This, unfortunately will take some time - I'm hoping to get something done for Galileo (i.e. June 2009).
  2. Figure out some hacks. I haven't delved deeply in to the mysteries of PDE build, but it seems to me that, after PDE build has checked out the projects to be built, some custom code could be added to import them into the workspace being used by PDE build. Conceptually, this is easy. Practically, I don't know how to do it.