Ant Tasks

On this page we explain how to work with ABS models using Ant. The tasks of this page are all included in the file build.xml template file.

Prerequisites

Folder Layout

The following targets are all based on the following project layout:

+ Project
  +- src/abs/     -- contains all .abs files of the ABS model
     +- test.abs  -- an abs file with a module <<<Test>>> and a main block
  +- lib/         -- contains necessary jar files
  +- target/java  -- will contain generated Java code and is created

Test File

The file test.abs has the following content:

module Test;

// the main block
{
  assert False;
}

Ant Properties

We thus use the following Ant properties. The only property which has to be adapted for your project is the abs.mainmodule property, which specifies which main block is executed when executing the ABS system.

  <property name="lib" location="lib" />
  <property name="src" location="src" />
  <property name="target" location="target" />
   
  <property name="src.abs" location="${src}/abs" />
  <property name="target.java.src" location="${target}/java/src" />
  <property name="target.java.bin" location="${target}/java/bin" />

  <property name="lib.abs" location="${lib}/absfrontend.jar" />

  <!-- change this to the name of the module that contains the main block -->
  <property name="abs.mainmodule" value="Test" />

Classpath

We define the build.abs.classpath to hold the absfrontend.jar

ABS model files

<path id="build.abs.classpath">
   <pathelement location="${lib.abs}"/>
</path>

The fileset src.abs.files and the path absfileargs hold all ABS files of the ABS model.

<fileset dir="${src.abs}" id="src.abs.files">
   <include name="**/*.abs" />
</fileset>
<pathconvert property="src.abs.fileargs" refid="src.abs.files" pathsep=" " />

Prepare

The target prepare creates the necessary target folders. It depends on the target lib.abs.getjar explained below.

<target name="prepare" depends="lib.abs.getjar">
  <mkdir dir="${target.java.src}" />
  <mkdir dir="${target.java.bin}" />
</target>

Clean

A corresponding clean target deletes all generated files

<target name="clean" description="Removes all generated files">
  <delete failonerror="false" includeemptydirs="true">
    <fileset dir="${target}"/>
  </delete>
</target>

Download the newest ABS JAR

In order to automatically download the newest absfrontend.jar you can use the following Ant target:

<target name="lib.abs.getjar">
  <mkdir dir="${lib}" />
  <get src="http://tools.hats-project.eu/download/absfrontend.jar"
       dest="${lib}" usetimestamp="true" verbose="true" />
</target>

This target will download the absfrontend.jar and put it into the lib folder. Before downloading it will check if the newest version (based on a timestamp) is already existing and only download the jar file if it is newer than the existing one.

Type-Check the ABS model

To type check an ABS model use the following target:

<target name="abs.typecheck" depends="prepare">
  <java classname="abs.frontend.parser.Main"
     fork="true" failonerror="true"
     classpathref="build.abs.classpath">
     <arg line="${src.abs.fileargs}"/>
  </java>
</target>

Generate, Compile, and run Java code

Generate Java code

To generate Java code from the ABS model use the following target:

<target name="abs.generate.java" 
  description="Generates Java code" depends="clean,prepare">
  <echo>FILES: ${src.abs.fileargs}</echo>
  <java classname="abs.backend.java.JavaBackend" 
    fork="true" failonerror="true" classpathref="build.abs.classpath">
    <arg line="${src.abs.fileargs}"/>
    <arg value="-sourceonly" />
    <arg value="-d" />
    <arg value="${target.java.src}" />
  </java>
</target>

Compile Java code

To compile the generated Java code use the following target:

<target name="abs.compile.java" depends="abs.generate.java">
  <javac classpathref="build.abs.classpath" 
     srcdir="${target.java.src}" 
     destdir="${target.java.bin}">
  </javac>
</target>

Run Java code

The following target runs the generated Java code

  <target name="abs.run.java" depends="abs.compile.java">
    <java classname="${abs.mainmodule}.Main">
       <classpath>
	 <path refid="build.abs.classpath" />
	 <pathelement path="${target.java.bin}" />
       </classpath>
    </java>
  </target>