Read acceleo-2.6-user-tutorial.pdf text version

ACCELEO User Tutorial

This handbook is the exclusive ownership of its authors and was conceded to the profit of Obeo SARL. This handbook is protected by intellectual ownership rights. It deals with a software product called ACCELEO, currently distributed under the open source Eclipse Public License (EPL). The distribution of this handbook is however not free. This handbook makes it possible to fully take advantage of the many advanced functionalities of ACCELEO software and required on behalf of its authors and of OBEO an important compilation and synthesis work, as well as consequent financial and time investments. Nevertheless, there may still be mistakes left in this document, OBEO shall not be held responsible for any resulting inconvenience. ACCELEO as well as the content of this document may be altered without prior notice. This document is not under Free license. This document can be downloaded without any fee from the OBEO website after proper registering. You may read and use it for any activity, commercial or not, related to ACCELEO. Yet permission of copying, translating or distributing freely or commercially this manual is subject to prior approval by OBEO. ____________________ "OBEO", "ACCELEO", as well as OBEO and ACCELEO logos are registered trademarks of Obeo in France and in other countries. All other names, titles, drawings, and logos are the exclusive ownership of their authors and are protected by intellectual ownership rights. This handbook was written with the following tools: OpenOffice ____________________ Authors: Jonathan MUSSET, Étienne JULIOT, Stéphane LACRAMPE With the participation of: Goulwen LE FUR, Julien DUPONT, Guillaume RAIMBAULT, Nathalie LEPINE, William PIERS, Cédric BRUN, and Laurent GOUBET Copyright 2006 2008 Obeo. All rights reserved.

Summary

1 - Introduction.......................................................................................................................1 1.1 - Minimum knowledge required...................................................................................1 1.2 - Documentation for Acceleo.......................................................................................1 2 - Installation.........................................................................................................................2 3 - Quick Startup....................................................................................................................3 3.1 - Import a Project into Eclipse.....................................................................................3 3.2 - Launch the Generation Chain...................................................................................5 4 - Modeling...........................................................................................................................7 4.1 - Definition....................................................................................................................7 4.2 - The Modelers.............................................................................................................8 4.2.1 - The UML2 Meta-Model with the EMF Modeler..................................................8 4.2.1.1 - Creating a Project.......................................................................................9 4.2.1.2 - Creating a UML2 Model............................................................................10 4.2.1.2.a - Creating a Package...........................................................................11 4.2.1.2.b - Creating a Class................................................................................12 4.2.1.2.c - Creating an Attribute..........................................................................12 4.2.1.2.d - Adding a Profile to a Model...............................................................13 4.2.1.2.e - Create an Association.......................................................................14 4.2.1.2.f - Validate the Model..............................................................................16 4.2.2 - Using the Example...........................................................................................16 4.2.2.1 - Importing a Project into Eclipse................................................................17 4.2.2.2 - Creating a Project " Dynamic Web Project "............................................19 4.2.2.3 - The model WebLog_fr.uml.......................................................................22 4.2.2.4 - Creating a Model......................................................................................23 5 - Initializing a Project.........................................................................................................26 5.1 - Importing Generation Modules................................................................................26 5.2 - Code Generation Files............................................................................................27 5.2.1 - Previewing the Results.....................................................................................27 5.2.1.1 - Synchronizing the Model Code.................................................................29 5.3 - Creating the Generation Chain...............................................................................30 5.3.1 - Creating a Generation Chain Using the Assistant...........................................30 5.3.2 - Creating a Generation Chain without the Assistant.........................................34 5.3.2.1 - Adding a Model.........................................................................................35 5.3.2.2 - Adding a Target Folder.............................................................................37 5.3.2.3 - Adding a Log.............................................................................................37 5.3.2.4 - Adding a Meta-Model...............................................................................38 5.3.2.5 - Adding the Generation File.......................................................................38

6 - Generation......................................................................................................................41 6.1 - Running a Generation Chain...................................................................................41 6.2 - Importing a Tomcat server......................................................................................42 6.2.1 - Importing the Tomcat Libraries........................................................................45 6.3 - Testing the Application............................................................................................47 7 - Parameters.....................................................................................................................49 7.1 - The Generation Chains...........................................................................................49 7.1.1 - Modifying a Generation Chain.........................................................................49 7.2 - The " logs "..............................................................................................................50 7.3 - The " Properties " Files............................................................................................51 7.3.1 - Creating a " Properties " File............................................................................51 8 - Update Management......................................................................................................54 8.1 - Manual Development..............................................................................................54 8.1.1 - Adding code to the servlets.............................................................................54 8.2 - Functional Updates.................................................................................................55 8.2.1 - Modification of the Input Model........................................................................55 8.2.1.1 - Modification of an Attribute.......................................................................55 8.2.1.2 - Adding a Class..........................................................................................56 8.2.1.3 - Deleting a Class........................................................................................57 8.2.1.4 - Renaming a class.....................................................................................58 8.2.1.5 - Adding/Modifying a Relationship (association / inheritance)...................58 8.3 - The " Lost " Files.....................................................................................................58 8.4 - Acceleo Traceability................................................................................................60 9 - Advanced Use................................................................................................................61 9.1 - Launching a Generation Chain Automatically from within Eclipse.........................61 10 - Additional Environments ..............................................................................................62 10.1 - Managing Different Versions.................................................................................62 10.1.1 - Sharing a New Project...................................................................................62 10.1.2 - Sharing Modifications.....................................................................................63 10.1.3 - Loading the Modifications from Another User...............................................63

Acceleo 2.6: User Tutorial

Page 1/62

1 - Introduction

This document is a detailed tutorial aimed at allowing users to master the code generator Acceleo, a product developed by Obeo. The functions dealt with will permit the creation of generation modules within projects, as well as management of products created using Acceleo over their life cycle. Acceleo is designed for people willing to profit from MDA technologies to increase their software development productivity. It allows the generation of files using UML, MOF, and EMF modules. This plug-in features: - - - - - - Complete integration with both the Eclipse environment and the EMF framework Code/model Synchronization Incremental generation Smooth adaptation for any industrial projects Ease of update and management of templates Syntax coloring, auto-completion and error detection

