Friday, January 8, 2010

Running Open Architecture Ware workflows on save

We use open architecture ware for Aranea. With Aranea you can use a domain specific language (dsl) to model messages which can be send between Aranea nodes (computers). For example a message to send a status could look something like this:
[project AraneaDemo prefix=A_] { 
 [namespace Core] {
  [message Status] {
   properties={
    message: string notVoid
   }
  }
 }
}
Open Architecture Ware is then used to interpret the dsl, generate a model out of it, and then generate Java and Eiffel code out of this model. The Java class for the message above looks something like this:

GeSHi © 2004-2007 Nigel McNie, 2007-2009 Benny Baumann, 2008-2009 Milian Wolff
  1. package aranea.demo.core;
  2.  
  3. public class StatusMessage extends AraneaMessage {
  4.  
  5.         public final String message;
  6.  
  7.         /**
  8.          * Constructs a <code>Status</code> message without reply handler.
  9.          *
  10.          */
  11.         public StatusMessage(String message) {
  12.                 this(message, null);
  13.         }
  14.  
  15. }
Parsed in 0.093 seconds at 2.88 KB/s
A so called worklflow is used to script how to convert the dsl file.

The past

Until now it was required to invoke the workflow by hand, that is: right click and select 'run oaw workflow' from the context menu. That was not very cool and sometimes we forgot to regenerate the classes after changing the dsl. I thought a better solution would be to use a builder.

Ant builder

Did you know that eclipse can run any ant script on build? You can add an ant builder to your projects and define when to execute the ant scripts. Right click your project then open Properties and open the Builder property page:

Adding a new builder is trivial. The hard part was to write the ant script such that it can be executed. After a few days of trial and error I was able to create a script which can run any OAW workflow. The files are below and licensed under MIT license. I hope this is of use to someone. If you want to play with it read trough this site: http://aranea.origo.ethz.ch/wiki/how_to_create_an_aranea_message_project

GeSHi © 2004-2007 Nigel McNie, 2007-2009 Benny Baumann, 2008-2009 Milian Wolff
  1. <project name="project" default="main" basedir=".">
  2.        
  3.         <import file="runOAW.xml"/>
  4.  
  5.     <target name="main" description="the main entry point">
  6.                 <antcall target="buildJava"/>
  7.         <antcall target="buildEiffel"/>
  8.     </target>
  9.        
  10.         <target name="buildJava" description="build the java messages">
  11.         <property name="workflowLocation"  value="${basedir}/src"/>
  12.         <property name="workflowFile" value="GenerateJavaMessages.oaw"/>
  13.         <antcall target="RunOaW.generate" />
  14.     </target>
  15.        
  16.         <target name="buildEiffel" description="build the java messages">
  17.         <property name="workflowLocation"  value="${basedir}/src"/>
  18.         <property name="workflowFile" value="GenerateEiffelMessages.oaw"/>
  19.         <antcall target="RunOaW.generate" />
  20.     </target>
  21.  
  22. </project>
  23.  
  24. <project name="RunOaW" default="generate" basedir=".">
  25.  
  26.         <property name="eclipse" value="${eclipse.pdebuild.home}/../.."/>
  27.         <property name="plugins"  value="${eclipse}/plugins"/>
  28.        
  29.    <!-- Classpath Definition -->
  30.         <path id="deps.classpath">
  31.                 <fileset dir="${plugins}/">
  32.                         <include name="org.openarchitectureware.*.jar"/>
  33.                         <include name="org.apache.commons.*.jar"/>
  34.                         <include name="org.eclipse.*.jar"/>
  35.                 </fileset>
  36.                 <fileset dir="${plugins}/org.antlr_3.0.0">
  37.                         <include name="*.jar"/>
  38.                 </fileset>
  39.                 <fileset dir="${plugins}/org.antlr.runtime_3.0.0">
  40.                         <include name="*.jar"/>
  41.                 </fileset>
  42.                 <pathelement path="${workflowLocation}" />
  43.                 <pathelement path="${basedir}/../araneaMessage.dsl.generator/bin"/>
  44.                 <pathelement path="${basedir}/../araneaMessage.dsl/bin"/>
  45.                 <fileset dir="${plugins}/">
  46.                         <include name="araneaMessage.dsl*.jar" />
  47.                 </fileset>
  48.         </path>
  49.  
  50.    <target name="generate">
  51.       <taskdef name="workflow" classpathref="deps.classpath" classname="org.openarchitectureware.workflow.ant.WorkflowAntTask" >
  52.       </taskdef>
  53.       <workflow file="${workflowFile}">
  54.                  <classpath>
  55.                     <path refid="deps.classpath" />
  56.                  </classpath>
  57.       </workflow>
  58.        
  59.    </target>
  60.  
  61. </project>
  62.  
Parsed in 0.016 seconds at 126.32 KB/s

This form post helped me a lot to get this script right.

No comments:

Post a Comment

Followers