Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 09:04 Go to next message
Niels Brouwers is currently offline Niels BrouwersFriend
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 #894455 is a reply to message #894435] Mon, 09 July 2012 09:46 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

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 10:56 Go to previous message
Niels Brouwers is currently offline Niels BrouwersFriend
Messages: 80
Registered: July 2009
Member
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!


Kind regards,
Niels Brouwers.
Previous Topic:generate.emtl not found
Next Topic:Retrieve target folder during generation
Goto Forum:
  


Current Time: Fri Apr 19 21:30:15 GMT 2024

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

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

Back to the top