Home » Modeling » M2T (model-to-text transformation) » [acceleo]Access to java code and properties from scripts(Wonder if properties and java code can be accessed from scripts)
|
Re: [acceleo]Access to java code and properties from scripts [message #495524 is a reply to message #495287] |
Thu, 05 November 2009 08:46 |
|
This is a multi-part message in MIME format.
--------------000903090305050402050905
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Sebastien,
Both were great assets of Acceleo 2.6, and we obviously wanted them back
in the new version.
1) Java code. Though the tooling isn't mature yet on this, you can still
call for java methods from Acceleo code through
"invoke('java.lang.String', 'equalsIgnoreCase(java.lang.String)',
Sequence{'test, 'TEST'}" for example; which would be equivalent to
Java's "test".equalsIgnoreCase("TEST"). This is still extremely verbose
and we hope to be able to simplify in it the future.
2) Properties. Though we didn't port the old "getBestProperty" methods
that were a little "too magic", you can use either one of :
- getProperty(String key)
- getProperty(String propertyFile, String key)
- getProperty(String key, Sequence replacements)
- getProperty(String propertyFile, String key, Sequence replacements)
As for availability, 1) is in there since 0.8, but 2) only appeared in
Acceleo 0.9. Take a look at the javadoc of
AcceleoNonStandardLibrary#OPERATION_OCLANY_GETPROPERTY for the
description of all four.
Note that you will need to alter the generated launcher to add the
properties files that are to be taken into account for the generation.
Namely, take a look at AcceleoService#addPropertiesFile.
Laurent Goubet
Obeo
S a écrit :
> Hello,
> After creating a demonstrator using acceleo 2.6 some months ago, I'm
> going to move to acceleo M2T.
> The migration of Acceleo to an OMG standard is a great thing.
> However, I don't know if the following great features from acceleo 2.6
> are still available :
> - Access from script to java code
> - Access from script to properties
>
> Thank you for your answers
>
> Sebastien
>
>
--------------000903090305050402050905
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
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyLyI+T2JlbzwvYT4NCmVtYWls O2ludGVybmV0
OmxhdXJlbnQuZ291YmV0QG9iZW8uZnINCnVybDpodHRwOi8vd3d3Lm9iZW8u ZnINCnZlcnNp
b246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------000903090305050402050905--
|
|
|
Re: [acceleo]Access to java code and properties from scripts [message #495640 is a reply to message #495524] |
Thu, 05 November 2009 15:21 |
Sebastien Roy Messages: 51 Registered: November 2009 |
Member |
|
|
Thank you Laurent for your answer.
1)
I've just tested the 'invoke' statement. It works great.
However, I've a strange behaviour : when the 'invoke' is put in a query, even if the query is not called from anywhere , it conflicts with String.toUpperFirst().
For instance, the following code leads to an error :
[module invokeConflict('http://www.eclipse.org/uml2/2.1.0/UML')/]
[template public invokeConflict(p : Package)]
[file (p.name.toUpperFirst(), false)]
[p.name/]
[/file]
[/template]
[query public checkMyPrettyRegularExpression(s : String) : String = invoke('com.thalesgroup.isr.mde.test1.MyMDEUtils', 'checkMyRegularExpression(java.lang.String)', Sequence{s})/]
The detailed error is :
An internal error occurred during: "Launching invokeConflict".
org.eclipse.emf.ecore.xmi.UnresolvedReferenceException: Unresolved reference '/1/String_Class/toUpperFirst'. (platform:/resource/com.thalesgroup.isr.mde.test1/bin/com/thalesgroup/isr/mde/test1/files/invokeConflict.emtl, 19, 105)
When the query is removed or put into comment, the error is not raised.
When the invocation is written inside the main template, it works perfectly.
2)
Where is located the javadoc ? I cannot find it.
Regards
Sebastien
[Updated on: Thu, 05 November 2009 15:22] Report message to a moderator
|
|
|
Re: [acceleo]Access to java code and properties from scripts [message #495660 is a reply to message #495640] |
Thu, 05 November 2009 15:39 |
|
This is a multi-part message in MIME format.
--------------090203030101050502060206
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Sebastien,
Your error seems weird ... never seen that. And I cannot reproduce the
bug either :(. Under which version of Eclipse and Acceleo are you
observing this behavior?
As for the javadoc ... It *should* be it Help -> Help Contents ->
Acceleo -> Developer Guide -> Javadoc -> API Reference ... yet I saw
while accessing it that it is no longer in there :(. I'll try and fix
this for the next build. For now you can retrieve the sources of the
classes you need and look at the doc from there. We're also in the
process of documenting all accessible operations.
Laurent Goubet
Obeo
Sebastien Roy wrote:
> Thank you Laurent for your answer.
>
> 1)
> I've just tested the 'invoke' statement. It works great. However, I've a
> strange behaviour : when the 'invoke' is put in a query, even if the
> query is not called from anywhere , it conflicts with
> String.toUpperFirst().
> For instance, the following code leads to an error :
> [module invokeConflict('http://www.eclipse.org/uml2/2.1.0/UML')/]
>
> [template public invokeConflict(p : Package)]
> [file (p.name.toUpperFirst(), false)]
> [p.name/]
> [/file]
> [/template]
>
>
> [query public checkMyPrettyRegularExpression(s : String) : String =
> invoke('com.thalesgroup.isr.mde.test1.MyMDEUtils',
> 'checkMyRegularExpression(java.lang.String)', Sequence{s})/]
>
> The detailed error is :
> An internal error occurred during: "Launching invokeConflict".
> org.eclipse.emf.ecore.xmi.UnresolvedReferenceException: Unresolved
> reference '/1/String_Class/toUpperFirst'.
> (platform:/resource/com.thalesgroup.isr.mde.test1/bin/com/th alesgroup/isr/mde/test1/files/invokeConflict.emtl,
> 19, 105)
>
> When the query is removed or put into comment, the error is not raised.
> When the invocation is written inside the main template, it works
> perfectly.
>
> 2)
> Where is located the javadoc ? I cannot find it.
>
--------------090203030101050502060206
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=
--------------090203030101050502060206--
|
|
| | | |
Re: [acceleo]Access to java code and properties from scripts [message #496184 is a reply to message #496107] |
Mon, 09 November 2009 10:17 |
|
This is a multi-part message in MIME format.
--------------080009050904060503060905
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Hi Alain,
The Acceleo "invoke" operation allows access to java methods, not
fields. What you try to do is access the "println" method of
"OutputStream" on the particular output stream that is "System.out".
That is not possible as is; you could create your own java method that
will print on console and call that one.
The problem might be easier though. If you only wish to print messages
on the console, use the special url "stdout" for a File block : all
generated text for such a "file" will be printed out on the standard
output; namely, System.out.
[file ('stdout', false)]test[/file]
Laurent Goubet
Obeo
Alain MICHEL wrote:
> Hi all,
>
> As we talk of invoke, I couldn't make the following code work :
>
> [invoke('java.lang.System', 'out.println(java.lang.String)',
> Sequence{'test'})/]
>
> I've seen in the tests that static methods worked. But what about
> calling a method from a public static field?
--------------080009050904060503060905
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=
--------------080009050904060503060905--
|
|
|
Re: [acceleo]Access to java code and properties from scripts [message #496324 is a reply to message #495724] |
Mon, 09 November 2009 17:21 |
|
This is a multi-part message in MIME format.
--------------050001070708080504030005
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Sebastien,
I couldn't get this to fail however I tried. I'll fall back to version
0.9M2 and try on it, but the current devlopment version doesn't seem to
present this failure.
Laurent Goubet
Obeo
Sebastien Roy wrote:
> I've reproduced the bug with the following configuration
> - Eclipse 3.5 with modeling tools
> - Acceleo updated to 9.0M2
> - New Acceleo project (test1)
> - New template (generate) with the following content :
> [module generate('http://www.eclipse.org/uml2/2.1.0/UML')/]
>
> [template public generate(p : Package)]
>
> [file (p.name.toUpperFirst(), false)]
> [p.name/]
> [/file]
> [/template]
>
>
> [query public checkMyPrettyRegularExpression(s : String) : String =
> invoke('MyMDEUtils', 'checkMyRegularExpression(java.lang.String)',
> Sequence{s})/]
>
>
>
--------------050001070708080504030005
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=
--------------050001070708080504030005--
|
|
|
Re: [acceleo]Access to java code and properties from scripts [message #496381 is a reply to message #496184] |
Mon, 09 November 2009 19:51 |
Alain MICHEL Messages: 9 Registered: July 2009 |
Junior Member |
|
|
Thanks for your answer Laurent,
I didn't know the stdout trick, I suppose it can be quicker than debugging sometimes, nice.
Also my point was not specific to println() but that it might be useful to be able to call a method from a static field sometimes. But like you said, since it's possible to define a class to call such a method, and it's a case that doesn't happen very often, it's fine the way it is.
Thanks,
Alain
[Updated on: Mon, 09 November 2009 19:52] Report message to a moderator
|
|
| |
Re: [acceleo]Access to java code and properties from scripts [message #498990 is a reply to message #498878] |
Thu, 19 November 2009 13:21 |
|
This is a multi-part message in MIME format.
--------------070902020702080807080506
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Thanks for the feedback
Sebastien Roy wrote:
> Laurent Goubet wrote on Mon, 09 November 2009 12:21
>> Sebastien,
>>
>> I couldn't get this to fail however I tried. I'll fall back to version
>> 0.9M2 and try on it, but the current devlopment version doesn't seem
>> to present this failure.
>>
>> Laurent Goubet
>> Obeo
>
> Indeed, the bug doesn't appear on the latest (0.9M3) version of Acceleo.
> Thank you
>
--------------070902020702080807080506
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=
--------------070902020702080807080506--
|
|
|
Goto Forum:
Current Time: Thu Oct 10 18:21:20 GMT 2024
Powered by FUDForum. Page generated in 0.04543 seconds
|