Write to console from Acceleo templates [message #894435] |
Mon, 09 July 2012 09:04 |
Niels Brouwers Messages: 80 Registered: July 2009 |
Member |
|
|
Hi all,
I would like to write some warnings to the console. I've tried two mechanisms, unfortunately both failed.
1) Using Java service wrapper
Service:
package generator.utils;
public class ConsoleUtils {
public void PrintWarning(String msg)
{
System.out.println("Warning: " + msg);
}
}
Wrapper:
[query public printWarning(msg : String) : OclAny =
invoke('generator.utils.ConsoleUtils',
'PrintWarning(java.lang.String)',
Sequence{msg})
/]
2) Write to 'stdout' file.
[template public printWarning(msg : String)]
[file ('stdout', true, 'Cp1252')]
WARNING: [msg/]
[/file]
[/template]
In both cases, the following statement in a template is used to print a message to the console:
printWarning('some warning message')/]
I can not find a console view where this message is shown. However, when I create a simple Java application with one System.out.println statement, the console is popped up immediately showing the desired text.
Does anyone know what I am doing wrong? Is there some setting I missed? Help is really appreciated here.
Thanks!
Kind regards,
Niels Brouwers.
[Updated on: Mon, 09 July 2012 09:05] Report message to a moderator
|
|
|
|
Re: Write to console from Acceleo templates [message #894747 is a reply to message #894455] |
Tue, 10 July 2012 10:56 |
Niels Brouwers Messages: 80 Registered: July 2009 |
Member |
|
|
Stephane Begaudeau wrote on Mon, 09 July 2012 05:46Hi,
During the generation, the Acceleo generator is deployed in your current Eclipse instance and as such, you can't access the console. If you need to log some information, you would need to use something like this:
WorkbenchPlugin.getDefault().getLog().log(...)
You would have to use the logging mechanism of the Eclipse platform. More information on this on the Eclipse wiki here and there.
Or if it's for debugging a Java service, you can always try to throw a new runtime exception.
Regards,
Stephane Begaudeau, Obeo
Thanks Stephane,
I know understand what the problem was. Using your information I got a warning message to be logged in the error log, which is perfect in my case!
The ConsoleUtils Java service wrapper know looks like this:
public class ConsoleUtils {
public void PrintWarning(String msg)
{
Activator plugin = Activator.getDefault();
plugin.getLog().log(new Status(Status.WARNING, plugin.getBundle().getSymbolicName(), Status.OK, msg, null));
}
}
Thanks!
Kind regards,
Niels Brouwers.
|
|
|
Powered by
FUDForum. Page generated in 0.02680 seconds