Tutorial – First TRIMM Groovy project (standalone)

This is the simplest TRIMM Groovy project possible. It doesn’t require any project dependencies.

Prerequisites:

Step 1 – Create an Enterprise Architect Model

See Trimm Java tutorial (standalone)

Step 2 – Configure the TRIMM Groovy code generator

TRIMM Groovy’s default configuration format is YAML, which is a very simple file format (like XML but without all the noisy brackets < >)
We create a configuration file e.g. called GroovyModel.yml (the name and extension can be anything you like) and place it in C:\TRIMM-examples\SimplestGroovyModel\
You can use NotePad, Edit, NotePad++ or what ever you like to create the file.

The first thing we need to tell TRIMM is where our XMI file is placed:

xmiModelPath: mysimplemodel.xml

Next we need to tell TRIMM which UML tool we used. Since we used Enterprise Architect we will use the value EA

umlTool: EA

Note: Other possible values are MagicDraw16, MagicDraw17 or the FQCN (Fully Qualified Class Name) for a Java class on the classpath that implements the XmiReader interface. Alternative you can specify a .groovy script (that also implements the XmiReader interface)

Finally we need to specify where TRIMM should output its files (relative to the directory from which it is run)
We do this using the generateBaseClassesToPath setting:

generateBaseClassesToPath: output

Note: The TRIMM code generator automatically cleans up files in its output folder that wasn’t part of the code generation phase. It’s therefore necessary that you specify generateBaseClassesToPath to be something different than an empty value, otherwise you will loose all the contents in your project folder!

The complete configuration file looks like this:

xmiModelPath: mysimplemodel.xml
umlTool: EA
generateBaseClassesToPath: output

That’s it for this simple model.

Step 3 – Generate code using TRIMM Groovy standalone

Open a Command Prompt (or Terminal on Unix/OSX)
For this example I’m assuming that you have extracted TRIMM Groovy standalone to C:\TRIMM-examples\SimplestGroovyModel\ so that this folder now contains a bin and repo folder:

simple-groovy-folder-view

We want the generated code to be placed in a subfolder called generated.
Run the following command from the command prompt (on Windows):
bin\GroovyYamlGenerator -yaml GroovyModel.yml

This will yield a lot of console output which ends with the following:

simple-groovy-output-start-small

If we do a listing of the files in the output then we will see that it contains subfolders matching the dk.tigerteam.examples.simplestgroovymodel we added to the UML model.
It also contains two files ContactInfo.groovy and Customer.groovy which are generated based on the two UML classes in the model.

simple-groovy-output-folder-small

Customer.groovy

package dk.tigerteam.examples.simplegroovymodel

import java.util.Date
import dk.tigerteam.examples.simplegroovymodel.ContactInfo

class Customer {

/**
 * No documentation<p/>
 * Defined in Customer<p/>
 */
int age

/**
 * No documentation<p/>
 * Defined in Customer<p/>
 */
java.util.Date created

/**
 * No documentation<p/>
 * Defined in Customer<p/>
 */
String firstName

/**
 * No documentation<p/>
 * Defined in Customer<p/>
 */
String lastName

ContactInfo contactInfo

}

ContactInfo.groovy

package dk.tigerteam.examples.simplegroovymodel

class ContactInfo {

/**
 * No documentation<p/>
 * Defined in ContactInfo<p/>
 */
String email

/**
 * No documentation<p/>
 * Defined in ContactInfo<p/>
 */
String mobilePhone

}