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"

(Java)
 
(6 intermediate revisions by one other user not shown)
Line 3: Line 3:
 
== Introduction ==
 
== 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.  
+
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 ==
 
== Environment ==
Line 9: Line 9:
 
=== Eclipse ===
 
=== 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 [http://www.eclipse.org/downloads/ 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.  
+
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 [http://www.eclipse.org/downloads/ 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 [http://download.eclipse.org/modeling/emft/texo/updates/interim update site] or by downloading the plugins directly from this [http://download.eclipse.org/modeling/emft/texo/updates/interim site] and placing the plugins in the dropins directory.
+
Then next install the Texo plugins within the downloaded Eclipse version. This can be done through the update manager using [http://download.eclipse.org/modeling/emft/texo/updates/interim update site] or by downloading the plugins directly from the [http://download.eclipse.org/modeling/emft/texo/updates/interim 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 by your build script.  
+
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 ===
 
=== 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:
+
Texo also needs a workspace and a java project for the code generation. These can also be created automatically by Texo during code generation.  
* 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 [[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]].  
+
  
But again: Texo can and will also generate the workspace and java project for you if you don't specify one.
+
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 [[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]].
  
 
=== Model files ===
 
=== Model files ===
Line 34: Line 34:
  
 
The java and ant headless generation both use the same 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 [[Texo/Generate_JPA-ORM_Introduction#Generating_JPA_annotated_model_code|JPA]] annotations
* Code generation parameters:
+
* dao: if this flag is present then also the [[Texo/Dao|dao]] layer is generated
** 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 [[Texo/Generate_JPA-ORM_Introduction#Generating_JPA_annotated_model_code|generated code]] will have JPA annotations
+
** dao: if this flag is present then also the [[Texo/Dao|dao]] layer is generated
+
  
 
=== Java ===
 
=== Java ===
Line 52: Line 48:
 
-modelLocation /home/mtaal/mytmp/models -jpa -dao
 
-modelLocation /home/mtaal/mytmp/models -jpa -dao
 
</source>
 
</source>
Let's go through the different options and settings:
+
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 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 -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.
Line 59: Line 55:
 
The other parameters and flags correspond to the code generation parameters discussed in the previous section.
 
The other parameters and flags correspond to the code generation parameters discussed in the previous section.
  
=== Location of generated code ===
+
=== ANT ===
  
The generated code will be present within the project. As a default it will be present in the src-gen folder.
+
The Texo code generation can also be called from an ANT script. Within the Texo code base you can find an example ANT [http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/generator/org.eclipse.emf.texo.eclipse.generator/examples/texo-gen-macrodef.xml macrodefinition] and [http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/generator/org.eclipse.emf.texo.eclipse.generator/examples/build.xml build].
  
== Code generation: ant ==
+
The macro definition uses the same parameters as discussed in the previous section. In addition two other parameters are needed:
 +
* eclipse: the location of the Eclipse installation
 +
* data: the workspace location
  
 +
See the [http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/generator/org.eclipse.emf.texo.eclipse.generator/examples 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.
  
[[Image:org.eclipse.emf.texo.generate.code.png|center|600px]]
+
After code generation step you can let your build logic copy the source files to any suitable location for compilation.

Latest revision as of 15:49, 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.

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

The Texo code generation can also be called from an ANT script. 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 two other parameters are needed:

  • eclipse: the location of the Eclipse installation
  • data: the workspace location

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