1.1 - Minimum knowledge required

The present guide does not intend to provide a training course for all of the issues addressed by the MDA or Acceleo. This guide assumes the readers has some knowledge in the fields of :

- - -

Java modeling (for example: UML) Eclipse

Knowledge of the following concepts would also be an advantage, but none is essential for the understanding of this document:

- - - -

meta-models UML2 meta-model development of Eclipse Plug-Ins MDA or MDD

1.2 - Documentation for Acceleo

This tutorial is part of a set offered by Obeo. Each document of this set deals with a different aspect of mastering Acceleo:

· · ·

Reference: description and explanation of each keyword of the Acceleo script syntax User Guide: documentation of Acceleo's functions Architectural Tutorial: guide for creating and personalizing generation modules.

Acceleo 2.6: User Tutorial

Page 2/62

2 - Installation

Acceleo is an open source project, licensed under the Eclipse Public License (EPL), it can be downloaded and used free of charge. The first step in installing Acceleo is then to download and install the Eclipse platform along with EMF. It is then possible to download and install Acceleo. Acceleo can be installed in a number of distinct ways. Each is specific to the manner your Eclipse platform has been installed. The recommended installation http://www.acceleo.org/update/. method is to make use of the following update site :

Each type of installation is detailed step-by-step in the User's Guide.

Acceleo 2.6: User Tutorial

Page 3/62

3 - Quick Startup

This section of the tutorial is designed for those who wish to directly execute the example provided on the Acceleo site: http://www.acceleo.org/pages/download-sample-modules/en. Extract the contents of the archive into the directory of your choice. The archive should contain three sub directories:

· · ·

free.demo.weblog free.uml2.gen.java free.uml14.gen.java

3.1 - Import a Project into Eclipse

Import " free.demo.weblog " into Eclipse :

­ ­ ­

Select "File" => " Import... " (cf. Figure 1). Select the assistant " Existing Project Into Workspace " (cf. Figure 2). Click " Next ".

Figure 1: Import a project (1)

Figure 2: Import a project (2)

Acceleo 2.6: User Tutorial

Page 4/62

­ ­ ­

Click " Browse... " (cf. Figure 3) in order to open a window which contains all the files on the disk Select the location that contains " free.demo.weblog "(cf. Figure 4). Click " OK ".

Figure 3: Import a project (3)

Figure 4: Import a project (4)

" free.demo.weblog " is added to the list (cf. Figure 5). Once the list contains all the desired files Click " Finish " to add the project to Eclipse.

Figure 5: Import a Project (5) The project " free.demo.weblog " is a " Dynamic Web Project " (cf. 4.2.2.2 Creating a project " Dynamic Web Project "). Repeat the above-described procedure to import the project " free.uml2.gen.java ".

Acceleo 2.6: User Tutorial

Page 5/62

Please note that the directory " src " is empty (cf. Figure 6). The generation will fill this directory.

Figure 6: Tree for both projects

3.2 - Launch the Generation Chain

Once both projects are imported, the " free.demo.weblog>weblog.chain>Launch " generation chain must be launched (cf. Figure 7).

Figure 7: Launch the generation chain

Figure 8: The generated files

Note : The files generated are based on the UML model WebLog_fr.uml, which has been designed in

Acceleo 2.6: User Tutorial

Page 6/62

French. An English version of the model is also provided with the example. The following pages of this guide shows pictures using the French version of the model, but it would work the same with the English version. After clicking " Launch ", a progress bar shows up and once finished, the subdirectory " src " will contain three packages with the generated Java files. (cf. Figure 8).

Acceleo 2.6: User Tutorial

Page 7/62

4 - Modeling

The Acceleo tool offers different modeling possibilities:

­ ­ ­ ­ ­

UML1.x UML2 Ecore DSL Others (Merise, SADT, OMT, proprietary tools..)

4.1 - Definition

The following is a reminder of some UML specific definitions which could be helpful to understand the tutorial. Profile: A profile is a standard extension mechanism for the UML language that allows the specialization of a UML scheme for a particular domain. It consists of a coherent set of stereotypes, tagged-values and constraints NOTE: We do not add meta-classes, but rather annotations to existing UML meta-classes . Standard profiles do exist: profile CORBA (OMG), profile EJB 1.0 (JCP), etc. Stereotypes: The stereotype concept enables elements to be classified (annotated) and acts as a new meta-model element. A stereotype is a " GeneralizableElement ". An inherited relation is therefore possible for stereotypes. It is also possible to define abstract stereotypes in order to avoid duplications when stereotypes have common properties. Tagged-value: The concept of tagged-values enables information to be added to classes. A tagged-value can be considered as a new meta-attribute. Constraints: The concept of constraints is used to express the relationship between stereotypes and tagged-values.

Acceleo 2.6: User Tutorial

Page 8/62

4.2 - The Modelers

The models produced by numerous modelers are compatible with Acceleo because of its use of standard and open formats. Acceleo is natively based on EMF, and is thus directly compatible with tools created around this framework. Examples include RSM, Together, and Omondo. Not all modelers are integrated with Eclipse, but most of them offer an XMI-type export function to ensure compatibility with other tools. Acceleo has been successfully tested with export tools using models UML 1.4 with XMI 1.x: Poseidon, Objecteering, Sparx, ArgoUML, etc. In order to read an XMI that is different from EMF, right-click on the XMI file and choose " Convert XMI ". The procedure is always the same: Either the modeler is integrated with Eclipse and Acceleo can directly use the XMI files, or the modeler is external, and in this case, the XMI file must be exported to a sub-directory in the workspace, and the file must be updated in Eclipse. The following is a cinematic diagram in a DSM created via GMF :

Figure 9: Cinematic diagram in a DSM This model is directly compatible with Acceleo because it is based on EMF.

4.2.1 - The UML2 Meta-Model with the EMF Modeler

Acceleo uses the EMF editor to open models based on UML2. This modeler is present in the " Example EMF Model Creation Wizards " section. A project must have been created before creating a UML2 model.

Acceleo 2.6: User Tutorial

