Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » Write to console from Acceleo templates
Write to console from Acceleo templates [message #894435] Mon, 09 July 2012 05:04 Go to next message
Eclipse UserFriend
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!

[Updated on: Mon, 09 July 2012 05:05] by Moderator

Re: Write to console from Acceleo templates [message #894455 is a reply to message #894435] Mon, 09 July 2012 05:46 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

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

--
Twitter: @sbegaudeau & @acceleo
Google+: stephane.begaudeau & acceleo
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo
Re: Write to console from Acceleo templates [message #894747 is a reply to message #894455] Tue, 10 July 2012 06:56 Go to previous message
Eclipse UserFriend
Stephane Begaudeau wrote on Mon, 09 July 2012 05:46
Hi,

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!
Previous Topic:generate.emtl not found
Next Topic:Retrieve target folder during generation
Goto Forum:
  


Current Time: Sun Jul 06 12:57:06 EDT 2025

Powered by FUDForum. Page generated in 0.07958 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top