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 "Texo/Integrate code generation in a build"

(Workspace and Java Project)
Line 17: Line 17:
 
=== Workspace and Java Project ===
 
=== Workspace and Java Project ===
  
Texo also needs a workspace and a java project for the code generation. These can also be created automatically by Texo during code generation. Creating them up-front gives the following advantages:
+
Texo also needs a workspace and a java project for the code generation. These can also be created automatically by Texo during code generation.  
 +
 
 +
Creating them up-front gives the following advantages:
 
* you have better control over code formatting and import resolving: if you prepare a workspace with a java project then you can define these formatting rules within that java project.
 
* you have better control over code formatting and import resolving: if you prepare a workspace with a java project then 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 [[Texo/Generate_Artifacts#Setting_the_output_folder|output folder]], the template directory for [[Texo/Template_Overriding|template overriding]] or [[Texo/ORM_JPA_Options|ORM options]].  
 
* texo code generation settings: within the java project you can also set Texo related settings such as the [[Texo/Generate_Artifacts#Setting_the_output_folder|output folder]], the template directory for [[Texo/Template_Overriding|template overriding]] or [[Texo/ORM_JPA_Options|ORM options]].  

Revision as of 15:06, 21 October 2012

Introduction

Texo code generation can be integrated quite easily within your build process. Texo uses Eclipse for code formatting and import resolving. This wiki page discusses how Texo can be run headless directly with java or using ANT.

Environment

Eclipse

Texo uses Eclipse and a workspace to generate code. The Texo plugins must be installed in the Eclipse version. 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 the update 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 for your build script.

Workspace and Java Project

Texo also needs a workspace and a java project for the code generation. These can also be created automatically by Texo during code generation.

Creating them up-front gives the following advantages:

  • you have better control over code formatting and import resolving: if you prepare a workspace with a java project then 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.

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 and the workspace location has to be defined. See the example ANT files as a reference.

Location of generated code

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

After code generation step you can let your build logic copy the source files to any suitable location for compilation.

Back to the top