Page 9/62

4.2.1.1 - Creating a Project

To create a project, simply select the new project creation wizard: " File>New>Other>General>Project " (Figure 11).

Figure 11: Creating a project (1)

Figure 10: Creating a project (2)

­ ­

Enter " fr.obeo.pim.demo.tutorial " as the " Project Name " field. Click " Finish " to add the project to Eclipse (figure 12).

Figure 12: Creating a project (3)

Acceleo 2.6: User Tutorial

Page 10/62

We will now create a " model " folder (cf. Figure 14) in this new project. To do so :

­

Right-click on the project root and select the folder creation assistant " New>Folder " (cf. Figure 13).

Figure 13: Creating a folder

Figure 14: Naming a folder

­ ­

Fill in the field " Folder name " Click " Finish " to add the folder to Eclipse. An empty folder will then be created in the project.

4.2.1.2 - Creating a UML2 Model

To create a UML2 model:

­ ­ ­ ­ ­

Right-click on the " model " folder Select the EMF model creation assistant " New>Other>Example EMF Model Creation Wizards>UML2 Model " (cf. Figure 15). Click " Next ". Enter the model name " Tutorial.uml " in the " File name " field. (cf. Figure 16). Click " Next ".

Acceleo 2.6: User Tutorial

Page 11/62

Figure 15: Creation of a model Figure 16: Naming a model In the " Model Object " field, choose " Model " (cf. Figure 17). Click " Finish " for the model to be created.

­ ­

Figure 17: Selecting a model object An empty model has been created. Now we can create the desired model.

4.2.1.2.a - Creating a Package

The first step consists of creating a package:

­ ­

Right-click on the root element named " Model " From the " Child " list, select the " Package " element. (Figure 18)

Acceleo 2.6: User Tutorial

Page 12/62

Figure 18: Creating a package Figure 19: Displaying the property view The properties of this new " Package " element can be found in the " Properties " view. If this view is not currently displayed by Eclipse, right-click on your new package and select " ShowProperties View " (cf. Figure 19). Filling in the " name " field is required. Let's call this package "myFirstPackage" (Figure 20).

Figure 20: Property name Clicking on a model element allows its properties to be modified in the " Properties " view.

4.2.1.2.b - Creating a Class

Now that the package has been created, let's add a class "MyClass" within it. The following operations will help you do so:

­ ­

Right-click on the "myFirstPackage" package, select the menu item " New Child>Class " Fill in the " name " field of the new class with as "myClass".

4.2.1.2.c - Creating an Attribute

Now, to add an attribute to this class, complete the following operations:

­ ­

Right-click on the class "myClass", select the " New Child>Property " menu item. Fill in the " name " field with "myAttribute".

Try and fill in the type of the attribute "myAttribute". The type of an attribute is modified via the corresponding property. Yet in this case, clicking on the field "type" will not allow you to use primitive types (such as String).

Acceleo 2.6: User Tutorial

Page 13/62

To use primitive types, UML2 profiles must be employed.

4.2.1.2.d - Adding a Profile to a Model

In order to set a UML2 profile, simply right-click on one of the model elements and select " Load Resource... " (cf. Figure 21)

Figure 21: Add a profile(1)

In the dialog that just appeared, the URI of the profile to load must be entered. The profile containing the primitive types (integer, character string, boolean...) has the URI: pathmap://UML_PROFILES/Standard.profile.uml. (cf. Figure 22)

Figure 22: Add a profile (2)

Acceleo 2.6: User Tutorial

Page 14/62

Two new resources are then loaded within the model (cf. Figure 23).

Figure 23: New profile

It is now possible to select "String" as the type of "myAttribute": select it in the modeler and modify the "type" property (cf. Figure 24).

Figure 24: Choosing the String primitive type To add a little something to the model, create a second class " MySecondClass " (cf. 3.2.1.2.b Create a class) with a single attribute "mySecondAttribute" (cf. 3.2.1.2.c Create an attribute).

4.2.1.2.e - Create an Association

This new attribute "mySecondAttribute" will be of type "MyClass": simply select "MyClass" in the " type " field of the " Properties " view (cf. figure 25). An association between the two classes has just been created.

Figure 25: Create an association A second method to create an association between two classes is to add the association manually: right-click on the package and select the " New Child>Association " menu item. The new association is added at the end of the model (cf. figure 26).

Acceleo 2.6: User Tutorial

Page 15/62

Figure 26: Adding an association between two classes Fill in the " memberEnd " field of this association in the " Properties " view: you must make use of the selector (circled on figure 27).

Figure 27: The selector A window is now opened:

­ ­ ­

Select "myAttribute" and click " Add " Select "mySecondAttribute" and click " Add ". Validate via " OK " (cf. Figure 28).

Figure 28: Creating an association The " memberEnd " field is now made up of two attributes (cf. Figure 29).

Acceleo 2.6: User Tutorial

Page 16/62

Figure 29: Filled in the " memberEnd " field

4.2.1.2.f - Validate the Model

The model has been created. To ensure its validity, right-click on the root element, " Model ", and select " Validate " (cf. Figure 30).

Figure 31: Validation completed

Figure 30: Validation of the model

4.2.2 - Using the Example

This part explains the way the example works. An example of both a model and a script can be downloaded from the Acceleo website at the following URL: http://www.acceleo.org/pages/download-sample-modules/en. Extract the contents of the archive into the directory of your choice. The archive should contain three sub directories:

· · ·

free.demo.weblog free.uml2.gen.java free.uml14.gen.java

Acceleo 2.6: User Tutorial

Page 17/62

4.2.2.1 - Importing a Project into Eclipse

Import " free.demo.weblog " into Eclipse.

­ ­ ­

Select "File" => " Import... " (cf. Figure 32) Then select the " Existing Project Into WorkSpace " project import assistant (cf. Figure 33). Click " Next " to import the project into Eclipse.

Figure 32: Import a project (1)

­ ­ ­

Figure 33: Import a project (2)

Click " Browse... " (cf. Figure 34) in order to open a window which contains all the files on the disk Select the location that contains " free.demo.weblog " (cf. Figure 35). Click " OK ".

