Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Accessing external variables from templates
[Acceleo] Accessing external variables from templates [message #532205] Fri, 07 May 2010 10:12 Go to next message
labassim  is currently offline labassim
Messages: 6
Registered: May 2010
Junior Member
Hi,
I am writin mtl generation templates and I would like to access external variables to customize my generation.
To make things clearer :
I created an Eclipse wizard which aims at creating a custom java project. The project architecture is defined by the user within the wizard (package name..).
When I click finish in the end of the wizard, I launch the generation template (by calling the main method of the java file associated to the mtl template).
I would like to pass arguments to the mtl template, for example to generate files in the package defined in the wizard.
Is there a way to achieve this ?
Thanks in advance.
Re: [Acceleo] Accessing external variables from templates [message #532356 is a reply to message #532205] Sat, 08 May 2010 15:12 Go to previous messageGo to next message
Sebastien Roy is currently offline Sebastien Roy
Messages: 51
Registered: November 2009
Member
A solution to your problem could consist in putting all your variables in an HashSet and passing it to the java launcher of your mtl scripts (see Acceleo documentation for the details)

Regards

Sebastien
Re: [Acceleo] Accessing external variables from templates [message #533082 is a reply to message #532205] Wed, 12 May 2010 04:10 Go to previous message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1609
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030703000807080002070606
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Mehdi,

You can define Acceleo templates with more than one argument ("[template
public templateName(arg0 : type, arg1 : type, arg2 : type, ...)]").
Nothing prevents you from passing arguments over to the generation
template ... though if you use the generated "main" method, it only
takes an array of Strings as parameter, in turn your arguments can only
be of type "String". The first String in the array has to be the path to
the model (and this is the model we'll iterate over to find the _first_
argument of the called template), the second String is the folder we'll
use as the root of the generated files' paths, any subsequent String
will be passed on to the called template as the second (and subsequent)
arguments.

If you wish for more complex types as arguments of your generation
templates -keep in mind you can only use "model" element (elements
defined in a metamodel or instances of those)-, you'll have to mimic the
behavior of the generated "main" method and call the "doGenerate" yourself.

Laurent Goubet
Obeo

labassim wrote:
> Hi,
> I am writin mtl generation templates and I would like to access external
> variables to customize my generation.
> To make things clearer :
> I created an Eclipse wizard which aims at creating a custom java
> project. The project architecture is defined by the user within the
> wizard (package name..).
> When I click finish in the end of the wizard, I launch the generation
> template (by calling the main method of the java file associated to the
> mtl template).
> I would like to pass arguments to the mtl template, for example to
> generate files in the package defined in the wizard.
> Is there a way to achieve this ?
> Thanks in advance.
>


--------------030703000807080002070606
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------030703000807080002070606--
Previous Topic:[Acceleo] Import a meta-model using its path
Next Topic:[Acceleo] Defining multiple metamodels within the same template
Goto Forum:
  


Current Time: Mon Apr 21 08:45:55 EDT 2014

Powered by FUDForum. Page generated in 0.02076 seconds