Archive for the ‘Products’ Category

Introducing CodeGenClipse and CodeGenJostraca

Saturday, June 10th, 2006

For my first Eclipse related posting on this blog, I would like to introduce two free Eclipse plugins just released this week. I will start with CodeGenJostraca that offers integration of the Jostraca code generator into the Eclipse v3.1.2+ IDE.

Why code generation?
I am a big believer in the DRY (Don’t Repeat Yourself) principle and believe that code generation is a great tool to help achieve it’s goal. More specifically I have found that code generation (when done right) helps me improve quality and save time & effort by reducing redundancy and drudge work (especially for statically typed languages like Java or C# that I use a lot these days when doing consulting).

Why the Jostraca code generator?
A year ago while evaluation existing code generation tools, I ended up with Jostraca, a free GPL code generation tool written by Richard Rodger.

Jostraca is a template based generator that is based on extended Java Server Pages syntax. Notably, Jostraca lets you use this syntax with multiple languages, including Java, Perl, Python, Ruby etc. The output can be of any (textual) type including new source files for the project.

The Jostraca template language is much more powerful than the language for the (in eclipse circles) well know JET generator, which I have personally found inadequate for my needs. For an example of one useful Jostraca feature, that JET does not have, check the Jostraca template extract below. It that shows how to declare a java template method called “formatThis”, that just like a macro, can be called from the normal generate method:

<%@ section declare %>
<%private void formatThis(String name) {%>
<%=name%>
<%}%>

<%@ section generate %>
<% formatThis( “foo” ); %>

For those that wonder about the implementation, the above extract gets translated to a temporary codewriter class that is executed in order to produce the actual output (similar to how JSP translates into servlets that are executed upon a http request in order to produce HTML).

Jostraca has many more advanced features. Look at the Jostraca code generator documentation for details.

What CodeGenJostraca offers for your code generation needs
CodeGenJostraca allows you to create/edit your Jostraca templates in the eclipse editor. The plugin features a fully integrated (incremental) Jostraca builder that generates output automatically when you save your template file and inserts the generated output directly into your project structure at a configurable location!

As such CodeGenJostraca allows you to use codegeneration with a seamless build process just like working with normal source files (note this is very different from most other code generators, including JET, which requires you to perform special actions or even do some programming to produce your output).

CodeGenJostraca allows you to write your templates in any language supported by Jostraca, including my favourite scripting languages Ruby and Python!

However for the current release, Java based templates have the best support regarding error handling, libraries and stability. One particular notable feature – absent for all other eclipse generator tools I have heard of - is that the Java templates can access all libraries and classes on the eclipse project path! I.e. you can have external libraries or helper classes in your project that gets called when Jostraca is generating code while eclipse builds your project (note that using this feature will make your project depend on itself for building ; a bit like self hosting compilers).

My business case or why I am releasing this project (for free)?
I work as a freelance software architect/developer and also do some development on the side. I use code generation but it is not my current focus business wise. Therefore, I am releasing this project as free GPL code… So, if other developers can use this project that is fine. If some of you can come up with improvements even better ;-)

A word about the implementation and CodeGenClipse
My ultimate aim is to offer support for multiple code generators as need arises, with Jostraca being the initial focus. I have therefore released the project as two plugins:
CodeGenClipse : A generic Eclipse plugin that provides a basic foundation for integrating code generators in Eclipse. End users do not use this plugin in itself, but other plugins depends on it. This plugin is bundled with the plugin below.
CodegenJostraca : An Eclipse plugin that offers integration of the Jostraca code generator into the Eclipse IDE. This plugin is targeted towards end users and the principal subject of this posting.

Notes & disclaimers
Note that this is a beta release that has been tested under Eclipse 3.1.2 and Eclipse 3.2RC5 running JDK1.5_06 under Windows XP. It requires JDK1.5! It has NOT been tested on Unix/Linux/Mac so far. It runs stable on the few PC’s I use but that is all I can assure you of right now. Note also that of the many scripting languages supported by Jostraca, only Java, Ruby and Python has been tested so far.
In addition plugin developers interested in supporting other code generators should be aware that the CodeGenClipse plugin is a bit rough right now and the API is not stable yet.

More information
See the project homepage http://codegenclipse.sourceforge.net/ or the sourceforge project site. Alternatively contact me directly (see my homepage for details).


Bad Behavior has blocked 145 access attempts in the last 7 days.