Acceleo 2.6: User Tutorial

Page 18/62

Figure 35: Import a project (4) Figure 34: Import a project (3) The project " free.demo.weblog " is added to the list (cf. Figure 36). Once the list contains all the desired files Click " Finish " to add the project to Eclipse (cf. Figure 37).

Figure 37: Import a project (6)

Figure 36: Import a project (5)

" free.demo.weblog " is a " Dynamic Web Project " project.

Acceleo 2.6: User Tutorial

Page 19/62

4.2.2.2 - Creating a Project " Dynamic Web Project "

This section explains how the project free.demo.weblog was created This section will explain how the example was created and how to create it once again. Eclipse WTP must be installed prior to following these instructions. Select the dynamic Web project creation assistant: " File>New>Other>Web>Dynamic Web Project " (cf. Figure 38 & 39), then click " Next ". NOTE: if "Dynamic Web Project" does not appear in your Eclipse, WTP is not what you installed.

Figure 39: Creation of a project (2)

Figure 38: Creation of a project (1)

Acceleo 2.6: User Tutorial

Page 20/62

­ ­

Fill in the " Project Name " field with the desired name for the project and click " Next " (cf. Figure 40). Click " Next " (cf. figure 41).

Figure 41: Creating a project (4) Figure 40: Creating a project (3)

Figure 43: Creating a project (6)

Figure 42: Creating a project (5)

Acceleo 2.6: User Tutorial

Page 21/62

When the " Open associated Perspective " view (cf. figure 43) is displayed,

­

click " Yes " to obtain a J2EE perspective (cf. Figure 44) or " No " to preserve the Java perspective (cf. Figure 45).

­

Figure 44: J2EE perspective To change the perspective manually later on, simply click the " Open Perspective " icon (circled on Figure 45).

Figure 45: Java perspective

Acceleo 2.6: User Tutorial

Page 22/62

4.2.2.3 - The model WebLog_fr.uml

In order to better understand the Weblog project, here is a UML representation of the class diagram. The first representation is of WebLog GUI (cf. Figure 46); the second models WebLog business project (cf. Figure 47).

Figure 46: Class diagram of Weblog GUI

Figure 47: Class diagram of Weblog business project

Acceleo 2.6: User Tutorial

Page 23/62

4.2.2.4 - Creating a Model

Throughout this section the reference model will be the model " WebLog_fr.uml ". " WebLog_en.uml " is the same UML2 model, in English. " Weblog_en.uml14 " is this same model, described in UML 1.4 and in English Once the project has been created (cf: 4.2.1.1 My First Project or 4.2.2.2 Creating a Project " Dynamic Web Project "), create a directory " model " within it. Right-click on this new directory and select " File>New>Other>Example EMF Model Creation Wizards " for the EMF model creation assistant (cf. Figure 48).

Figure 48: Creating a model

­ ­ ­

Name the new model in the following dialog then continue to the model object selection. In the " Model Object " section, choose " Model " (cf. Figure 49). Next click " Finish " for the model to be created. Figure 49: Creating a model (2)

Acceleo 2.6: User Tutorial

Page 24/62

Open this new model, right-click on its root element and select the menu item " New Child ". A list of the elements that can be added appears. (cf. Figure 50).

Figure 50: Possible children nodes

The following list describes the type of elements that can be added as children (presented above):

· · · · · ·

Profiles Packages Classes Properties Operations Operation parameters

The attributes of these elements may be modified in the "properties" view (cf. figure 52). If this view does not appear in Eclipse, right-click on the model (in the " Reflective Editor ") and select the " Show Properties View " menu item (cf. Figure 51).

Acceleo 2.6: User Tutorial

Page 25/62

Figure 51: Displaying the Properties view

Figure 52: Properties view The properties will not be described in detail in this tutorial; however a few points will be addressed. The cardinalities:

· ·

" Lower ": Minimal cardinalities " Upper ": Maximum cardinalities

Infinity is represented by " -1 " for the upper cardinality Types: " Type " modifies the attribute type. The name: " Name " changes the name of the element. This property is mandatory. The WebLog example does not use stereotypes but " keywords ". The three models provided in the directory " model " were created with a modeler that replaced stereotypes with " keywords ". " keywords " can be considered the same as stereotypes.

Acceleo 2.6: User Tutorial

Page 26/62

5 - Initializing a Project

The " WebLog_fr.uml " model will be used for this section.

5.1 - Importing Generation Modules

Because we are using " WebLog_fr.uml " as the reference model, the generation module corresponding to this model must be imported. The reference module which need to be imported is:

·

free.uml2.gen.java

This directory can be found in the archive downloaded in part 3 (cf. 3.2.2). To import this project, refer to part 4.2.2.1 Importing a Project into Eclipse. The two projects should appear in Eclipse (cf. Figure 53).

Figure 53: Projects in Eclipse For the remainder of the tutorial, it is recommended that the Acceleo perspective be open. If it needs to be opened, simply click on the " Open Perspective " icon (cf. Figure 45), and choose Acceleo if it appears in the list. If it is not present in the presented list, select " Other... ", Acceleo, then confirm via " Ok " (cf. Figure 54).

Figure 54: Acceleo perspective

Acceleo 2.6: User Tutorial

Page 27/62

5.2 - Code Generation Files

The " free.uml2.gen.java " project contains the generator files. These files can be found in the directory " src ": they use the extension " .mt ".

Figure 55: Code generation files These files are generation scripts and allow the generation of the desired code.

5.2.1 - Previewing the Results

In order to preview the generation results, you first need to open a model (in this example, WebLog_en.uml). Afterwards, right-click on either one of the model elements (does not matter which) and select the menu item " Acceleo>Select Generator " (cf: Figure 56).

Figure 56: Select a code generator Next, select the generator which result needs to be previewed. This example will use the template " jdbc.mt ", located in " src>org>acceleo>modules>uml2>gen>java>dao " as described on Figure 57.

Acceleo 2.6: User Tutorial

Page 28/62

Figure 57: Selection of the file to preview The model classes of defined with a " keywords " value of " Entity " are decorated with an arrow added (cf. Figure 58)

