Jump to: navigation, search

Difference between revisions of "ATL/User Guide - Building ATL With ANT And Maven"

< ATL
 
(8 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
Currently Maven doesn't provide any plugin to compile ATL files and given such limitations a workaround is necessary. A custom ANT task has been developed that receives .atl files as input and then compiles them into .asm files. The following instructions describe how to set up a project to compile ATL files.  
 
Currently Maven doesn't provide any plugin to compile ATL files and given such limitations a workaround is necessary. A custom ANT task has been developed that receives .atl files as input and then compiles them into .asm files. The following instructions describe how to set up a project to compile ATL files.  
  
= ATL Compilation ANT task =
+
= ATL Compilation ANT Task  =
* Create a new project to contain the ATL compilation ANT task
+
* Create the ANT task suing the following code:
+
  
  package com.ericsson.ecim.ant;
+
*Create a new project to contain the ATL compilation ANT task
 +
*Create the ANT task using the following code:<br>
 +
 
 +
  package com.x.ant;
 
  import java.io.File;
 
  import java.io.File;
  import java.io.FileInputStream;
+
  import java.io.FileInputStream;  
 
  import java.util.Iterator;
 
  import java.util.Iterator;
 
  import java.util.Vector;
 
  import java.util.Vector;
  import org.apache.tools.ant.BuildException;
+
  import org.apache.tools.ant.BuildException;  
 
  import org.apache.tools.ant.Task;
 
  import org.apache.tools.ant.Task;
 
  import org.apache.tools.ant.types.FileSet;
 
  import org.apache.tools.ant.types.FileSet;
Line 20: Line 21:
 
  import org.apache.tools.ant.types.resources.FileResourceIterator;
 
  import org.apache.tools.ant.types.resources.FileResourceIterator;
 
  import org.eclipse.m2m.atl.engine.compiler.atl2006.Atl2006Compiler;
 
  import org.eclipse.m2m.atl.engine.compiler.atl2006.Atl2006Compiler;
 +
 
  public class AtlCompilerTask extends Task {
 
  public class AtlCompilerTask extends Task {
private Atl2006Compiler compiler = new Atl2006Compiler();  
+
  private Atl2006Compiler compiler = new Atl2006Compiler();
private Vector<FileSet> filesets = new Vector<FileSet>();
+
     
        public AtlCompilerTask() {
+
  private Vector&lt;FileSet&gt; filesets = new Vector&lt;FileSet&gt;();
                Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+
        }
+
  public AtlCompilerTask() {
    public void addFileset(FileSet fileset) {
+
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        filesets.add(fileset);
+
  }
    }  
+
        @Override
+
  public void addFileset(FileSet fileset) {
        public void execute() throws BuildException {
+
      filesets.add(fileset);
                try {
+
  }
                        //iterate over all the FileSet(s) passed in from ANT
+
     
                        for(Iterator<FileSet> itFSets = filesets.iterator(); itFSets.hasNext();)  
+
      @Override
                        {
+
      public void execute() throws BuildException {
                    //get a FileSet
+
              try {
                    FileSet fs = itFSets.next();       
+
                      //iterate over all the FileSet(s) passed in from ANT
                    FileResourceIterator iter = (FileResourceIterator)fs.iterator();
+
                      for(Iterator&lt;FileSet&gt; itFSets = filesets.iterator(); itFSets.hasNext();)  
                 
+
                      {
                    //loop over all the files in a given FileSet
+
                          //get a FileSet
                    while(iter.hasNext())
+
                          FileSet fs = itFSets.next();
                    {
+
        
                        FileResource fr = (FileResource)iter.next();
+
                          FileResourceIterator iter = (FileResourceIterator)fs.iterator();
                        File file = fr.getFile();    
+
                 
                        //compile each ATL file suffixing it with .asm
+
                          //loop over all the files in a given FileSet
                        compiler.compile(new FileInputStream(file),file.getAbsolutePath().replace(".atl", ".asm"));
+
                          while(iter.hasNext())
                    }
+
                          {
                }  
+
                              FileResource fr = (FileResource)iter.next();
                }
+
                              File file = fr.getFile();
                catch (Exception e) {
+
                     
                        e.printStackTrace();
+
                              //compile each ATL file suffixing it with .asm
                        throw new BuildException("Exception while calling the ATL compiler task.", e);
+
                              compiler.compile(new FileInputStream(file),file.getAbsolutePath().replace(".atl", ".asm"));
                }
+
                          }
        }
+
                      }  
 +
              }
 +
              catch (Exception e) {
 +
                      e.printStackTrace();
 +
                      throw new BuildException("Exception while calling the ATL compiler task.", e);
 +
              }
 +
      }
 
  }
 
  }
  
* Ensure you have all the ATL dependencies on your ANT builder classpath
+
*Ensure you have all the ATL dependencies on your ANT builder classpath
  
= ATL Compilation Maven Build =
+
= ATL Compilation Maven Build =
* We assume the ANT task defined above exists in your workspace
+
* Add a build procedure to the .pom file located in the project for which you wish to compile its .atl sources, as follows:
+
  
<!-- build ATL files -->
+
*We assume the ANT task defined above exists in your workspace
         <build>
+
*Add a build procedure to the .pom file located in the project for which you wish to compile its .atl sources, as follows:
                <plugins>
+
 
                        <plugin>
+
<!-- build ATL files -->  
                                <groupId>org.apache.maven.plugins</groupId>
+
 
                                <artifactId>maven-antrun-plugin</artifactId>
+
         &lt;build&gt;
                                <version>1.7</version>
+
            &lt;plugins&gt;
                                <executions>
+
                    &lt;plugin&gt;
                                        <execution>
+
                            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                                                <id>compile</id>
+
                            &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
                                                <phase>compile</phase>
+
                            &lt;version&gt;1.7&lt;/version&gt;
                                                <configuration>
+
                            &lt;executions&gt;
                                                        <target>
+
                                    &lt;execution&gt;
                                                                <property name="com.x.ant.location" value="../com.x.ant" />
+
                                            &lt;id&gt;compile&lt;/id&gt;
                                                                <property name="dependency-classpath" refid="maven.dependency.classpath" />
+
                                            &lt;phase&gt;compile&lt;/phase&gt;
                                                                <echo message="Start ATL compilation" />
+
                                            &lt;configuration&gt;
                                                                <echo message="Maven Dependencies: ${dependency-classpath}" />
+
                                                    &lt;target&gt;
 +
                                                            &lt;property name="com.x.ant.location" value="../com.x.ant" /&gt;
 +
                                                            &lt;property name="dependency-classpath" refid="maven.dependency.classpath" /&gt;
 +
                                                            &lt;echo message="Start ATL compilation" /&gt;
 +
                                                            &lt;echo message="Maven Dependencies: ${dependency-classpath}" /&gt;
 
                                                                 <!-- reference custom ant task called AtlCompilerTask located in
 
                                                                 <!-- reference custom ant task called AtlCompilerTask located in
 
                                                                         project com.x.ant -->
 
                                                                         project com.x.ant -->
                                                                <taskdef name="compileATL"
+
                                                                        classpath="${com.x.ant.location}/target/AtlCompilerTask.jar"
+
                                                                        classname="com.x.ant.AtlCompilerTask" classpathref="maven.dependency.classpath" />
+
 +
                                                            &lt;taskdef name="compileATL"
 +
                                                                    classpath="${com.x.ant.location}/target/AtlCompilerTask.jar"
 +
                                                                    classname="com.x.ant.AtlCompilerTask" classpathref="maven.dependency.classpath" /&gt;
 
                                                                 <!-- invoke task compilerATL to generate an .asm file for each .atl file under ATL folder -->
 
                                                                 <!-- invoke task compilerATL to generate an .asm file for each .atl file under ATL folder -->
                                                                <compileATL>
+
                                                                        <fileset dir="${basedir}/ATL" includes="**/*.atl" />
+
                                                                </compileATL>
+
                                                                <echo message="Done!" />
+
                                                            &lt;compileATL&gt;
                                                        </target>
+
                                                                    &lt;fileset dir="${basedir}/ATL" includes="**/*.atl" /&gt;
                                                </configuration>
+
                                                            &lt;/compileATL&gt;
                                                <goals>
+
                                                            &lt;echo message="Done!" /&gt;
                                                        <goal>run</goal>
+
                                                    &lt;/target&gt;
                                                </goals>
+
                                            &lt;/configuration&gt;
                                        </execution>
+
                                            &lt;goals&gt;
                                </executions>
+
                                                    &lt;goal&gt;run&lt;/goal&gt;
                        </plugin>
+
                                            &lt;/goals&gt;
                </plugins>
+
                                    &lt;/execution&gt;
        </build>
+
                            &lt;/executions&gt;
 +
                    &lt;/plugin&gt;
 +
            &lt;/plugins&gt;
 +
    &lt;/build&gt;
  
* If not already done, add a reference to the ATL folder in your project's build.properties, so that all .atl and .asm files can be included inside the jar generated for that particular project module, as follows:
+
*If not already done, add a reference to the ATL folder in your project's build.properties, so that all .atl and .asm files can be included inside the jar generated for that particular project module, as follows:
  
 
  source.. = src/
 
  source.. = src/
Line 109: Line 125:
 
  plugin.properties
 
  plugin.properties
  
Some notes:
+
Some notes:  
* The build section is executed during compilation phase, invoking the task<compileATL> defined in AtlCompilerTask.jar This task receives as input all references to those files ended with .atl suffix under the folder ATL and then starts their compilation, creating their equivalent .asm file. It's mandatory that AtlCompilerTask.jar exists just before executing the ant script, for this reason the project com.ericsson.ecim.ant should always be compiled before any project that uses ATL.  
+
 
 +
*The build section is executed during compilation phase, invoking the task&lt;compileATL&gt; defined in AtlCompilerTask.jar This task receives as input all references to those files ended with .atl suffix under the folder ATL and then starts their compilation, creating their equivalent .asm file. It's mandatory that AtlCompilerTask.jar exists just before executing the ant script, for this reason the project com.x.ant should always be compiled before any project that uses ATL.
 +
 
 +
*If you have any sort of dependency errors regarding ATL libraries, it's most likely that you need to update the MANIFEST.MF file with those missing libraries.
  
* If you have any sort of dependency errors regarding ATL libraries, it's most likely that you need to update the MANIFEST.MF file with those missing libraries.
+
Maven reads this file in order to figure out which jars should be downloaded from the local or remote repositories and then adds them to the project's classpath. For example your Manifest.MF may need:  
Maven reads this file in order to figure out which jars should be downloaded from the local or remote repositories and then adds them to the project's classpath.
+
For example your Manifest.MF may need:
+
  
 
  Require-Bundle: org.eclipse.ui,
 
  Require-Bundle: org.eclipse.ui,
 
  org.eclipse.core.runtime;bundle-version="3.4.0",
 
  org.eclipse.core.runtime;bundle-version="3.4.0",
 
  org.eclipse.core.resources;bundle-version="3.4.2",
 
  org.eclipse.core.resources;bundle-version="3.4.2",
com.ericsson.ecim.core;bundle-version="1.0.0",
 
 
  org.eclipse.m2m.atl.core.emf;bundle-version="3.2.1";visibility:=reexport,
 
  org.eclipse.m2m.atl.core.emf;bundle-version="3.2.1";visibility:=reexport,
 
  org.eclipse.m2m.atl;bundle-version="3.2.1",
 
  org.eclipse.m2m.atl;bundle-version="3.2.1",
Line 148: Line 164:
 
  org.eclipse.m2m.atl.profiler.ui;bundle-version="3.2.1",
 
  org.eclipse.m2m.atl.profiler.ui;bundle-version="3.2.1",
 
  org.eclipse.m2m.atl.profiler.vm;bundle-version="3.2.1"
 
  org.eclipse.m2m.atl.profiler.vm;bundle-version="3.2.1"
 +
<div style=""></div>
  
<div style="">
 
 
= See Also =
 
= See Also =
</div>
 
 
<div style="">
 
<div style="">
 
* [[ATL/User_Guide_-_Introduction | Introduction]]
 
* [[ATL/User_Guide_-_Introduction | Introduction]]

Latest revision as of 11:04, 26 July 2012

The Problem

Currently Maven doesn't provide any plugin to compile ATL files and given such limitations a workaround is necessary. A custom ANT task has been developed that receives .atl files as input and then compiles them into .asm files. The following instructions describe how to set up a project to compile ATL files.

ATL Compilation ANT Task

  • Create a new project to contain the ATL compilation ANT task
  • Create the ANT task using the following code:
package com.x.ant;
import java.io.File;
import java.io.FileInputStream; 
import java.util.Iterator;
import java.util.Vector;
import org.apache.tools.ant.BuildException; 
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.types.resources.FileResourceIterator;
import org.eclipse.m2m.atl.engine.compiler.atl2006.Atl2006Compiler;

public class AtlCompilerTask extends Task {
  private Atl2006Compiler compiler = new Atl2006Compiler();
      
  private Vector<FileSet> filesets = new Vector<FileSet>();

  public AtlCompilerTask() {
       Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  }

  public void addFileset(FileSet fileset) {
     filesets.add(fileset);
  }
      
     @Override
     public void execute() throws BuildException {
             try {
                     //iterate over all the FileSet(s) passed in from ANT
                     for(Iterator<FileSet> itFSets = filesets.iterator(); itFSets.hasNext();) 
                     {
                          //get a FileSet
                          FileSet fs = itFSets.next();
     
                          FileResourceIterator iter = (FileResourceIterator)fs.iterator();
                 
                          //loop over all the files in a given FileSet
                          while(iter.hasNext())
                          {
                             FileResource fr = (FileResource)iter.next();
                             File file = fr.getFile();
                     
                             //compile each ATL file suffixing it with .asm
                             compiler.compile(new FileInputStream(file),file.getAbsolutePath().replace(".atl", ".asm"));
                          }
                     } 
             }
             catch (Exception e) {
                     e.printStackTrace();
                     throw new BuildException("Exception while calling the ATL compiler task.", e);
             }
     }
}
  • Ensure you have all the ATL dependencies on your ANT builder classpath

ATL Compilation Maven Build

  • We assume the ANT task defined above exists in your workspace
  • Add a build procedure to the .pom file located in the project for which you wish to compile its .atl sources, as follows:


       <build>
            <plugins>
                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-antrun-plugin</artifactId>
                            <version>1.7</version>
                            <executions>
                                    <execution>
                                            <id>compile</id>
                                            <phase>compile</phase>
                                            <configuration>
                                                    <target>
                                                            <property name="com.x.ant.location" value="../com.x.ant" />
                                                            <property name="dependency-classpath" refid="maven.dependency.classpath" />
                                                            <echo message="Start ATL compilation" />
                                                            <echo message="Maven Dependencies: ${dependency-classpath}" />



                                                            <taskdef name="compileATL"
                                                                    classpath="${com.x.ant.location}/target/AtlCompilerTask.jar"
                                                                    classname="com.x.ant.AtlCompilerTask" classpathref="maven.dependency.classpath" />



                                                            <compileATL>
                                                                    <fileset dir="${basedir}/ATL" includes="**/*.atl" />
                                                            </compileATL>
                                                            <echo message="Done!" />
                                                    </target>
                                            </configuration>
                                            <goals>
                                                    <goal>run</goal>
                                            </goals>
                                    </execution>
                            </executions>
                    </plugin>
            </plugins>
    </build>
  • If not already done, add a reference to the ATL folder in your project's build.properties, so that all .atl and .asm files can be included inside the jar generated for that particular project module, as follows:
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
ATL/,\
plugin.properties

Some notes:

  • The build section is executed during compilation phase, invoking the task<compileATL> defined in AtlCompilerTask.jar This task receives as input all references to those files ended with .atl suffix under the folder ATL and then starts their compilation, creating their equivalent .asm file. It's mandatory that AtlCompilerTask.jar exists just before executing the ant script, for this reason the project com.x.ant should always be compiled before any project that uses ATL.
  • If you have any sort of dependency errors regarding ATL libraries, it's most likely that you need to update the MANIFEST.MF file with those missing libraries.

Maven reads this file in order to figure out which jars should be downloaded from the local or remote repositories and then adds them to the project's classpath. For example your Manifest.MF may need:

Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime;bundle-version="3.4.0",
org.eclipse.core.resources;bundle-version="3.4.2",
org.eclipse.m2m.atl.core.emf;bundle-version="3.2.1";visibility:=reexport,
org.eclipse.m2m.atl;bundle-version="3.2.1",
org.eclipse.m2m.atl.adt;bundle-version="3.2.1",
org.eclipse.m2m.atl.adt.debug;bundle-version="3.2.1",
org.eclipse.m2m.atl.adt.editor;bundle-version="3.2.1",
org.eclipse.m2m.atl.adt.ui;bundle-version="3.2.1",
org.eclipse.m2m.atl.cheatsheets;bundle-version="3.2.1",
org.eclipse.m2m.atl.common;bundle-version="3.2.1",
org.eclipse.m2m.atl.core.ant;bundle-version="3.2.1",
org.eclipse.m2m.atl.core.ui;bundle-version="3.2.1",
org.eclipse.m2m.atl.core.ui.vm;bundle-version="3.2.1",
org.eclipse.m2m.atl.debug.core;bundle-version="3.2.1",
org.eclipse.m2m.atl.doc;bundle-version="3.2.1",
org.eclipse.m2m.atl.drivers.emf4atl;bundle-version="3.2.1",
org.eclipse.m2m.atl.drivers.uml24atl;bundle-version="3.2.1",
org.eclipse.m2m.atl.dsls;bundle-version="3.2.1",
org.eclipse.m2m.atl.engine;bundle-version="3.2.1",
org.eclipse.m2m.atl.engine.emfvm;bundle-version="3.2.1",
org.eclipse.m2m.atl.engine.emfvm.launch;bundle-version="3.2.1",
org.eclipse.m2m.atl.engine.vm;bundle-version="3.2.1",
org.eclipse.m2m.atl.examples;bundle-version="3.2.1",
org.eclipse.m2m.atl.profiler.core;bundle-version="3.2.1",
org.eclipse.m2m.atl.profiler.emfvm;bundle-version="3.2.1",
org.eclipse.m2m.atl.profiler.exportmodel;bundle-version="3.2.1",
org.eclipse.m2m.atl.profiler.exportmodel.editor;bundle-version="3.2.1",
org.eclipse.m2m.atl.profiler.model;bundle-version="3.2.1",
org.eclipse.m2m.atl.profiler.ui;bundle-version="3.2.1",
org.eclipse.m2m.atl.profiler.vm;bundle-version="3.2.1"

See Also