|How to access information about the code generated? [message #507193]
||Tue, 12 January 2010 13:05
| Erik Sandin
Registered: January 2010
Hello out there! |
I am using JET to generate some java and xml files. Is there any way that I can access information about what has been generated and what has been updated?
As the developer I am now giving the model as input to a JET transformation but, since we want some kind of abstraction, this code generation technique will be used by several people and therefore I am thinking of using the generation technique as a plugin. When I give the model as input to JET I get info about what has happened in the console. This info would be of great interest! So the question is as below.
Is there any way for me to access code generation information when using JET code generation as a plugin?
|Re: How to access information about the code generated? [message #507267 is a reply to message #507193]
||Tue, 12 January 2010 16:56
| Paul Elder
Registered: July 2009
Unfortunately, there is no public API for accessing the log information
that you see on the JET execution context.
But, if you're willing to take a risk on using internal classes, getting
at this information is pretty simple...
The class org.eclipse.jet.internal.runtime.RuntimeLoggerContextExtende r
is the logging intermediary between log messages issued by tags and any
listeners to this. Given a JET2Context object, you use the
getInstance(JET2Context) static method to obtain an instance.
Once you have a RuntimeLoggerContextExtender, you can use
addListener(RuntimeTagLogger) to add a listener to tag execution.
org.eclipse.jet.internal.runtime.RuntimeTagLogger is an interface with a
single log(String,TagInfo,String,int) method to implement. It is called
everytime a tag wants to log some message. The last argument (int level)
is one of the RuntimeLoggerContextExtender.XXX_LEVEL constants.
So, it should be possible for you to invoke a JET transformation from
API something like the following:
// load the source model, if necessary. Take a peek at the
// implementation of JET2Platform.runTransformOnString()
// or JET2Platform.runTransformOnResource() methods
// for inspiration
// construct a JET2Context
final JET2Context ctx = new JET2Context(inMemoryInputModelRoot);
// get and configure the RuntimeLoggerContextExtender
final RuntimeLoggerContextExtender logExt
// add a log listener...
logExt.addListener( new MyRuntimeTagLogger() );
// finally, run the transformation..
final IStatus status
= JET2Platform.runTransform(id, ctx, progressMonitor);
The only risk you take in doing this is the usage of internal API, so a
future JET version make move, modify or delete these classes/methods
If you'd like a stable API, consider filing an enhancement request. If
you'd really, really like a stable API, consider contributing an
|Re: How to access information about the code generated? [message #511515 is a reply to message #511418]
||Mon, 01 February 2010 20:27
| Paul Elder
Registered: July 2009
Glad you're making progress...
The org.eclipse.jet.resource.project.name typically gets set by
JET2Platform.runTransformOnResource(). Of course, you have had to bypass
this. But, all is not lost, the actual work of loading the IResource and
setting all those variables is delegated to another public static function:
IResource resource, String loaderId, String fileExtension);
So, modifying your code so that you:
1) create your JET2Context object
2) call WorkspaceContextExtender.loadResourceAsSource
3) finally call JET2Platform.runTransform()
Let me know it if works.
Powered by FUDForum
. Page generated in 0.01699 seconds