Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » How to access information about the code generated?(How to access information about the code generated?)
How to access information about the code generated? [message #507193] Tue, 12 January 2010 13:05 Go to next message
Erik Sandin is currently offline Erik SandinFriend
Messages: 4
Registered: January 2010
Junior Member
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?

Best regards

Erik Sandin
Re: How to access information about the code generated? [message #507267 is a reply to message #507193] Tue, 12 January 2010 16:56 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Erik:

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
= RuntimeLoggerContextExtender.getInstance(ctx);

// 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
without warning.

If you'd like a stable API, consider filing an enhancement request. If
you'd really, really like a stable API, consider contributing an
implementation :-)

Paul
Re: How to access information about the code generated? [message #511418 is a reply to message #507267] Mon, 01 February 2010 15:04 Go to previous messageGo to next message
Erik Sandin is currently offline Erik SandinFriend
Messages: 4
Registered: January 2010
Junior Member
Thank you Paul!

This helped, though I had to do some changes in the example code to make it work it now produces a nice output. The log function works terrific but now I have a new problem. The JET transformation does not work anymore.

Variable "org.eclipse.jet.resource.project.name" is not defined.
templates/main.jet
completed action. 
templates/main.jet
completed action. 
templates/main.jet
loop initialized
templates/main.jet
finished loop
templates/main.jet
Variable "org.eclipse.jet.resource.project.name" is not defined.
templates/main.jet
completed action. 
templates/main.jet
completed action. 
templates/main.jet...


The error message keeps on going and none of the tags in main.jet seems to work. I am using the code sent to me to run runTransform so nothing is wrong there. I belive there are some issues with the model sent to runTransform. It works without the the log part but by using runTransformationOnReference instead. Are there any known problems with using runTransform because I can't seem to find the problem
Re: How to access information about the code generated? [message #511515 is a reply to message #511418] Mon, 01 February 2010 20:27 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Erik:

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:

WorkspaceContextExtender.loadResourceAsSource(JET2Context context,
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.

Paul
Previous Topic:[Acceleo] Inconsistent Line Ending Style
Next Topic:[Announce] M2T XPAND 0.8.0M5 is available
Goto Forum:
  


Current Time: Thu Apr 25 16:22:32 GMT 2024

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

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

Back to the top