# Ant tasks support

Operational QVT Ant tasks let you launch QVTO transformations from the Ant script. These tasks can be run either from the Eclipse user interface or the command line.

## Creating an Ant script

Transformation with the following signature

    modeltype ECORE uses 'http://www.eclipse.org/emf/2002/Ecore';
    transformation Transf(inout m1 : ECORE, out m2 : ECORE);

in assumption that it is stored in workspace in project "qvto" under "transforms" folder, can be called from Ant script as follows

    <project name="project" default="default" xmlns:qvto="http://www.eclipse.org/qvt/1.0.0/Operational">
        <target name="default">

            <qvto:transformation
                uri="platform:/resource/qvto/transforms/Transf.qvto"
                >

                <inout
                    uri="platform:/resource/qvto/transforms/in.ecore"
                    outuri="platform:/resource/qvto/transforms/out_in.ecore"
                />
                <out
                    uri="platform:/resource/qvto/transforms/test.ecore#//cls">
                    <feature
                        name="eAnnotations"
                        clearcontents="true"
                    />
                </out>

                <trace
                    uri="platform:/resource/qvto/transforms/Transformation.qvtotrace"
                />
            </qvto:transformation>

        </target>
    </project>

Ant task used to run QVTO transformation is `http://www.eclipse.org/qvt/1.0.0/Operational:transformation`. Nested element and attribute definitions follows:

<Tag> / "Attribute" | Description
<transformation> | References QVTO transformation task.
"uri" | URI of the transformation file to be executed.
<in> | References corresponding (in order) [in] transformation parameter.
"uri" | URI of the [in] transformation parameter.
<inout> | References corresponding (in order) [inout] transformation parameter.
"uri" | URI of the [inout] transformation parameter passed as input. If "outuri" attribute is ommited then that URI is used to store output as well.
"outuri" | URI for storing modified [inout] transformation parameter
<out> | References corresponding (in order) [out] transformation parameter.
"uri" | URI for storing [out] transformation parameter
<feature> | References target structural feature (related to [out] transformation parameter URI) to save the result to.
"name" | Name the target structural feature to save the result to.
"clearcontents" | Specifies whether you want to clear contents of the target feature before writing the result.
<trace> | References trace instance that is created upon transformation execution. If this tag is omitted, trace is not saved.
"uri" | URI for storing trace file.

All URIs used in transformation task (transformation URI, transformation's parameter URI, trace URI) are resolved due to the following rules:

- in case it's platform URI (URI.isPlatform() == true) - it is used as-is
- in case it's non-relative file URI (URI.isRelative() == false) - it's resolved against workspace root
- in case it's relative file URI (URI.isRelative() == false) but starts with ["\", "/"] - it's resolved against workspace root
- in case it's relative file URI (URI.isRelative() == false) and does not start with ["\", "/"] - it's resolved against script location

## Running script as an Ant task from the Eclipse user interface

- You must make sure that the script will be run in the same JRE as your workspace. To do this, right-click your build file in the Navigator View and choose Run As->Ant Build....
- In the Edit Configuration dialog, open the JRE tab and select the Run in the same JRE as the workspace option. This step must be completed before you run the build script for the first time.
- Run the script by right-clicking the build file and choosing Run As->Ant Build.

## Running script as an Ant task from the command line

In a command shell, run a command similar to the following one:

    java -Xms128m -Xmx1024m -XX:MaxPermSize=256m -jar ./plugins/org.eclipse.equinox.launcher_<version>.jar
      -data <WORKSPACE_PATH> -nosplash -consolelog -application org.eclipse.ant.core.antRunner -f <ANTSCRIPT>

where <WORKSPACE_PATH> is the path to your workspace and <ANTSCRIPT> is the path to your Ant script file.