Figure 58: Class with " keywords " having a value of "Entity" Previewing the code that would be generated via this template can be done through the " Source " tab with one of the decorated element selected (both circled on Figure 58). Text in black is the code that has been dynamically generated and is related to the previously selected model elements. In this example, the class "User". Likewise, the purple text is the code that has been statically generated. (cf. Figure 59).

Acceleo 2.6: User Tutorial

Page 29/62

Figure 59: Preview of the generated code

5.2.1.1 - Synchronizing the Model Code

The model and the generated code are synchronized. It is thus possible to find the model element that generated a particular portion of the code, and vice versa. Simply double-click on a dynamically generated element (one that is in black), in order for its corresponding element to be selected in the model. (cf. Figure 60).

Figure 60: Synchronization of the model code Likewise, a single click on a model element selects the corresponding generated code. (cf. Figure 61). A second click in the model selects the second occurrence of generated text, and so on.

Acceleo 2.6: User Tutorial

Page 30/62

Figure 61: Synchronization of the model code

5.3 - Creating the Generation Chain

There are two possible ways to create a generation chain. Either use the available assistant or create it manually.

5.3.1 - Creating a Generation Chain Using the Assistant

In this example, the generation chains (.chain) are in the " free.demo.weblog " project. The location of the chain is of no importance. To create a generation chain, it is advisable to use the Acceleo perspective (cf. Figure 45 and 54). In the example, the generation chains have already been created. The purpose of this section is to recreate a generation chain identical to the " weblog.chain " generation chain. To create a new generation chain:

­ ­

Right-click on the " free.demo.weblog " project. Select " New>chain " (cf. Figure 62).

Acceleo 2.6: User Tutorial

Page 31/62

Figure 62: Creating a new generation chain Select the appropriate meta-model. For the purpose of this example, select the UML2 meta-model "http://www.eclipse.org/uml2/2.0.0/UML" (cf. Figure 63), then click on " Next ".

Figure 63: Selection of the meta-model Select the " WebLog_en.uml " model (cf. Figure 64), then carry on with " Next ".

Figure 64: Selecting the model

Acceleo 2.6: User Tutorial

Page 32/62

Now the desired generation templates should be selected; here, all of the templates contained within the " dto ", " dao ", and " ui " directories (cf. Figure: 65). Continue via " Next ".

Figure 65: Selecting the scripts

Finally, select the location and the name of this new generation chain (cf. Figure 66). This example chain should be located in the " free.demo.weblog " directory and named " MyWebLog_en.chain "

Figure 66: Finalizing the generation chain

Acceleo 2.6: User Tutorial

Page 33/62

This new generation chain consists of the following (cf. Figure 67):

Figure 67: Contents of a generation chain It lists the set of resources used and the actions that must take place. The specialized editor helps the user and allows for the validation of the tasks. There are two types elements: resources and the actions. The resources part, also called "Repository", contains the whole set of resources used by the actions. There are seven types of resources:

· · · · · · ·

Model: Models to which the generator will be applied Model Set : Sets of models on which the generators will be applied Folder: Directories in which the generation will take place Log: Logs available to record generation errors Meta-Model: The high level meta-models describing the input models Script: The generators that need to be applied Custom File : Other files that could be used by actions (« Custom Action »)

The actions part, also called "ActionSet", contains all the tasks that must be launched. There are seven types of actions:

· ·

Generate: applies a generator to a model, and places the whole hierarchy of the generated files the specified target directory. The required meta-model is the one that describes the input model. Convert Xmi: Converts an XMI 1.x file that has been exported by a non EMF modeler into an XMI 2.0 file based on EMF. This conversion can handle UML13 and UML14 meta-models defined for EMF with either the http://www.obeo.fr/acceleo/uml13 URI or the http://www.obeo.fr/acceleo/uml14 URI. This action is often used before a generation action which will be applied on the resulting converted model. Backup: Saves all the resources from one directory to another. Several levels of backup may be defined. The backup of a target generation directory is especially useful during the template fine-tuning phase, when the risk of getting errors is greater. However, this action may be redundant and does not always work well with version management tools such as CVS or SVN. It should be used with moderation! Clear: Empties the content of each file in a selected directory, including its subdirectories. This action does not delete the resources; it simply empties their content and produces empty files. Remove: Permanently deletes the selected files and directories. Call : Launches the chains with the given path (« Chain Path »), substituting the declared parameters of the sub chain by the given arguments. A double click on the new "Call" will allow the selection of the chain to call.

·

· · ·

Acceleo 2.6: User Tutorial

Page 34/62

·

Custom Action : Launch a custom action on the selected resources. To specify an action you have to put the « ID » property.

5.3.2 - Creating a Generation Chain without the Assistant

To create a generation chain without the assistant, place the cursor over the " free.demo.weblog " directory and right-click. Select " New>Other>Acceleo>Empty Chain " (cf. Figure 68).

Figure 68: Creation of a generation chain without the assistant Click " Next " and name the chain, " webLog_en_sa.chain " (cf. Figure 69) and click " Finish " to add the chain to Eclipse.

Figure 69: Naming the generation chain

The chain is created, but is empty. The required element for its operation must be added.

Acceleo 2.6: User Tutorial

Page 35/62

5.3.2.1 - Adding a Model

­ ­

Open the generation chain and right-click on "Repository" Select " New Child>Model " (cf. Figure 70).

Figure 70: Selection of a model There are then two possibilities to select the desired model :

­

The first is to enter the URI of the model in the " Path " field of the properties view: " /free.demo.weblog/model/WebLog_fr.uml " (cf. Figure 71).

Figure 71: URI of the model This solution is fastidious and complicated. The second is an easier way of choosing a model in the Eclipse workspace:

­

Double-click on the "Model" element in the editor. This action opens a dialog box to allow a selection to be made from among the available models. (cf. Figure 72).

Figure 72: Double click on the model

Acceleo 2.6: User Tutorial

Page 36/62

­

Select the " model " directory (on the left). This selection displays the models that are present in the directory on the right-hand side. To select a model, simply check the box at its side and click " OK " (cf. Figure 73).

