Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Acceleo/Maven"

(first version of the maven page)
 
(Acceleo Equinox Launcher)
(48 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=Maven Integration=
+
= Compilation =
  
/!\ currently being written for the Eclipse 4.2 Juno release /!\
+
== Debug Messages ==
 +
Debug messages in Maven can be activated with a "-X" at the end of your maven command. For example to have the debug message of the clean operation, switch "mvn clean" to this "mvn clean -X".
 +
 
 +
== Maven Hosting ==
 +
The Acceleo artifacts and their stand alone dependencies are now hosted on repo.eclipse.org
 +
 
 +
== Releases Notes ==
 +
=== 2014/01/20 ===
 +
* The Acceleo artifacts are now hosted on repo.eclipse.org along with the maven plugin. They are now built as part of the Acceleo nightly build.
 +
* The artifactId of the maven plugin has been modified to org.eclipse.acceleo.maven to match all the other Acceleo artifacts
 +
* The hosting on raw.github.com is now deprecated!
 +
 
 +
===2012/09/7===
 +
* Fixing the possible ClassCastException with multiple generators built in a single maven build.
 +
* The build will now fail if there are errors.
 +
* A new property has been introduced to deactivate the failure on error. (<failOnError>false</failOnError>)
 +
 
 +
===2012/07/09===
 +
* The meta-model can now be resolved from the compilation dependencies and not only from the runtime dependencies. You can have the meta-model in a dependency resolved by Tycho and not only in one resolved by Maven
 +
* Improved debug messages
 +
 
 +
===2012/06/25===
 +
* Fix a bug for Mac OS X and Linux support of the build with dependencies inside jars
 +
* Improved debug messages
 +
 
 +
===2012/05/20===
 +
* First release
 +
 
 +
== Configuration ==
 +
The Acceleo maven plugin uses a configuration block to find the information about the project that should be compiled. Here is an example of this configuration for an UML generator.
 +
  <configuration>
 +
    <useBinaryResources>false</useBinaryResources>
 +
    <usePlatformResourcePath>true</usePlatformResourcePath>
 +
    <acceleoProject>
 +
      <root>${project.basedir}</root>
 +
      <entries>
 +
        <entry>
 +
          <input>src/main/java</input>
 +
          <output>target/classes</output>
 +
        </entry>
 +
      </entries>
 +
      <jars>
 +
        <jar>p2.eclipse-plugin:org.obeonetwork.pim.uml2.gen.java</jar>
 +
      </jars>
 +
    </acceleoProject>
 +
    <packagesToRegister>
 +
      <packageToRegister>org.eclipse.uml2.uml.UMLPackage</packageToRegister>
 +
    </packagesToRegister>
 +
    <uriHandler>org.eclipse.acceleo.maven.AcceleoURIHandler</uriHandler>
 +
    <failOnError>false</failOnError>
 +
  </configuration>
 +
 
 +
* <span style="font-weight:bold">useBinaryResource</span> - indicate that the advanced serialization should be used. The compiled modules produced are smaller but they are not as powerful to support complex URI use case (dynamic meta-models for example). This option should be at "false" by default.
 +
* <span style="font-weight:bold">usePlatformResourcePath</span> - indicate that absolute paths should be converted to "platform:/" relative paths. This option should be at "true" by default.
 +
* <span style="font-weight:bold">root</span> - The root of the project
 +
* <span style="font-weight:bold">entries</span> - Classpath entries for example "src" as the input and "bin" as the output.
 +
* <span style="font-weight:bold">jars</span> - The dependencies of the generator. Those dependencies can be defined using one of the following conventions
 +
** <span style="font-weight:bold">${project.basedir}\lib\myJar.jar</span> - A jar file located in the project.
 +
** <span style="font-weight:bold">p2.eclipse-plugin:org.eclipse.acceleo.anotherGenerator</span> - Another generator resolved thanks to Tycho.
 +
** <span style="font-weight:bold">p2.eclipse-plugin:org.eclipse.acceleo.anotherGenerator:1.0.0</span> - Another generator resolved thanks to Tycho limited to a specific version.
 +
** <span style="font-weight:bold">org.eclipse.acceleo:org.eclipse.acceleo.anotherGenerator</span> - Another generator resolved by maven.
 +
** <span style="font-weight:bold">org.eclipse.acceleo:org.eclipse.acceleo.anotherGenerator:1.0.0</span> - Another generator resolved by maven limited to a specific version.
 +
** <span style="font-weight:bold">org.eclipse.acceleo.anotherGenerator</span> - Another generator defined as a maven dependency.
 +
** <span style="font-weight:bold">org.eclipse.acceleo.anotherGenerator:1.0.0</span> - Another generator defined as a maven dependency with a restriction on a specific version.
 +
** <span style="font-weight:bold">C:\Users\MyName\...\myJar.jar</span> - The absolute path of a jar file.
 +
* <span style="font-weight:bold">packagesToRegister</span> - The name of the Java class that should be used to register the package on which the generation is launched.
 +
* <span style="font-weight:bold">uriHandler</span> - An AcceleoURIHandler used to convert the URI of the dependencies (if you want a different behavior than the usePlatformResourcePath). The default URI handler provided (org.eclipse.acceleo.maven.AcceleoURIHandler), does the same job as the option usePlatformResourcePath.
 +
* <span style="font-weight:bold">failOnError</span> - Indicates if the compilation should fail if errors are found (true by default).
 +
 
 +
== Stand Alone ==
 +
Launch this with the following command: mvn clean org.eclipse.acceleo:org.eclipse.acceleo.maven:3.5.0-SNAPSHOT:acceleo-compile compile verify
 +
 
 +
* example: http://git.eclipse.org/c/m2t/org.eclipse.acceleo.git/tree/tests/org.eclipse.acceleo.maven.tests
 +
* pom.xml: http://git.eclipse.org/c/m2t/org.eclipse.acceleo.git/tree/tests/org.eclipse.acceleo.maven.tests/pom.xml
 +
 
 +
The header of a regular maven pom.xml file.
 +
 
 +
  <project xmlns="http://maven.apache.org/POM/4.0.0"
 +
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 +
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 +
    <modelVersion>4.0.0</modelVersion>
 +
 
 +
The information of the project to build.
 +
 
 +
    <groupId>org.eclipse.acceleo</groupId>
 +
    <artifactId>org.eclipse.acceleo.maven-test</artifactId>
 +
    <version>3.5.0-SNAPSHOT</version>
 +
    <packaging>jar</packaging>
 +
    <name>org.eclipse.acceleo.maven.tests</name>
 +
    <description>The Acceleo maven tests plugin.</description>   
 +
 
 +
The repositories to use for the dependencies of this project (ex: org.eclipse.uml2.uml).
 +
    <repositories>
 +
      <repository>
 +
        <id>Eclipse - Acceleo Snapshots</id>
 +
        <url>https://repo.eclipse.org/content/repositories/acceleo-snapshots</url>
 +
      </repository>
 +
      <repository>
 +
        <id>Eclipse - Acceleo Release</id>
 +
        <url>https://repo.eclipse.org/content/repositories/acceleo-releases</url>
 +
      </repository>
 +
    </repositories>
 +
 
 +
The repositories where the plugin used during the build will be found (ex: org.eclipse.acceleo.maven).
 +
 
 +
    <pluginRepositories>
 +
      <pluginRepository>
 +
        <id>Eclipse - Acceleo Snapshots</id>
 +
        <url>https://repo.eclipse.org/content/repositories/acceleo-snapshots</url>
 +
      </pluginRepository>
 +
      <pluginRepository>
 +
        <id>Eclipse - Acceleo Release</id>
 +
        <url>https://repo.eclipse.org/content/repositories/acceleo-releases</url>
 +
      </pluginRepository>
 +
    </pluginRepositories>
 +
 
 +
The dependencies used to build. Here, the Acceleo maven plugin, the two plugins needed for the UML meta-model and log4j.
 +
 
 +
    <dependencies><span style="color:#1B9AF7">
 +
      <dependency>
 +
        <groupId>org.eclipse.acceleo</groupId>
 +
        <artifactId>org.eclipse.acceleo.maven</artifactId>
 +
        <version>3.5.0-SNAPSHOT</version>
 +
      </dependency>
 +
      <dependency>
 +
        <groupId>org.eclipse.acceleo</groupId>
 +
        <artifactId>org.eclipse.acceleo.engine</artifactId>
 +
        <version>3.5.0-SNAPSHOT</version>
 +
      </dependency>
 +
      <dependency>
 +
        <groupId>org.eclipse.uml2</groupId>
 +
        <artifactId>org.eclipse.uml2.uml</artifactId>
 +
        <version>4.1.1.v20130902-0826</version>
 +
      </dependency>
 +
      <dependency>
 +
        <groupId>org.eclipse.uml2</groupId>
 +
        <artifactId>org.eclipse.uml2.types</artifactId>
 +
        <version>1.1.0.v20130902-0826</version>
 +
      </dependency>
 +
      <dependency>
 +
        <groupId>org.eclipse.uml2</groupId>
 +
        <artifactId>org.eclipse.uml2.common</artifactId>
 +
        <version>1.8.1.v20130902-0826</version>
 +
      </dependency>
 +
      <dependency>
 +
        <groupId>org.slf4j</groupId>
 +
        <artifactId>slf4j-simple</artifactId>
 +
        <version>1.6.4</version>
 +
      </dependency></span>
 +
    </dependencies>
 +
 
 +
The configuration of the Acceleo build.
 +
 
 +
    <build>
 +
      <plugins>
 +
        <plugin>
 +
          <groupId>org.eclipse.acceleo</groupId>
 +
          <artifactId>org.eclipse.acceleo.maven</artifactId>
 +
          <version>3.5.0-SNAPSHOT</version>
 +
          <executions>
 +
            <execution>
 +
              <phase>compile</phase>
 +
            </execution>
 +
          </executions><span style="color:#1B9AF7">
 +
          <configuration>
 +
            <useBinaryResources>false</useBinaryResources>
 +
            <usePlatformResourcePath>true</usePlatformResourcePath>
 +
            <acceleoProject>
 +
              <root>${project.basedir}</root>
 +
              <entries>
 +
                <entry>
 +
                  <input>src/main/java</input>
 +
                  <output>target/classes</output>
 +
                </entry>
 +
              </entries>
 +
            </acceleoProject>
 +
            <packagesToRegister>
 +
              <packageToRegister>org.eclipse.uml2.uml.UMLPackage</packageToRegister>
 +
            </packagesToRegister>
 +
          </configuration></span>
 +
        </plugin>
 +
      </plugins>
 +
    </build>
 +
  </project>
 +
 
 +
== Maven Tycho build ==
 +
 
 +
Launch this with the following command: mvn clean org.eclipse.acceleo:org.eclipse.acceleo.maven:3.5.0-SNAPSHOT:acceleo-compile compile verify
 +
 
 +
* example: http://git.eclipse.org/c/m2t/org.eclipse.acceleo.git/tree/tests/org.eclipse.acceleo.maven.plugin.tests
 +
* pom.xml: http://git.eclipse.org/c/m2t/org.eclipse.acceleo.git/tree/tests/org.eclipse.acceleo.maven.plugin.tests/pom.xml
 +
 
 +
The following build only manages the compilation of an UML generator that is using another UML plugin as a dependency, for the support of features and update site have a look at Eclipse [[Minerva]].
 +
 
 +
The regular header of a Tycho based build.
 +
  <project xmlns="http://maven.apache.org/POM/4.0.0"
 +
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 +
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 +
   
 +
    <modelVersion>4.0.0</modelVersion>
 +
 
 +
The configuration of the plugin (the artifactId must match the name of the plugin).
 +
    <groupId>org.eclipse.acceleo</groupId>
 +
    <artifactId>org.eclipse.acceleo.maven.plugin.tests</artifactId>
 +
    <version>3.5.0-SNAPSHOT</version>
 +
    <packaging>eclipse-plugin</packaging>
 +
 
 +
The properties of the build
 +
 
 +
    <properties>
 +
      <tycho-version>0.14.1</tycho-version>
 +
    </properties>
 +
   
 +
    <profiles>
 +
      <profile>
 +
        <id>platform-indigo</id>
 +
        <activation>
 +
          <activeByDefault>true</activeByDefault>
 +
          <property>
 +
            <name>platform-version-name</name>
 +
            <value>indigo</value>
 +
          </property>
 +
        </activation>
 +
        <properties>
 +
          <uml-to-java-site>http://marketplace.obeonetwork.com/updates/od5/</uml-to-java-site>
 +
          <eclipse-site>http://download.eclipse.org/releases/indigo</eclipse-site>
 +
          <platform-version>[3.7,3.8)</platform-version>
 +
        </properties>
 +
      </profile>
 +
    </profiles>
 +
 
 +
Where to find the dependencies.
 +
    <repositories>
 +
      <repository>
 +
        <id>eclipse-platform</id>
 +
        <layout>p2</layout>
 +
        <url>${eclipse-site}</url>
 +
      </repository>
 +
      <repository>
 +
        <id>uml-to-java</id>
 +
        <layout>p2</layout>
 +
        <url>${uml-to-java-site}</url>
 +
      </repository>
 +
      <repository>
 +
        <id>Eclipse - Acceleo Snapshots</id>
 +
        <url>https://repo.eclipse.org/content/repositories/acceleo-snapshots</url>
 +
      </repository>
 +
      <repository>
 +
        <id>Eclipse - Acceleo Release</id>
 +
        <url>https://repo.eclipse.org/content/repositories/acceleo-releases</url>
 +
      </repository>
 +
    </repositories>
 +
 
 +
Where to find the maven plugin used during the build.
 +
    <pluginRepositories>
 +
      <pluginRepository>
 +
        <id>codehaus.snapshots</id>
 +
        <url>http://snapshots.repository.codehaus.org/</url>
 +
      </pluginRepository>
 +
      <pluginRepository>
 +
        <id>Eclipse - Acceleo Snapshots</id>
 +
        <url>https://repo.eclipse.org/content/repositories/acceleo-snapshots</url>
 +
      </pluginRepository>
 +
      <pluginRepository>
 +
        <id>Eclipse - Acceleo Release</id>
 +
        <url>https://repo.eclipse.org/content/repositories/acceleo-releases</url>
 +
      </pluginRepository>
 +
    </pluginRepositories>
 +
 
 +
The dependencies used.
 +
    <dependencies><span style="color:#1B9AF7">
 +
      <dependency>
 +
        <groupId>org.eclipse.acceleo</groupId>
 +
        <artifactId>org.eclipse.acceleo.maven</artifactId>
 +
        <version>3.5.0-SNAPSHOT</version>
 +
      </dependency>
 +
      <dependency>
 +
        <groupId>org.eclipse.acceleo</groupId>
 +
        <artifactId>org.eclipse.acceleo.engine</artifactId>
 +
        <version>3.5.0-SNAPSHOT</version>
 +
      </dependency>
 +
      <dependency>
 +
        <groupId>org.eclipse.uml2</groupId>
 +
        <artifactId>org.eclipse.uml2.uml</artifactId>
 +
        <version>4.1.1.v20130902-0826</version>
 +
      </dependency>
 +
      <dependency>
 +
        <groupId>org.eclipse.uml2</groupId>
 +
        <artifactId>org.eclipse.uml2.types</artifactId>
 +
        <version>1.1.0.v20130902-0826</version>
 +
      </dependency>
 +
      <dependency>
 +
        <groupId>org.eclipse.uml2</groupId>
 +
        <artifactId>org.eclipse.uml2.common</artifactId>
 +
        <version>1.8.1.v20130902-0826</version>
 +
      </dependency>
 +
      <dependency>
 +
        <groupId>org.slf4j</groupId>
 +
        <artifactId>slf4j-simple</artifactId>
 +
        <version>1.6.4</version>
 +
      </dependency>
 +
    </span></dependencies>
 +
 
 +
The configuration of the build. You can see here that we are building this generator while using another existing generator as a dependency. This generator is, here, found by Tycho thanks to the update site define above in the "repositories" section.
 +
    <build>
 +
      <plugins>
 +
        <plugin>
 +
          <groupId>org.eclipse.tycho</groupId>
 +
          <artifactId>tycho-maven-plugin</artifactId>
 +
          <version>${tycho-version}</version>
 +
          <extensions>true</extensions>
 +
        </plugin>
 +
        <plugin>
 +
          <groupId>org.eclipse.tycho</groupId>
 +
          <artifactId>target-platform-configuration</artifactId>
 +
          <version>${tycho-version}</version>
 +
          <configuration>
 +
            <resolver>p2</resolver>
 +
            <pomDependencies>consider</pomDependencies>
 +
          </configuration>
 +
        </plugin>
 +
        <plugin>
 +
          <groupId>org.eclipse.acceleo</groupId>
 +
          <artifactId>org.eclipse.acceleo.maven</artifactId>
 +
          <version>3.5.0-SNAPSHOT</version>
 +
          <executions>
 +
            <execution>
 +
              <phase>compile</phase>
 +
            </execution>
 +
          </executions><span style="color:#1B9AF7">
 +
          <configuration>
 +
            <useBinaryResources>false</useBinaryResources>
 +
            <usePlatformResourcePath>true</usePlatformResourcePath>
 +
            <acceleoProject>
 +
              <root>${project.basedir}</root>
 +
              <entries>
 +
                <entry>
 +
                  <input>src/main/java</input>
 +
                  <output>target/classes</output>
 +
                </entry>
 +
              </entries>
 +
              <jars>
 +
                <jar>p2.eclipse-plugin:org.obeonetwork.pim.uml2.gen.java</jar>
 +
              </jars>
 +
            </acceleoProject>
 +
            <packagesToRegister>
 +
              <packageToRegister>org.eclipse.uml2.uml.UMLPackage</packageToRegister>
 +
            </packagesToRegister>
 +
            <uriHandler>org.eclipse.acceleo.maven.AcceleoURIHandler</uriHandler>
 +
          </configuration></span>
 +
        </plugin>
 +
      </plugins>
 +
      <pluginManagement>
 +
        <plugins>
 +
          <plugin>
 +
            <groupId>org.eclipse.tycho</groupId>
 +
            <artifactId>tycho-compiler-plugin</artifactId>
 +
            <version>${tycho-version}</version>
 +
            <configuration>
 +
              <encoding>UTF-8</encoding>
 +
            </configuration>
 +
          </plugin>
 +
          <plugin>
 +
            <!-- TODO remove workaround when https://issues.sonatype.org/browse/TYCHO-473 is fixed -->
 +
            <groupId>org.eclipse.tycho</groupId>
 +
            <artifactId>tycho-source-plugin</artifactId>
 +
            <version>${tycho-version}</version>
 +
            <executions>
 +
              <execution>
 +
                <id>attach-source</id>
 +
                <phase>process-classes</phase>
 +
                <goals>
 +
                  <goal>plugin-source</goal>
 +
                </goals>
 +
              </execution>
 +
            </executions>
 +
          </plugin>
 +
          <plugin>
 +
            <groupId>org.apache.maven.plugins</groupId>
 +
            <artifactId>maven-resources-plugin</artifactId>
 +
            <version>2.4.1</version>
 +
            <configuration>
 +
              <encoding>ISO-8859-1</encoding>
 +
            </configuration>
 +
          </plugin>
 +
          <plugin>
 +
            <groupId>org.apache.maven.plugins</groupId>
 +
            <artifactId>maven-antrun-plugin</artifactId>
 +
            <version>1.3</version>
 +
          </plugin>
 +
        </plugins>
 +
      </pluginManagement>
 +
    </build>
 +
  </project>
 +
 
 +
== Plugin Management (parent and children pom.xml) ==
 +
In order to support a complex maven architecture with a parent pom.xml and children pom.xml, you should declare in the parent pom.xml the following code
 +
  <build><span style="color:#1B9AF7">
 +
    <pluginManagement>
 +
      <plugins>
 +
        <plugin>
 +
          <groupId>org.eclipse.acceleo</groupId>
 +
        <artifactId>org.eclipse.acceleo.maven</artifactId>
 +
        <version>3.5.0-SNAPSHOT</version>
 +
          <executions>
 +
            <execution>
 +
              <id>acceleo-compile</id>
 +
              <phase>compile</phase>
 +
              <goals>
 +
                <goal>acceleo-compile</goal>
 +
              </goals>
 +
            </execution>
 +
          </executions>
 +
        </plugin>
 +
      </plugins>
 +
    </pluginManagement></span>
 +
  </build>
 +
 
 +
And in the children, the Acceleo configuration, like this
 +
 
 +
  <build>
 +
    <plugins>
 +
      <plugin>
 +
        <groupId>org.eclipse.acceleo</groupId>
 +
        <artifactId>org.eclipse.acceleo.maven</artifactId>
 +
        <version>3.5.0-SNAPSHOT</version>
 +
        <executions><span style="color:#1B9AF7">
 +
          <execution>
 +
            <phase>compile</phase>
 +
            <goals>
 +
              <goal>acceleo-compile</goal>
 +
            </goals>
 +
          </execution></span>
 +
        </executions>
 +
        <configuration>
 +
          <useBinaryResources>false</useBinaryResources>
 +
          <usePlatformResourcePath>true</usePlatformResourcePath>
 +
          <acceleoProject>
 +
            <root>${project.basedir}</root>
 +
            <entries>
 +
              <entry>
 +
                <input>src</input>
 +
                <output>target/classes</output>
 +
              </entry>
 +
            </entries>
 +
          </acceleoProject>
 +
          <packagesToRegister>
 +
            <packageToRegister>org.eclipse.emf.ecore.EcorePackage</packageToRegister>
 +
          </packagesToRegister>
 +
        </configuration>
 +
      </plugin>
 +
    </plugins>
 +
  </build>
 +
 
 +
The Acceleo compilation will be launch during the compilation phase without having to specify it in the maven command. It will work with a simple "mvn clean verify".
 +
 
 +
== Known Issues ==
 +
 
 +
=== Compatibility with EMF ===
 +
Acceleo uses the OCL meta-model, the OCL meta-model extends Ecore (bad idea), as a result, the serialization of emtl files depends on the serialization of Ecore.ecore. EMF 2.9 has changed the way ENamedElement without any name are serialized in XMI. As a result, Acceleo modules built with EMF 2.9+ can only be used on EMF 2.9+.
 +
 
 +
If you want to build your generators for EMF2.9+ use the maven plugin with the artifactId org.eclipse.acceleo.maven, otherwise use org.eclipse.acceleo.maven.compatibility
 +
 
 +
=== ClassCast Exception: XXXFactory cannot be casted into a XXXFactoryImpl ===
 +
It happens sometimes with complex dependencies between generators during a same build (if in the same build, you are building the metamodel and the generators), it should work anyway. Building the meta-model separately and resolving it with a Tycho based dependency and the location of the update site of the meta-model seems to fix this issue.
 +
 
 +
This issue should be fixed in the latest release.
 +
 
 +
=Execution=
 +
 
 +
Starting with Neon and and the version 3.6.4 Acceleo offers two different ways to launch a code generation as part of a Maven Build.
 +
1- a Maven plugin
 +
2- a Tycho application (since Neon): the Acceleo Equinox Launcher
 +
 
 +
The Maven plugin, but it can be hard to setup for the following reasons :
 +
* the generator (and all its dependencies) should be working in standalone -- which can prove to be difficult or impossible if at least one of the dependency is not supporting this.
 +
this requires explict registration of EPackages and Resource factories, technical details which uses are not necessarly aware of as this is done automatically in an OSGi/Equinox context
 +
* the generator has to be published itself in a Maven repository, which requires an infrastructure.
 +
 
 +
All these factors are especially relevant for our core user base which is fairly used to the Eclipse technologies, will generally distribute their generators alongside other tooling through p2 update-sites.
 +
 
 +
Since version 0.14, Tycho (which integrates Maven and Eclipse based technologies) provide a generic way to launch any Equinox application through the tycho-eclipserun-plugin. Tycho-eclipserun allow the definition of extra dependencies retrieved through p2.
 +
We recommend the use of the Acceleo Launcher with Tycho 0.24+ as this version made the specification of application arguments more rebust to spurious line endings.
 +
 
 +
From a runtime point of view, the application is launched in an equinox runtime and as such every "auto-wiring" of the EPackages and Resource factories would work out of the box in the exact same way they works in Eclipse.
 +
 
 +
The Acceleo Equinox Launcher can be dynamically provisionned by Tycho using a simple pom.xml and configured to:
 +
* import projects in the workspace
 +
* launch an Acceleo generator based on its qualified class name
 +
* specify generation parameters as part of the pom.xml
 +
* starts a .launch file
 +
* starts the Java codegen from the EMF core project.
 +
 
 +
'''Which one should I use ?'''
 +
 
 +
If the generator (and his dependencies) has been carefully designed to work as a standalone Java Application and setting up a Maven repository is common practice in your organization, then the Maven plugin might be the best option.
 +
If the generator dependencies are fairly complex, might include eclipse technologies and/or your organization is used to deliver software using Eclipse update sites, then the Acceleo Equinox Launcher is the best option.
 +
If you don't know, the Acceleo Equinox Launcher is also the best option.
 +
 
 +
== Acceleo Equinox Launcher ==
 +
 
 +
The [https://github.com/cbrun/acceleo-launcher-examples following repository] contains documentation and executable examples of use of the Acceleo Equinox Launcher.
 +
 
 +
Here is an example pom.xml to launch a UML to embedded C code generation as part of a Maven build.
 +
 
 +
  ...
 +
  <plugin>
 +
        <groupId>org.eclipse.tycho.extras</groupId>
 +
        <artifactId>tycho-eclipserun-plugin</artifactId>
 +
        <version>${tycho-version}</version>
 +
        <configuration>
 +
          <repositories>
 +
            <repository>
 +
              <id>Neon update site </id>
 +
              <layout>p2</layout>
 +
              <url>http://download.eclipse.org/releases/neon/</url>
 +
            </repository>
 +
            <repository>
 +
              <id>UML 2 Embedded C Generator</id>
 +
              <layout>p2</layout>
 +
              <url>http://download.eclipse.org/umlgen/updates/nightly/latest/mars</url>
 +
            </repository>
 +
          </repositories>
 +
          <applicationsArgs>
 +
            <args>-consoleLog</args>
 +
            <args>-application</args>
 +
            <args>org.eclipse.acceleo.equinox.AcceleoLauncher</args>
 +
            <args>-data</args>
 +
            <args>${project.build.directory}/wks</args>
 +
            <args>-models</args>
 +
            <args>https://git.eclipse.org/c/umlgen/org.eclipse.umlgen.git/plain/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/models/NonRegressionModel.uml</args>
 +
            <args>-output</args>
 +
            <args>./src-gen</args>
 +
            <args>-actions</args>
 +
            <args>generate:org.eclipse.umlgen.gen.embedded.c/org.eclipse.umlgen.gen.embedded.c.main.Uml2ec</args>
 +
          </applicationsArgs>         
 +
          <dependencies>
 +
            <!-- We need the actual launcher application -->
 +
            <dependency>
 +
              <artifactId>org.eclipse.acceleo.equinox.launcher</artifactId>
 +
              <type>eclipse-plugin</type>
 +
            </dependency>
 +
            <!-- The Eclipse feature packaging the code generator. -->
 +
            <dependency>
 +
              <artifactId>org.eclipse.umlgen.gen.embedded.c</artifactId>
 +
              <type>eclipse-plugin</type>
 +
            </dependency>
 +
            <dependency>
 +
              <artifactId>org.eclipse.umlgen.gen.embedded.c.profile</artifactId>
 +
              <type>eclipse-plugin</type>
 +
            </dependency>
 +
          </dependencies>
 +
        </configuration>
 +
        <executions>
 +
          <execution>
 +
            <goals>
 +
              <goal>eclipse-run</goal>
 +
            </goals>
 +
            <phase>generate-sources</phase>
 +
          </execution>
 +
        </executions>
 +
      </plugin>
 +
  ...
 +
 
 +
== Maven Plugin ==
 +
A maven plugin is available to launch an Acceleo generator. Here is an example of the use of this plugin:
 +
 
 +
  <?xml version="1.0" encoding="UTF-8"?>
 +
  <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
 +
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 +
    <modelVersion>4.0.0</modelVersion>
 +
 
 +
    <groupId>org.eclipse.acceleo</groupId>
 +
    <artifactId>generated</artifactId>
 +
    <version>1.0.0-SNAPSHOT</version>
 +
    <packaging>eclipse-plugin</packaging>
 +
 
 +
    <build>
 +
      <plugins><span style="color:#1B9AF7">
 +
        <plugin>
 +
          <groupId>org.eclipse.acceleo</groupId>
 +
          <artifactId>org.eclipse.acceleo.maven.launcher</artifactId>
 +
          <version>3.5.0-SNAPSHOT</version>
 +
          <executions>
 +
            <execution>
 +
              <phase>process-resources</phase>
 +
              <goals>
 +
                <goal>acceleo-launcher</goal>
 +
              </goals>
 +
            </execution>
 +
          </executions>
 +
          <configuration>
 +
            <generatorClass>org.eclipse.acceleo.module.sample.main.Generate</generatorClass>
 +
            <model>${basedir}/model/My.ecore</model>
 +
            <outputFolder>${basedir}/src</outputFolder>
 +
          </configuration>
 +
          <dependencies> <!-- The generator that we will use -->
 +
            <dependency>
 +
              <groupId>org.eclipse.acceleo</groupId>
 +
              <artifactId>org.eclipse.acceleo.module.sample</artifactId>
 +
              <version>1.0.0-SNAPSHOT</version>
 +
            </dependency>
 +
          </dependencies>
 +
        </plugin></span>
 +
      </plugins>
 +
    </build>
 +
  </project>
 +
 
 +
In order to launch this execution, you can use the following command:
 +
 
 +
  mvn clean verify org.eclipse.acceleo:org.eclipse.acceleo.maven.launcher:3.5.0-SNAPSHOT:acceleo-launcher
 +
 
 +
You can also plug it directly in the build by adding the following content to the parent pom.xml:
 +
  <build><span style="color:#1B9AF7">
 +
    <pluginManagement>
 +
      <plugins>
 +
        <plugin>
 +
          <groupId>org.eclipse.acceleo</groupId>
 +
        <artifactId>org.eclipse.acceleo.maven.launcher</artifactId>
 +
        <version>3.5.0-SNAPSHOT</version>
 +
          <executions>
 +
            <execution>
 +
              <id>acceleo-launcher</id>
 +
              <phase>process-resources</phase>
 +
              <goals>
 +
                <goal>acceleo-launcher</goal>
 +
              </goals>
 +
            </execution>
 +
          </executions>
 +
        </plugin>
 +
      </plugins>
 +
    </pluginManagement></span>
 +
  </build>
 +
 
 +
Once plugged into the build, you can just call mvn clean verify on the parent's pom.xml and the generation will be triggered during the maven build. This launcher maven plugin has also been added to the build and it is available from https://repo.eclipse.org/index.html in the acceleo-snapshots repository. A "compatibility" version of the plugin, using EMF 2.8.3 is also available with the artifactId "org.eclipse.acceleo.maven.launcher.compatibility".

Revision as of 08:49, 22 June 2016

Compilation

Debug Messages

Debug messages in Maven can be activated with a "-X" at the end of your maven command. For example to have the debug message of the clean operation, switch "mvn clean" to this "mvn clean -X".

Maven Hosting

The Acceleo artifacts and their stand alone dependencies are now hosted on repo.eclipse.org

Releases Notes

2014/01/20

  • The Acceleo artifacts are now hosted on repo.eclipse.org along with the maven plugin. They are now built as part of the Acceleo nightly build.
  • The artifactId of the maven plugin has been modified to org.eclipse.acceleo.maven to match all the other Acceleo artifacts
  • The hosting on raw.github.com is now deprecated!

2012/09/7

  • Fixing the possible ClassCastException with multiple generators built in a single maven build.
  • The build will now fail if there are errors.
  • A new property has been introduced to deactivate the failure on error. (<failOnError>false</failOnError>)

2012/07/09

  • The meta-model can now be resolved from the compilation dependencies and not only from the runtime dependencies. You can have the meta-model in a dependency resolved by Tycho and not only in one resolved by Maven
  • Improved debug messages

2012/06/25

  • Fix a bug for Mac OS X and Linux support of the build with dependencies inside jars
  • Improved debug messages

2012/05/20

  • First release

Configuration

The Acceleo maven plugin uses a configuration block to find the information about the project that should be compiled. Here is an example of this configuration for an UML generator.

 <configuration>
   <useBinaryResources>false</useBinaryResources>
   <usePlatformResourcePath>true</usePlatformResourcePath>
   <acceleoProject>
     <root>${project.basedir}</root>
     <entries>
       <entry>
         <input>src/main/java</input>
         <output>target/classes</output>
       </entry>
     </entries>
     <jars>
       <jar>p2.eclipse-plugin:org.obeonetwork.pim.uml2.gen.java</jar>
     </jars>
   </acceleoProject>
   <packagesToRegister>
     <packageToRegister>org.eclipse.uml2.uml.UMLPackage</packageToRegister>
   </packagesToRegister>
   <uriHandler>org.eclipse.acceleo.maven.AcceleoURIHandler</uriHandler>
   <failOnError>false</failOnError>
 </configuration>
  • useBinaryResource - indicate that the advanced serialization should be used. The compiled modules produced are smaller but they are not as powerful to support complex URI use case (dynamic meta-models for example). This option should be at "false" by default.
  • usePlatformResourcePath - indicate that absolute paths should be converted to "platform:/" relative paths. This option should be at "true" by default.
  • root - The root of the project
  • entries - Classpath entries for example "src" as the input and "bin" as the output.
  • jars - The dependencies of the generator. Those dependencies can be defined using one of the following conventions
    • ${project.basedir}\lib\myJar.jar - A jar file located in the project.
    • p2.eclipse-plugin:org.eclipse.acceleo.anotherGenerator - Another generator resolved thanks to Tycho.
    • p2.eclipse-plugin:org.eclipse.acceleo.anotherGenerator:1.0.0 - Another generator resolved thanks to Tycho limited to a specific version.
    • org.eclipse.acceleo:org.eclipse.acceleo.anotherGenerator - Another generator resolved by maven.
    • org.eclipse.acceleo:org.eclipse.acceleo.anotherGenerator:1.0.0 - Another generator resolved by maven limited to a specific version.
    • org.eclipse.acceleo.anotherGenerator - Another generator defined as a maven dependency.
    • org.eclipse.acceleo.anotherGenerator:1.0.0 - Another generator defined as a maven dependency with a restriction on a specific version.
    • C:\Users\MyName\...\myJar.jar - The absolute path of a jar file.
  • packagesToRegister - The name of the Java class that should be used to register the package on which the generation is launched.
  • uriHandler - An AcceleoURIHandler used to convert the URI of the dependencies (if you want a different behavior than the usePlatformResourcePath). The default URI handler provided (org.eclipse.acceleo.maven.AcceleoURIHandler), does the same job as the option usePlatformResourcePath.
  • failOnError - Indicates if the compilation should fail if errors are found (true by default).

Stand Alone

Launch this with the following command: mvn clean org.eclipse.acceleo:org.eclipse.acceleo.maven:3.5.0-SNAPSHOT:acceleo-compile compile verify

The header of a regular maven pom.xml file.

 <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>

The information of the project to build.

   <groupId>org.eclipse.acceleo</groupId>
   <artifactId>org.eclipse.acceleo.maven-test</artifactId>
   <version>3.5.0-SNAPSHOT</version>
   <packaging>jar</packaging>
   <name>org.eclipse.acceleo.maven.tests</name>
   <description>The Acceleo maven tests plugin.</description>    

The repositories to use for the dependencies of this project (ex: org.eclipse.uml2.uml).

   <repositories>
     <repository>
       <id>Eclipse - Acceleo Snapshots</id>
       <url>https://repo.eclipse.org/content/repositories/acceleo-snapshots</url>
     </repository>
     <repository>
       <id>Eclipse - Acceleo Release</id>
       <url>https://repo.eclipse.org/content/repositories/acceleo-releases</url>
     </repository>
   </repositories>

The repositories where the plugin used during the build will be found (ex: org.eclipse.acceleo.maven).

   <pluginRepositories>
     <pluginRepository>
       <id>Eclipse - Acceleo Snapshots</id>
       <url>https://repo.eclipse.org/content/repositories/acceleo-snapshots</url>
     </pluginRepository>
     <pluginRepository>
       <id>Eclipse - Acceleo Release</id>
       <url>https://repo.eclipse.org/content/repositories/acceleo-releases</url>
     </pluginRepository>
   </pluginRepositories>

The dependencies used to build. Here, the Acceleo maven plugin, the two plugins needed for the UML meta-model and log4j.

   <dependencies>
     <dependency>
       <groupId>org.eclipse.acceleo</groupId>
       <artifactId>org.eclipse.acceleo.maven</artifactId>
       <version>3.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.eclipse.acceleo</groupId>
       <artifactId>org.eclipse.acceleo.engine</artifactId>
       <version>3.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.eclipse.uml2</groupId>
       <artifactId>org.eclipse.uml2.uml</artifactId>
       <version>4.1.1.v20130902-0826</version>
     </dependency>
     <dependency>
       <groupId>org.eclipse.uml2</groupId>
       <artifactId>org.eclipse.uml2.types</artifactId>
       <version>1.1.0.v20130902-0826</version>
     </dependency>
     <dependency>
       <groupId>org.eclipse.uml2</groupId>
       <artifactId>org.eclipse.uml2.common</artifactId>
       <version>1.8.1.v20130902-0826</version>
     </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
       <version>1.6.4</version>
     </dependency>
   </dependencies>

The configuration of the Acceleo build.

   <build>
     <plugins>
       <plugin>
         <groupId>org.eclipse.acceleo</groupId>
         <artifactId>org.eclipse.acceleo.maven</artifactId>
         <version>3.5.0-SNAPSHOT</version>
         <executions>
           <execution>
             <phase>compile</phase>
           </execution>
         </executions>
         <configuration>
           <useBinaryResources>false</useBinaryResources>
           <usePlatformResourcePath>true</usePlatformResourcePath>
           <acceleoProject>
             <root>${project.basedir}</root>
             <entries>
               <entry>
                 <input>src/main/java</input>
                 <output>target/classes</output>
               </entry>
             </entries>
           </acceleoProject>
           <packagesToRegister>
             <packageToRegister>org.eclipse.uml2.uml.UMLPackage</packageToRegister>
           </packagesToRegister>
         </configuration>
       </plugin>
     </plugins>
   </build>
 </project>

Maven Tycho build

Launch this with the following command: mvn clean org.eclipse.acceleo:org.eclipse.acceleo.maven:3.5.0-SNAPSHOT:acceleo-compile compile verify

The following build only manages the compilation of an UML generator that is using another UML plugin as a dependency, for the support of features and update site have a look at Eclipse Minerva.

The regular header of a Tycho based build.

 <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   
   <modelVersion>4.0.0</modelVersion>

The configuration of the plugin (the artifactId must match the name of the plugin).

   <groupId>org.eclipse.acceleo</groupId>
   <artifactId>org.eclipse.acceleo.maven.plugin.tests</artifactId>
   <version>3.5.0-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>

The properties of the build

   <properties>
     <tycho-version>0.14.1</tycho-version>
   </properties>
   
   <profiles>
     <profile>
       <id>platform-indigo</id>
       <activation>
         <activeByDefault>true</activeByDefault>
         <property>
           <name>platform-version-name</name>
           <value>indigo</value>
         </property>
       </activation>
       <properties>
         <uml-to-java-site>http://marketplace.obeonetwork.com/updates/od5/</uml-to-java-site>
         <eclipse-site>http://download.eclipse.org/releases/indigo</eclipse-site>
         <platform-version>[3.7,3.8)</platform-version>
       </properties>
     </profile>
   </profiles>

Where to find the dependencies.

   <repositories>
     <repository>
       <id>eclipse-platform</id>
       <layout>p2</layout>
       <url>${eclipse-site}</url>
     </repository>
     <repository>
       <id>uml-to-java</id>
       <layout>p2</layout>
       <url>${uml-to-java-site}</url>
     </repository>
     <repository>
       <id>Eclipse - Acceleo Snapshots</id>
       <url>https://repo.eclipse.org/content/repositories/acceleo-snapshots</url>
     </repository>
     <repository>
       <id>Eclipse - Acceleo Release</id>
       <url>https://repo.eclipse.org/content/repositories/acceleo-releases</url>
     </repository>
   </repositories>

Where to find the maven plugin used during the build.

   <pluginRepositories>
     <pluginRepository>
       <id>codehaus.snapshots</id>
       <url>http://snapshots.repository.codehaus.org/</url>
     </pluginRepository>
     <pluginRepository>
       <id>Eclipse - Acceleo Snapshots</id>
       <url>https://repo.eclipse.org/content/repositories/acceleo-snapshots</url>
     </pluginRepository>
     <pluginRepository>
       <id>Eclipse - Acceleo Release</id>
       <url>https://repo.eclipse.org/content/repositories/acceleo-releases</url>
     </pluginRepository>
   </pluginRepositories>

The dependencies used.

   <dependencies>
     <dependency>
       <groupId>org.eclipse.acceleo</groupId>
       <artifactId>org.eclipse.acceleo.maven</artifactId>
       <version>3.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.eclipse.acceleo</groupId>
       <artifactId>org.eclipse.acceleo.engine</artifactId>
       <version>3.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.eclipse.uml2</groupId>
       <artifactId>org.eclipse.uml2.uml</artifactId>
       <version>4.1.1.v20130902-0826</version>
     </dependency>
     <dependency>
       <groupId>org.eclipse.uml2</groupId>
       <artifactId>org.eclipse.uml2.types</artifactId>
       <version>1.1.0.v20130902-0826</version>
     </dependency>
     <dependency>
       <groupId>org.eclipse.uml2</groupId>
       <artifactId>org.eclipse.uml2.common</artifactId>
       <version>1.8.1.v20130902-0826</version>
     </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
       <version>1.6.4</version>
     </dependency>
   </dependencies>

The configuration of the build. You can see here that we are building this generator while using another existing generator as a dependency. This generator is, here, found by Tycho thanks to the update site define above in the "repositories" section.

   <build>
     <plugins>
       <plugin>
         <groupId>org.eclipse.tycho</groupId>
         <artifactId>tycho-maven-plugin</artifactId>
         <version>${tycho-version}</version>
         <extensions>true</extensions>
       </plugin>
       <plugin>
         <groupId>org.eclipse.tycho</groupId>
         <artifactId>target-platform-configuration</artifactId>
         <version>${tycho-version}</version>
         <configuration>
           <resolver>p2</resolver>
           <pomDependencies>consider</pomDependencies>
         </configuration>
       </plugin>
       <plugin>
         <groupId>org.eclipse.acceleo</groupId>
         <artifactId>org.eclipse.acceleo.maven</artifactId>
         <version>3.5.0-SNAPSHOT</version>
         <executions>
           <execution>
             <phase>compile</phase>
           </execution>
         </executions>
         <configuration>
           <useBinaryResources>false</useBinaryResources>
           <usePlatformResourcePath>true</usePlatformResourcePath>
           <acceleoProject>
             <root>${project.basedir}</root>
             <entries>
               <entry>
                 <input>src/main/java</input>
                 <output>target/classes</output>
               </entry>
             </entries>
             <jars>
               <jar>p2.eclipse-plugin:org.obeonetwork.pim.uml2.gen.java</jar>
             </jars>
           </acceleoProject>
           <packagesToRegister>
             <packageToRegister>org.eclipse.uml2.uml.UMLPackage</packageToRegister>
           </packagesToRegister>
           <uriHandler>org.eclipse.acceleo.maven.AcceleoURIHandler</uriHandler>
         </configuration>
       </plugin>
     </plugins>
     <pluginManagement>
       <plugins>
         <plugin>
           <groupId>org.eclipse.tycho</groupId>
           <artifactId>tycho-compiler-plugin</artifactId>
           <version>${tycho-version}</version>
           <configuration>
             <encoding>UTF-8</encoding>
           </configuration>
         </plugin>
         <plugin>
           <groupId>org.eclipse.tycho</groupId>
           <artifactId>tycho-source-plugin</artifactId>
           <version>${tycho-version}</version>
           <executions>
             <execution>
               <id>attach-source</id>
               <phase>process-classes</phase>
               <goals>
                 <goal>plugin-source</goal>
               </goals>
             </execution>
           </executions>
         </plugin>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-resources-plugin</artifactId>
           <version>2.4.1</version>
           <configuration>
             <encoding>ISO-8859-1</encoding>
           </configuration>
         </plugin>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-antrun-plugin</artifactId>
           <version>1.3</version>
         </plugin>
       </plugins>
     </pluginManagement>
   </build>
 </project>

Plugin Management (parent and children pom.xml)

In order to support a complex maven architecture with a parent pom.xml and children pom.xml, you should declare in the parent pom.xml the following code

 <build>
   <pluginManagement>
     <plugins>
       <plugin>
         <groupId>org.eclipse.acceleo</groupId>
        <artifactId>org.eclipse.acceleo.maven</artifactId>
        <version>3.5.0-SNAPSHOT</version>
         <executions>
           <execution>
             <id>acceleo-compile</id>
             <phase>compile</phase>
             <goals>
               <goal>acceleo-compile</goal>
             </goals>
           </execution>
         </executions>
       </plugin>
     </plugins>
   </pluginManagement>
 </build>

And in the children, the Acceleo configuration, like this

 <build>
   <plugins>
     <plugin>
       <groupId>org.eclipse.acceleo</groupId>
       <artifactId>org.eclipse.acceleo.maven</artifactId>
       <version>3.5.0-SNAPSHOT</version>
       <executions>
         <execution>
           <phase>compile</phase>
           <goals>
              <goal>acceleo-compile</goal>
            </goals>
         </execution>
       </executions>
       <configuration>
         <useBinaryResources>false</useBinaryResources>
         <usePlatformResourcePath>true</usePlatformResourcePath>
         <acceleoProject>
           <root>${project.basedir}</root>
           <entries>
             <entry>
               <input>src</input>
               <output>target/classes</output>
             </entry>
           </entries>
         </acceleoProject>
         <packagesToRegister>
           <packageToRegister>org.eclipse.emf.ecore.EcorePackage</packageToRegister>
         </packagesToRegister>
       </configuration>
     </plugin>
   </plugins>
 </build>

The Acceleo compilation will be launch during the compilation phase without having to specify it in the maven command. It will work with a simple "mvn clean verify".

Known Issues

Compatibility with EMF

Acceleo uses the OCL meta-model, the OCL meta-model extends Ecore (bad idea), as a result, the serialization of emtl files depends on the serialization of Ecore.ecore. EMF 2.9 has changed the way ENamedElement without any name are serialized in XMI. As a result, Acceleo modules built with EMF 2.9+ can only be used on EMF 2.9+.

If you want to build your generators for EMF2.9+ use the maven plugin with the artifactId org.eclipse.acceleo.maven, otherwise use org.eclipse.acceleo.maven.compatibility

ClassCast Exception: XXXFactory cannot be casted into a XXXFactoryImpl

It happens sometimes with complex dependencies between generators during a same build (if in the same build, you are building the metamodel and the generators), it should work anyway. Building the meta-model separately and resolving it with a Tycho based dependency and the location of the update site of the meta-model seems to fix this issue.

This issue should be fixed in the latest release.

Execution

Starting with Neon and and the version 3.6.4 Acceleo offers two different ways to launch a code generation as part of a Maven Build. 1- a Maven plugin 2- a Tycho application (since Neon): the Acceleo Equinox Launcher

The Maven plugin, but it can be hard to setup for the following reasons :

  • the generator (and all its dependencies) should be working in standalone -- which can prove to be difficult or impossible if at least one of the dependency is not supporting this.

this requires explict registration of EPackages and Resource factories, technical details which uses are not necessarly aware of as this is done automatically in an OSGi/Equinox context

  • the generator has to be published itself in a Maven repository, which requires an infrastructure.

All these factors are especially relevant for our core user base which is fairly used to the Eclipse technologies, will generally distribute their generators alongside other tooling through p2 update-sites.

Since version 0.14, Tycho (which integrates Maven and Eclipse based technologies) provide a generic way to launch any Equinox application through the tycho-eclipserun-plugin. Tycho-eclipserun allow the definition of extra dependencies retrieved through p2. We recommend the use of the Acceleo Launcher with Tycho 0.24+ as this version made the specification of application arguments more rebust to spurious line endings.

From a runtime point of view, the application is launched in an equinox runtime and as such every "auto-wiring" of the EPackages and Resource factories would work out of the box in the exact same way they works in Eclipse.

The Acceleo Equinox Launcher can be dynamically provisionned by Tycho using a simple pom.xml and configured to:

  • import projects in the workspace
  • launch an Acceleo generator based on its qualified class name
  • specify generation parameters as part of the pom.xml
  • starts a .launch file
  • starts the Java codegen from the EMF core project.

Which one should I use ?

If the generator (and his dependencies) has been carefully designed to work as a standalone Java Application and setting up a Maven repository is common practice in your organization, then the Maven plugin might be the best option. If the generator dependencies are fairly complex, might include eclipse technologies and/or your organization is used to deliver software using Eclipse update sites, then the Acceleo Equinox Launcher is the best option. If you don't know, the Acceleo Equinox Launcher is also the best option.

Acceleo Equinox Launcher

The following repository contains documentation and executable examples of use of the Acceleo Equinox Launcher.

Here is an example pom.xml to launch a UML to embedded C code generation as part of a Maven build.

 ...
 <plugin>
       <groupId>org.eclipse.tycho.extras</groupId>
       <artifactId>tycho-eclipserun-plugin</artifactId>
       <version>${tycho-version}</version>
       <configuration>
         <repositories>
           <repository>
             <id>Neon update site </id>
             <layout>p2</layout>
             <url>http://download.eclipse.org/releases/neon/</url>
           </repository>
           <repository>
             <id>UML 2 Embedded C Generator</id>
             <layout>p2</layout>
             <url>http://download.eclipse.org/umlgen/updates/nightly/latest/mars</url>
           </repository>
         </repositories>
         <applicationsArgs>
           <args>-consoleLog</args>
           <args>-application</args>
           <args>org.eclipse.acceleo.equinox.AcceleoLauncher</args>
           <args>-data</args>
           <args>${project.build.directory}/wks</args>
           <args>-models</args>
           <args>https://git.eclipse.org/c/umlgen/org.eclipse.umlgen.git/plain/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/models/NonRegressionModel.uml</args>
           <args>-output</args>
           <args>./src-gen</args>
           <args>-actions</args>
           <args>generate:org.eclipse.umlgen.gen.embedded.c/org.eclipse.umlgen.gen.embedded.c.main.Uml2ec</args>
         </applicationsArgs>          
         <dependencies>
           <dependency>
             <artifactId>org.eclipse.acceleo.equinox.launcher</artifactId>
             <type>eclipse-plugin</type>
           </dependency>
           <dependency>
             <artifactId>org.eclipse.umlgen.gen.embedded.c</artifactId>
             <type>eclipse-plugin</type>
           </dependency>
           <dependency>
             <artifactId>org.eclipse.umlgen.gen.embedded.c.profile</artifactId>
             <type>eclipse-plugin</type>
           </dependency>
         </dependencies>
       </configuration>
       <executions>
         <execution>
           <goals>
             <goal>eclipse-run</goal>
           </goals>
           <phase>generate-sources</phase>
         </execution>
       </executions>
     </plugin>
  ...

Maven Plugin

A maven plugin is available to launch an Acceleo generator. Here is an example of the use of this plugin:

 <?xml version="1.0" encoding="UTF-8"?>
 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <modelVersion>4.0.0</modelVersion>
 
   <groupId>org.eclipse.acceleo</groupId>
   <artifactId>generated</artifactId>
   <version>1.0.0-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 
   <build>
     <plugins>
        <plugin>
          <groupId>org.eclipse.acceleo</groupId>
          <artifactId>org.eclipse.acceleo.maven.launcher</artifactId>
          <version>3.5.0-SNAPSHOT</version>
          <executions>
            <execution>
              <phase>process-resources</phase>
              <goals>
                <goal>acceleo-launcher</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <generatorClass>org.eclipse.acceleo.module.sample.main.Generate</generatorClass>
            <model>${basedir}/model/My.ecore</model>
            <outputFolder>${basedir}/src</outputFolder>
          </configuration>
          <dependencies> 
            <dependency>
              <groupId>org.eclipse.acceleo</groupId>
              <artifactId>org.eclipse.acceleo.module.sample</artifactId>
              <version>1.0.0-SNAPSHOT</version>
            </dependency>
          </dependencies>
        </plugin>
     </plugins>
   </build>
 </project>

In order to launch this execution, you can use the following command:

 mvn clean verify org.eclipse.acceleo:org.eclipse.acceleo.maven.launcher:3.5.0-SNAPSHOT:acceleo-launcher

You can also plug it directly in the build by adding the following content to the parent pom.xml:

 <build>
   <pluginManagement>
     <plugins>
       <plugin>
         <groupId>org.eclipse.acceleo</groupId>
        <artifactId>org.eclipse.acceleo.maven.launcher</artifactId>
        <version>3.5.0-SNAPSHOT</version>
         <executions>
           <execution>
             <id>acceleo-launcher</id>
             <phase>process-resources</phase>
             <goals>
               <goal>acceleo-launcher</goal>
             </goals>
           </execution>
         </executions>
       </plugin>
     </plugins>
   </pluginManagement>
 </build>

Once plugged into the build, you can just call mvn clean verify on the parent's pom.xml and the generation will be triggered during the maven build. This launcher maven plugin has also been added to the build and it is available from https://repo.eclipse.org/index.html in the acceleo-snapshots repository. A "compatibility" version of the plugin, using EMF 2.8.3 is also available with the artifactId "org.eclipse.acceleo.maven.launcher.compatibility".

Back to the top