Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Preferred way of using the ATL2006 compiler in Java program
[ATL] Preferred way of using the ATL2006 compiler in Java program [message #546649] Tue, 13 July 2010 16:20 Go to next message
Marten Sijtema is currently offline Marten SijtemaFriend
Messages: 67
Registered: November 2009
Member
Hello,

Since I still have problems with using the ATL compiler from a standalone java program my questions are the following:

1) Where can I get a proper version of the compiler.
2) Can I get a stand-alone (ie. outside eclipse) version?
3) Are there some examples on how to call this from Java?

Answering one of these questions can already tremendously help me.


My company: Sytematic, building business software from models.
Re: [ATL] Preferred way of using the ATL2006 compiler in Java program [message #546656 is a reply to message #546649] Tue, 13 July 2010 16:40 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
This is the code I use though it's not outside Eclipse so I don't know about the standalone mode.
We first inject the ATL file as an ATL Model using AtlParser and then AtlCompiler to get the ASM Model that we have to write to a file.
ByteArrayInputStream inputStream = new ByteArrayInputStream(yourATLString.getBytes());
EMFTCSInjector injector = new EMFTCSInjector();
Map params = new HashMap();
params.put("name","ATL");
params.put("indentString", " ");
params.put("identEsc", "\"");
params.put("stringDelim", "'");
params.put("serializeComments", "true");
EMFModel atlModel = null;
try {
	atlModel = factory.newModel((EMFReferenceModel) factory.getBuiltInResource("ATL.ecore"), "atlModel");
} catch (ATLCoreException e1) {
	e1.printStackTrace();
}
try {
	EMFReferenceModel problemMetaModel = (EMFReferenceModel) factory.getBuiltInResource("Problem.ecore");
	EMFModel problems = factory.newModel(problemMetaModel, "problemsModel");
	params.put("problems", problems);
	injector.inject(atlModel, inputStream, params);
	OutputStream source = new ByteArrayOutputStream();
	OutputStream result = new ByteArrayOutputStream();
	AtlParser parser = new AtlParser();
	parser.extract(atlModel, source, params);
	AtlCompiler.compile(new ByteArrayInputStream(source.toString().getBytes()), result);
	PrintWriter asmPrintWriter = new PrintWriter(location.substring(16, location.length())+"/transformation/"+model.getName()+"Copy.asm");
	ASM asm = new ASMXMLReader().read(new ByteArrayInputStream(result.toString().getBytes()));
	ASMXMLWriter txtWriter = new ASMXMLWriter(asmPrintWriter,false);
	txtWriter.print(asm);
	asmPrintWriter.flush();
	asmPrintWriter.close();
} catch(Exception e){
	e.printStackTrace();
}


Hope it helps
Re: [ATL] Preferred way of using the ATL2006 compiler in Java program [message #546658 is a reply to message #546656] Tue, 13 July 2010 16:44 Go to previous messageGo to next message
Marten Sijtema is currently offline Marten SijtemaFriend
Messages: 67
Registered: November 2009
Member
Thanks I give it a try. One more thing. Your factory variable, what does its declaration look like? Ie. what factory did you use?

Thanks in advance


My company: Sytematic, building business software from models.
Re: [ATL] Preferred way of using the ATL2006 compiler in Java program [message #546659 is a reply to message #546658] Tue, 13 July 2010 16:45 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
EMFModelFactory factory = new EMFModelFactory();
Re: [ATL] Preferred way of using the ATL2006 compiler in Java program [message #546660 is a reply to message #546659] Tue, 13 July 2010 16:49 Go to previous messageGo to next message
Marten Sijtema is currently offline Marten SijtemaFriend
Messages: 67
Registered: November 2009
Member
Could you also paste the relevant imports? Because if i press ctrl+shift+o (resolve imports) I can choose from different AtlParsers, each in a different package.

Then i can maybe see if the problem relies there...

Sorry to keep bothering:)


My company: Sytematic, building business software from models.
Re: [ATL] Preferred way of using the ATL2006 compiler in Java program [message #547000 is a reply to message #546649] Wed, 14 July 2010 22:03 Go to previous messageGo to next message
Marten Sijtema is currently offline Marten SijtemaFriend
Messages: 67
Registered: November 2009
Member
Matthias Bohlen, the author of Atl2006Compiler pointed me in the good direction, that differs a bit from the above used code:

import org.eclipse.m2m.atl.compilers.atl2006.Atl2006Compiler;
import org.eclipse.m2m.atl.engine.CompileTimeError;

public class YourCompilerClass
{
   /**
    * The file name of the ATL file to be compiled.
    *
    * @parameter expression="${andromda.atlcompiler.atlFileURL}"
    * @required
    */
   private URL    atlFileURL;

   /**
    * The file name of the compiled ASM file.
    *
    * @parameter expression="${andromda.atlcompiler.asmFilename}"
    * @required
    */
   private String asmFilename;

  public void executeCompiler()
  {
       getLog().info("atlFilename=" + atlFileURL);
       getLog().info("asmFilename=" + asmFilename);

       File outputFile = new File(this.asmFilename);
       outputFile.getParentFile().mkdirs();

       CompileTimeError[] compileTimeErrors = null;
       try
       {
           compileTimeErrors = new Atl2006Compiler().compile(this.atlFileURL.openStream(), this.asmFilename);
       }
       catch (IOException e)
       {
           throw new Exception("File to be compiled could not be found: " + this.atlFileURL, e);
       }

       if (compileTimeErrors.length > 0)
       {
           this.getLog().error("Errors when compiling " + atlFileURL);
           for (CompileTimeError error : compileTimeErrors)
           {
               this.getLog().error("    at " + error.getLocation() + " " + error.getDescription());
           }
           throw new Exception("compile time errors in ATL script");
       }

       this.getLog().info("ASM file written to '" + this.asmFilename + "'.");
  }
}



My company: Sytematic, building business software from models.
Re: [ATL] Preferred way of using the ATL2006 compiler in Java program [message #547001 is a reply to message #546649] Wed, 14 July 2010 22:06 Go to previous messageGo to next message
Marten Sijtema is currently offline Marten SijtemaFriend
Messages: 67
Registered: November 2009
Member
Matthias Bohlen, the author of Atl2006Compiler pointed me in the good direction, that differs a bit from the above used code:

import org.eclipse.m2m.atl.compilers.atl2006.Atl2006Compiler;
import org.eclipse.m2m.atl.engine.CompileTimeError;

public class YourCompilerClass
{
   /**
    * The file name of the ATL file to be compiled.
    *
    * @parameter expression="${andromda.atlcompiler.atlFileURL}"
    * @required
    */
   private URL    atlFileURL;

   /**
    * The file name of the compiled ASM file.
    *
    * @parameter expression="${andromda.atlcompiler.asmFilename}"
    * @required
    */
   private String asmFilename;

  public void executeCompiler()
  {
       getLog().info("atlFilename=" + atlFileURL);
       getLog().info("asmFilename=" + asmFilename);

       File outputFile = new File(this.asmFilename);
       outputFile.getParentFile().mkdirs();

       CompileTimeError[] compileTimeErrors = null;
       try
       {
           compileTimeErrors = new Atl2006Compiler().compile(this.atlFileURL.openStream(), this.asmFilename);
       }
       catch (IOException e)
       {
           throw new Exception("File to be compiled could not be found: " + this.atlFileURL, e);
       }

       if (compileTimeErrors.length > 0)
       {
           this.getLog().error("Errors when compiling " + atlFileURL);
           for (CompileTimeError error : compileTimeErrors)
           {
               this.getLog().error("    at " + error.getLocation() + " " + error.getDescription());
           }
           throw new Exception("compile time errors in ATL script");
       }

       this.getLog().info("ASM file written to '" + this.asmFilename + "'.");
  }
}



My company: Sytematic, building business software from models.
Re: [ATL] Preferred way of using the ATL2006 compiler in Java program [message #547626 is a reply to message #546649] Mon, 19 July 2010 08:05 Go to previous message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
a bit easier indeed Wink
Previous Topic:[QVTO] Accessing a EFeatureMapEntry
Next Topic:XML to xmi that confirms a metamodel ???
Goto Forum:
  


Current Time: Wed Nov 13 12:04:29 GMT 2024

Powered by FUDForum. Page generated in 0.03807 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top