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

Texo/Integrate code generation in a build

< Texo
Revision as of 14:55, 21 October 2012 by Mtaal.springsite.com (Talk | contribs) (Headless Code generation)

Introduction

Texo code generation can be integrated quite easily within your build process. Texo needs Eclipse and a workspace to generate code because Texo uses Eclipse for code formatting and import resolving. This wiki page discusses how Texo can be run headless directly or using ant.

Environment

Eclipse

Texo needs Eclipse and a workspace to generate code. The Eclipse version needs the Texo plugins to be installed. To setup Eclipse choose one of the version from the Eclipse downloads page, for example the 'Eclipse IDE for Java Developers' can be used (it is the smallest). Choose the version which can run on the platform on which your build is being run.

Then next install the Texo plugins within the downloaded Eclipse version. This can be done through the update manager using update site or by downloading the plugins directly from this site and placing the plugins in the dropins directory.

Now you have an Eclipse ready to be used. Place the Eclipse version somewhere on your build server and keep track of the directory where it is placed. You can alternatively also zip/tar.gz it and unzip it during the build or other solutions. As long as during the build this Eclipse installation is available by your build script.

Workspace and Java Project

Texo also needs a workspace and a java project for the code generation. But these can also be created automatically by Texo during the code generation. Creating them up-fron gives the following advantages:

  • you have better control on the code formatting and import resolving used: if you prepare a workspace with a java project before you can define these formatting rules within that java project.
  • texo code generation settings: within the java project you can also set Texo related settings such as the output folder, the template directory for template overriding or ORM options.

But again: Texo can and will also generate the workspace and java project for you if you don't specify one.

Model files

Texo generates code on the basis of ecore and xsd files. Texo needs access to the model files for code generation. The easiest method is to have a directory with one or more of the model files for which you want to generate code.

Headless Code generation

Headless code generation can be done through java or through ant.

Parameters

The java and ant headless generation both use the same parameters:

  • projectName: the name of the project in which to generate code. This is an optional parameter, if not specified then Texo will create the org.eclipse.emf.texo.gen project in the workspace location.
  • modelLocation: mandatory parameter, is the location/directory where Texo can find the model files. Can be a directory or a full path to one specific file.
  • jpa: if this flag is present then the generated code will have JPA annotations
  • dao: if this flag is present then also the dao layer is generated

Java

To generate code through java in a headless mode, you can execute the following command:

java -cp eclipse/plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar org.eclipse.equinox.launcher.Main 
-nosplash -data /home/mtaal/mytmp/headless/workspace 
-application org.eclipse.emf.texo.eclipse.generator.TexoCodeGenerator -projectName testgen 
-modelLocation /home/mtaal/mytmp/models -jpa -dao

Let's go through the arguments in the java call:

  • the classpath points to the launcher jar file, the version number of this launcher jar file can differ, so you need to check in the Eclipse/plugins directory to see which value it is. The classpath path depends on where the above command is executed.
  • the -data option points to the workspace location. It can be a non-existing (new) location or an existing one. If it is new Texo/Eclipse will create a new workspace.
  • the -application argument tells Eclipse which program to run (in this case Texo code generation)

The other parameters and flags correspond to the code generation parameters discussed in the previous section.

ANT

Within the Texo code base you can find an example ANT macrodefinition and build.

The macro definition uses the same parameters as discussed in the previous section. In addition the location of the Eclipse installation has to be explicitly set. See the example ANT files as a reference.

Location of generated code

The generated code will be present within the project. As a default it will be present in the src-gen folder.

Code generation: ant

Org.eclipse.emf.texo.generate.code.png

Back to the top