Figure 73: Select a model

5.3.2.2 - Adding a Target Folder

­ ­ ­

Open the generation chain and right-click on "Repository". Select " New Child>Folder " Then select " Folder " and fill the " Path " feature in the properties view with the " /free.demo.weblog " for the target directory, Double click on the " Folder " element, Choose the desired location (cf. Figure 74). path

or

­ ­

Acceleo 2.6: User Tutorial

Page 37/62

Figure 74: Select the target folder

­

Click " OK " to validate the target directory selection.

5.3.2.3 - Adding a Log

­ ­ ­

Open the generation chain and right-click on "Repository". Select " New Child>Log " Then select the " Log " that has just been created, and complete the " Path " field of the properties view as: " /free.demo.weblog/WebLog_fr.log.txt ", or Double-click the " Log " element that has just been added to the generation chain. Select the file that should be the generation's " Error Log " (cf. Figure 75).

­ ­

Figure 75: Select the error log

Acceleo 2.6: User Tutorial

Page 38/62

5.3.2.4 - Adding a Meta-Model

­ ­ ­

Open the generation chain and right-click on "Repository". Select " New Child>Emf Meta-model " Then select " Emf Meta-model " and fill in the " Path " property with:

http://www.eclipse.org/uml2/1.0.0/UML or

­ ­

Double-click on the meta-model that has just been created in the chain. Select the desired meta-model URI from the list (cf. Figure 76).

Figure 76: Choose the desired meta-model

5.3.2.5 - Adding the Generation File

­ ­ ­

Open the generation chain and right-click on "Repository". Select " New Child>Generator " Complete the " Path " field with the location of the desired generation file (.mt): or

" /free.uml2.gen.java/src/org/acceleo/modules/uml2/gen/java/dao/jdbc.mt. "

­

Double-click the file to choose the generation file (.mt) (cf. Figure 77).

Figure 77: Choose a generation file

Acceleo 2.6: User Tutorial

Page 39/62

It is possible to add as many " Generators " as desired, as demonstrated in Figure 67 above. Now let's define the generation actions:

­

Right-click " Action Set" and Select " New Child>Generate ".

In the " Properties " view, six fields must be completed.

Figure 78: The six property fields of a "Generate" action

· · · · · ·

Documentation: Name that will be displayed by the editor for this action. The generator's file name may be used, in order to locate it easily. Folder: Folder in which to generate the files. Generator: Path of the generation file (.mt) to use. Log: The error file (log) path. Meta-model: The meta-model URI. Model: The model path.

For each generation file (.mt) to launch, a corresponding " Generate " action must be defined. An example is shown on Figure 79, that " Generate " corresponds to the template " jdbc.mt ". For the other files, the manipulation is identical except for the " Documentation " property since it is a name chosen by the user, which can be distinct for each file. (cf Figure 79).

Figure 79: The six propriety fields of a " Generate " action

Acceleo 2.6: User Tutorial

Page 40/62

6 - Generation

6.1 - Running a Generation Chain

Now that the generation chain has been created, it is possible to generate the files. Right-click the generation chain " weblog.chain " and select " Launch " to launch the generation (cf. Figure 80).

Figure 80: Launcher for the generation chain The " src " directory, which up to now had been empty, now contains three packages:

· · ·

free.demo.weblog/src/org/acceleo/sample/dto free.demo.weblog/src/org/acceleo/sample/ihm free.demo.weblog/src/org/acceleo/sample/jdbc

These three packages contain the Java files that have just been generated. One of the three packages (free.demo.weblog/src/org/acceleo/sample/ihm) presents errors though. These can be resolved by importing a Tomcat server into the project.

Acceleo 2.6: User Tutorial

Page 41/62

6.2 - Importing a Tomcat server

A version of Tomcat server must first be installed on the machine. If necessary, it may be downloaded from the following address: http://tomcat.apache.org/ If you did not install Eclipse WTP, its plug-ins are also required before testing this new application : http://www.eclipse.org/webtools/main.php. Once the server version is installed on the machine, import it so Eclipse will recognize it:

­

Click the Window>Show View>Other (cf. Figure 81).

Figure 81: Import a Server

­

Select Server>Servers (cf. Figure 82)

Figure 82: Open Servers view

Acceleo 2.6: User Tutorial

Page 42/62

The " Servers " view is added to Eclipse (cf.:Figure 83).

Figure 83: The view Server

­

Right-click in the " Servers " view, and Select " New>Server " (cf. Figure 84).

Figure 84: Select Server

­

Select the Apache server installed on the machine. We installed Tomcat Server 5.5 for this example (cf. Figure 85).

Figure 85: Selection of the server

Acceleo 2.6: User Tutorial

Page 43/62

­

Click " Next " then Select the server installation directory via " Browse " (cf. Figure 86).

Figure 86: Select the installation directory

­ ­

Click " Next ". Select the "free.demo.weblog" project and add it to the server by clicking on " Add > " (cf. Figure 87).

Figure 88: Select the project

Figure 87: The project is now added

­

You're done, click on " Finish ".

Acceleo 2.6: User Tutorial

Page 44/62

6.2.1 - Importing the Tomcat Libraries

Even though the server is installed, the errors will still appear in the second package. To finally fix these errors you need to import the Tomcat server libraries in the project. Right-click on the project, then select " Properties>Java Build Path " (cf. Figure 89).

Figure 89: Adding the libraries from Tomcat

­

Select " Add Externals JARs ", find the installation directory for the Apache Software Foundation/Tomcat 5.5/common/lib server, select the servlet-api.jar file and click "Open"(cf. Figure 90).

Figure 90: Select the corresponding library

Acceleo 2.6: User Tutorial

Page 45/62

­

Close this dialog box via " OK " (cf. Figure 91).

Figure 91: Adding the libraries to the project " build path " The library is added to the project " build path ", and the error are all cleared. The WebContent directory has also been modified by the generation. It now contains a " jsp " directory containing the JSP files and a " WEB-INF " directory with, notably, the web.xml file.

Figure 92: Contents of the various folders

Acceleo 2.6: User Tutorial

Page 46/62

