<!DOCTYPE html> | |
<html lang="en"> | |
<!-- | |
/******************************************************************************** | |
** Copyright (c) 2012 Obeo. | |
** All rights reserved. This program and the accompanying materials | |
** are made available under the terms of the Eclipse Public License v1.0 | |
** which accompanies this distribution, and is available at | |
** http://www.eclipse.org/legal/epl-v10.html | |
** | |
** Contributors: | |
** Stephane Begaudeau (Obeo) - initial API and implementation | |
*********************************************************************************/ | |
--> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta name="description" content=""> | |
<meta name="author" content="Stéphane Bégaudeau"> | |
<!-- IE6-8 support of HTML elements --> | |
<!--[if lt IE 9]> | |
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
<link href="../../assets/css/bootstrap.css" rel="stylesheet"> | |
<link href="../../assets/css/docs.css" rel="stylesheet"> | |
<title>Acceleo</title> | |
</head> | |
<body> | |
<div class="container"> | |
<section id="introduction"> | |
<div class="page-header"> | |
<h1>Introduction <small>let's move out of Eclipse</small></h1> | |
</div> | |
<p> | |
Acceleo can run inside of Eclipse but you may want to to use your Acceleo generator out of your IDE to embed it | |
inside of another application for example. Acceleo let you compile and run your generator in stand alone | |
(AKA out of Eclipse) very easily. | |
</p> | |
<br /> | |
</section> | |
<section id="compilation"> | |
<div class="page-header"> | |
<h1>Compilation <small>build your generator!</small></h1> | |
</div> | |
<p> | |
In order to compile your Acceleo generator, you can use the maven plug-in or or can do it programmatically. | |
</p> | |
<h2>Programmatically</h2> | |
<p> | |
You can use the Java class, org.eclipse.acceleo.internal.parser.compiler.AcceleoParser to launch the compilation | |
programmatically, its use being straightforward, it is not explained here. You just need to instantiate an | |
AcceleoProject and then you need to call "buildAll(new BasicMonitor())". | |
</p> | |
<h2>Maven</h2> | |
<p> | |
The Acceleo Maven integration is will evolve independently of the releases of Acceleo, has such, it is recommended | |
to check the Acceleo wiki for an up to date documentation on the subject: <a href="http://wiki.eclipse.org/Acceleo/Maven">http://wiki.eclipse.org/Acceleo/Maven</a>. | |
</p> | |
<p> | |
An action is available by right clicking on an Acceleo generator and selecting "Configure" and then "Generate pom.xml" to generate | |
the skeleton of the pom.xml files necessary for the build. Some changes need to be done manually in order to have a valid build | |
since some information cannot be computed by Acceleo. | |
</p> | |
<br /> | |
<br /> | |
</section> | |
<section id="Run"> | |
<div class="page-header"> | |
<h1>Run <small>launch your generator out of Eclipse</small></h1> | |
</div> | |
<p> | |
An Acceleo generator can be launched from any J2SE-1.5+ application. | |
</p> | |
<h2>Registration</h2> | |
<p> | |
If you want to use your generator out of Eclipse, first you need to make sure that all the necessary elements are | |
registered. There are two kinds of elements that need to be registered: | |
</p> | |
<ul> | |
<li>EMF packages</li> | |
<li>EMF resources factories</li> | |
</ul> | |
<h3>Package registration</h3> | |
<p> | |
You need to register the package that contains your classifiers, in order to use it inside of your generator. | |
To do this, have a look at the method named "registerPackages" in the Java launcher generated next to your main | |
module. You need to add the following piece of code: | |
</p> | |
<pre> | |
/** | |
* @generated NOT | |
*/ | |
public void registerPackages(ResourceSet resourceSet) { | |
super.registerPackages(resourceSet); | |
if (!isInWorkspace(MyPackage.class)) { | |
resourceSet.getPackageRegistry().put(MyPackage.eINSTANCE.getNsURI(), MyPackage.eINSTANCE); | |
} | |
} | |
</pre> | |
<p> | |
The "@generated NOT" tag in the Javadoc is necessary to prevent the removal of your modification. Once the package | |
is registered, Acceleo can use EMF to load your input model. If this does not work, you will see an error message | |
stating that EMF cannot find the package with the uri "<metamodel_uri>". | |
</p> | |
<h3>Resource Factory registration</h3> | |
<p> | |
Acceleo also needs to have a resource factory in order to load your model. By default, Acceleo knows how to load | |
".xmi" files but if you are using models with a different extension, for example ".uml", you need to tell Acceleo | |
how to read those files. In order to do that, you need to have a look at the method named "registerResourceFactories" | |
in the Java launcher to add the following piece of code for your meta-model. The following example is necessary for | |
the use in stand alone of ".uml" models. | |
</p> | |
<pre> | |
/** | |
* @generated NOT | |
*/ | |
@Override | |
public void registerResourceFactories(ResourceSet resourceSet) { | |
super.registerResourceFactories(resourceSet); | |
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, | |
UMLResource.Factory.INSTANCE); | |
} | |
</pre> | |
<p> | |
Most of the time, you can use the following code, since EMF models are using by default the XMI resource | |
serialization: | |
</p> | |
<pre> | |
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("myextension", new XMIResourceFactoryImpl()); | |
</pre> | |
<h2>Dependencies</h2> | |
<p> | |
Here is the list of the dependencies that you need to have in your build-path to run an Acceleo generator out | |
of Eclipse: | |
</p> | |
<ul> | |
<li>lpg.runtime.java (version 2.0+)</li> | |
<li>org.eclipse.ocl (version 3.1.0+)</li> | |
<li>org.eclipse.ocl.ecore (version 3.1.1+)</li> | |
<li>org.eclipse.emf.common (version 2.7.0+)</li> | |
<li>org.eclipse.emf.ecore (version 2.7.0+)</li> | |
<li>org.eclipse.emf.ecore.xmi (version 2.7.0+)</li> | |
<li>org.eclipse.equinox.common (version 3.6.0+)</li> | |
<li>org.eclipse.core.contenttype (version 3.4.100+)</li> | |
<li>com.google.guava (version 10.0.1)</li> | |
</ul> | |
<p> | |
Those jars can be found in the plug-ins folder of your Eclipse installation. And you need the following Acceleo components: | |
</p> | |
<ul> | |
<li>org.eclipse.acceleo.common</li> | |
<li>org.eclipse.acceleo.engine</li> | |
<li>org.eclipse.acceleo.model</li> | |
<li>org.eclipse.acceleo.profiler</li> | |
</ul> | |
<p> | |
On top of those jars, you will also need the jar of your generator (you can obtain it by right clicking on it | |
and selecting "Export..." and then in the "Plug-In Development" category choose "Deployable Plug-In and Fragment"). | |
You can also build it thanks to maven. You will also need the jar of the meta-models that your generator are using and | |
their dependencies. For example, for the UML to Java example available in Acceleo (File -> New -> | |
Example -> Acceleo Model to Text -> UML to Java): | |
</p> | |
<ul> | |
<li>org.eclipse.acceleo.module.example.uml2java.helios (generator)</li> | |
<li>org.eclipse.uml2.common (a dependency of the UML meta-model)</li> | |
<li>org.eclipse.uml2.uml (the meta-model)</li> | |
</ul> | |
<h2>Run</h2> | |
<p> | |
In order to launch your generator, you need to instantiate it, to give it the URI of your model and the output folder | |
where the code will be generated. | |
</p> | |
<pre> | |
String path = "C:Users/anUser/Desktop/generators/uml2java/model/example.uml"; | |
URI modelURI = URI.createFileURI(URI.decode(path)); | |
File targetFolder = new File("C:Users/anUser/Desktop/generators/uml2java/result"); | |
GenerateJava generator = new GenerateJava(modelURI, targetFolder, new ArrayList<Object>()); | |
generator.doGenerate(new BasicMonitor()); | |
</pre> | |
<p> | |
In this example, "GenerateJava" is the Java launcher of our Acceleo generator. | |
</p> | |
<br /> | |
<br /> | |
</section> | |
<footer class="footer"> | |
<p> | |
The material in these guides are Copyright (c) 2008, 2012 Obeo. This material is available under the Eclipse Public License v1.0 | |
</p> | |
</footer> | |
</div> | |
</body> | |
</html> |