Re: Re: Compiling on the fly

Daniel Bonniot <[email protected]> Sat, 11 Dec 2004 18:09:56 +0100
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
Hi,

> Recently I've developed a very simple Nice template
> engine (I call it NiceTee).

Good name. Make me think of "a nice cup of tea" ;-)

> It's logic is very simple: lines preceded with '%' are
> placed as is into the Nice source, other lines
> are placed as writeln( "the line" ).
> When template is changed, it is automatically
> recompiled, and resulting package is loaded
> into the custom ClassLoader, with restricted
> permissions (sandbox).
> Currently I use reflection to instantiate and invoke
> the generated template. (It is nothing compared
> to hundreds reflection calls Velocity does).

This sounds very interesting. Have you, or are you planning to make this tool 
publicly available?

> Overall, I have no problems compiling NiceTee
> dynamically from the running CMS system.
> The only drawback for now is that I can't directly
> catch error reports generated by the compiler.

I believe the best way would be to plug into the compiler at a slightly higher 
level. In that mode, you pass a listener that is called back by the compiler 
to notify the progress of the compilation and possible warnings or errors. 
This is how all of the command-line compiler, the ant task, the unit tester 
and the eclipse plugin work, and of course they do different things in the 
listener.

I encourage you to look at how any of those works to see how to plug into the 
compiler in that way. For instance, the command-line compiler is in the 
src/nice/tools/compiler/console directory. It defines the 'compile' method you 
are using at the moment. You should rather directly call the compile method 
defined in nice.tools.compiler that takes several arguments, including a 
Compilation object. Don't hesitate to ask for help if you have any problem 
figuring this out.

Cheers,

Daniel


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/