6.3 - Testing the Application

Once the server has been installed, the application can be tested. In order to do so, you must first launch the server.

­ ­

Right-click on the server displayed on the " Servers " view. Select " Start " (cf. Figure 93).

Figure 93: Launch the Tomcat server

Once the server has been launched, the " Started " icon appears for it in the " Servers " view (cf. Figure 94).

Figure 94: The server is launched The " Console " view can also be consulted to check that the server has been properly launched (cf. Figure 95).

Figure 95: Console view

The next step is to open a Web Browser and go to the following URL: http://localhost:8080/free.demo.weblog/

Acceleo 2.6: User Tutorial

Page 47/62

A menu is then displayed on the browser. This page is the " Index.html " file (cf. Figure 96).

Figure 96: Menu for free.demo.weblog The link " Screen AccountEdition" allows you to create a new account (cf. Figure 97).

Figure 97: Creating an account

*NOTE* The functions are not implemented ­ only the GUI is.

Acceleo 2.6: User Tutorial

Page 48/62

7 - Parameters

7.1 - The Generation Chains

In section 5.3 we detailed step-by-step how to create a generation chain. Yet the needs can change once the generation chain has been created and it may happen that the generation chain no longer meets the its needs. It isn't necessary to create a new generation chain. Indeed, Acceleo allows the modification of an existing generation chain.

7.1.1 - Modifying a Generation Chain

Open the generation chain that need be modified. (cf. Figure 98).

Figure 98: The generation chain weblog.chain To modify an element, simply double-click on it. For example, if a generation file is to be modified, the file extension (.mt) should be double-clicked, and a new file may then be selected. To select the new file:

­

Uncheck the previously selected template by clicking on it (cf. Figure 99). The file's check box will then be cleared:

Acceleo 2.6: User Tutorial

Page 49/62

­

Figure 99: Deselect the file Now check the new template (cf. Figure 100). The check box shows the selection.

Figure 100: Select the new file

­

To validate the change, click " OK ".

7.2 - The " logs "

The " logs " will allow the events that prevented the generation to be recorded in when errors occur during the execution of a generation chain. The specified error log is displayed when an error arises during the generation. (cf. Figure 101).

Acceleo 2.6: User Tutorial

Page 50/62

Figure 101: Error file Simply double-click on this file to open it in Eclipse (cf. Figure 102).

Figure 102: Content of the error file Erasing the content of the log before a generation makes it easier to check whether the generation chain now runs normally or if there are still anomalies.

7.3 - The " Properties " Files

It's been mentioned earlier that the packages for different Java classes were parameterized according to the script. Even though they are modular, modifying the naming standards within a company requires all of the generators to be refactored. Acceleo incorporated a " properties " mechanism that establishes generation parameters; for example, the folder names, or package names where the files have to be generated. This mechanism will be demonstrated by providing parameters for the package names in Weblog project.

7.3.1 - Creating a " Properties " File

­ ­ ­

Create a new " org.acceleo.modules.uml2.utils " " free.demo.weblog " project.

package

in

the

" src "

directory

for

the

Right-click on this new package and select the " New > File " menu item. In the file creation assistant enter the name " config.properties " (cf. Figure 103).

Acceleo 2.6: User Tutorial

Page 51/62

Figure 103: Creating the config.properties file

­

The new " config.properties " file is created in the specified package (cf : Figure 104).

Figure 104: The file "properties"

Type in the following two lines (both of which hereafter referred to as "keys"):

package.format=com.enterprise project.name=weblog

Launch the " weblog.chain " chain. The files are now generated in the " com.enterprise.weblog " package instead of " org.acceleo.sample "(cf figure 105).

Figure 105: Packages generated wit parameterization If it is later decided to change the naming standard for the packages, simply add a " new_config.properties "

Acceleo 2.6: User Tutorial

Page 52/62

file alongside the " weblog.chain " file, and place within it a new value for the " project.name " key, such as " web.weblog " (supposing that the type of the product is " web " for the weblog). The next generation will now include the type of product "web" in the name of the packages (cf figure 106).

Figure 106: New "Properties" file enables the packages to have new names

Acceleo 2.6: User Tutorial

Page 53/62

8 - Update Management

8.1 - Manual Development 8.1.1 - Adding code to the servlets

It is possible to insert manual code into the generated code. Portions of the code where it is possible to insert user code are surrounded by the tags:

//Start of user code

and

//End of user code

For example, the init(HttpServletRequest req, HttpServletResponse resp) procedure in the free.demo.weblog/src/org/acceleo/sample/ihm/CreationCompteServland.java file can be personalized as follows: Within the section reserved for user code, enter:

//Start of user code init if (nom.equals("Julien")){ returnCode = PAGE_CONNECTION; } //End of user code

Then the application must be restarted:

­ ­

Right-click on the server in the "servers" view Select " Restart>Start " (cf. Figure 107).

Figure 107: Restarting the server

­

Refresh the current Web Browser page (F5). The action has been recognized.

If the generation chain is launched anew, the code surrounded by user tags is preserved. The same test may be executed by adding code outside the " Start of user code " tags. The modification is recognized when the server is restarted; however the code which was added outside the

Acceleo 2.6: User Tutorial

Page 54/62

tags will be deleted with the next generation. It is therefore very important to not write code outside of the tags intended for this use.

8.2 - Functional Updates 8.2.1 - Modification of the Input Model

Modifications can of course be made to the input model.

8.2.1.1 - Modification of an Attribute

It is possible to modify an attribute. To do this:

­

Select the " login " attribute for the "User" class in the " Business.blog " package (cf. Figure 108).

Figure 108: The model

­

Change its " name " property in the " Properties " view: change " login " in "identifier".

This example will be based on the /free.demo.weblog/src/org/acceleo/sample/dto/UserDto.java generated file.

Acceleo 2.6: User Tutorial

Page 55/62

Before the modification, the attributes were generated as follows:

public class UtilisateurDto implements Serializable { // serialVersionUID is used for serialization. private static final long serialVersionUID = 1L; protected protected protected protected protected String String String String String email; prenom; nom; login; motDePasse;

In order for the modifications to be recognized, the files must be regenerated. Simply launch the generation chain once again (cf. 6.1 Launching a Generation Chain). The attributes are now generated as follows:

public class UtilisateurDto implements Serializable { // serialVersionUID is used for serialization. private static final long serialVersionUID = 1L; protected protected protected protected protected String String String String String email; prenom; nom; identifier; motDePasse;

When an attribute is deleted, it is also removed from the generated files. For example, if the " email " attribute is deleted from the model, it will no longer appear in the generated Java files.

8.2.1.2 - Adding a Class

It is possible to add a class to the model:

­ ­ ­ ­

Add a new class in the " blog " package. Name it "Administrator". Create two "String" type attributes to it; name them " surname " and " name ". Also add to it a " keywords " with the value " Entity ". Copy ­ Paste it from one of the existing classes. (cf. Figure 109).

Figure 109: Adding a class

Acceleo 2.6: User Tutorial

Page 56/62

Now that the class has been added to the model, the model must be saved and the generation chain must be launch again. The new Java files have been created. (cf. Figure 110).

Figure 110: New files have been created If a class with a " Screen " stereotype (keyword " Screen ") has been created, then the generation will also have modified the web.xml file. Likewise, if the class had not been stereotyped, " Entity " (keyword " Entity "), no new Java files would have been created.

8.2.1.3 - Deleting a Class

It is also possible to delete a model class.

­ ­

To delete the "Administrator" class, right-click "Administrator" and select " Delete ". Save the model and relaunch the generation chain.

The files corresponding to the class have not been deleted. They must be deleted manually or use chainweblog.clean.chain. Be careful, the code that was manually inserted between the two "Start of user code" tags (cf: 8.1.1 Adding Code in the Servlets) will be deleted. This generation chain should only be used if no code was manually inserted between the guides.

8.2.1.4 - Renaming a class

It is possible to rename a class. The procedure is identical to that used to rename an attribute. (cf. 8.2.1.1 Modifying an attribute). Once the class has been renamed and the model has been saved, you must launch the generation chain. The result will be identical to that observed during the deletion of a class (cf. 8.2.1.3 Deletion of a class). That is , the new Java files will have been created; yet the old ones will still exist. (cf. Figure 111). In the example below, the class "User" has been renamed " Blogger ".

Acceleo 2.6: User Tutorial

Page 57/62

Figure 111: The new files and the old ones

8.2.1.5 - Adding/Modifying a Relationship (association / inheritance)

It is possible to add or to modify a relationship (association, inheritance). To do so, simply modify the relationship in the model, save this modification and launch the generation chain. The modification that was made will appear in the newly generated files.

8.3 - The " Lost " Files

If a modification is made to a generation file or a model that involves modifying the code generated between the " Start of user code " tags, a ".lost" file will be generated. For example if a model attribute is deleted, and this attribute was called within "user code" tags, then when the generation chain is relaunched, the old code is placed in a file with the extension " .lost ". The " .lost " files preserve the user code that is no longer valid due to a modification.

Figure 112: Example of a "lost" file

Acceleo 2.6: User Tutorial

Page 58/62

8.4 - Acceleo Traceability

As a complement to Acceleo, Obeo offers the Acceleo Traceability software. Acceleo Traceability is designed towards model/code synchronization. Here is an example usage of Acceleo Pro Traceability which warns the user when a modification is made to the code outside user tags, as this code would be lost on the next generation (cf. Figure 115).

Acceleo 2.6: User Tutorial

Page 59/62

9 - Advanced Use

9.1 - Launching a Generation Chain Automatically from within Eclipse

It is possible to launch a generation chain from the application launch icon

­ ­

within Eclipse.

Click the drop-down list of the " run " tab. Select " Run... " .

­ ­ ­

Double-click " Chain ". Fill in the " Name " field with the desired name for the launching configuration. Select the launching chain by clicking "Browse" (cf. Figure 113).

Figure 113: Select a launching chain. It is possible to select several launching chains. To launch the generation chain, it can then be selected in the drop-down list on the " Run " tab. (cf. Figure 114).

Figure 114: Launching the generation chain

Acceleo 2.6: User Tutorial

Page 60/62

10 - Additional Environments

10.1 - Managing Different Versions

In order to manage the different file versions, a version management tool such as CVS or SVN must be used. These free software programs may be downloaded at http://www.nongnu.org/cvs/ (CVS) or http://subversion.tigris.org/ (SVN). Once this software is installed, the easiest way to make use of them is to install the corresponding Eclipse plug-ins. The CVS plug-in for Eclipse is installed by default. One of the SVN

Figure 115: Acceleo Pro Traceability : example of the tool plug-ins for Eclipse, Subclipse, can be found at http://subclipse.tigris.org/. Once one of these plug-ins has been installed, the version management functions may be found in the " Team" menu located in the pop-up menu (right-click on a resource: project, file, folder, ...).

10.1.1 - Sharing a New Project

If a project has not already been shared, it may be shared on a server. To do so, right-click on the project to share. From the " Team " menu, select " Share Project... ". If more than a single version management software have been installed (CVS is installed by default), select the one that is to be used (cf. Figure 116).

Acceleo 2.6: User Tutorial

Page 61/62

Figure 116: Choosing the version management tool Fill in the required fields: the host, the repository, the login and the password. Click " Finish "; the data may now be used by other users.

Acceleo 2.6: User Tutorial

Page 62/62

10.1.2 - Sharing Modifications

Figure 117: Commentary window with SVN To share modifications to a project, right-click on the project. From the " Team " menu, click " Commit ". Enter the commit message that will explain the modifications that have been made, and click " OK " (cf. Figure 117). The modifications are now available on the server.

10.1.3 - Loading the Modifications from Another User

To load modifications from another user, click Team > Update. The version management tool will even manage possible conflicts, and asks the user what to do if it cannot resolve the conflict with no human intervention. Once this operation has finished, the other user's modifications are displayed.

Information

66 pages

Find more like this

Report File (DMCA)

Our content is added by our users. We aim to remove reported files within 1 working day. Please use this link to notify us:

Report this file as copyright or inappropriate

820121