Re: Compiling on the fly

Artem Gr <[email protected]> Tue, 30 Nov 2004 16:54:29 +0300
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
Recently I've developed a very simple Nice template
engine (I call it NiceTee).
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).

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.

Snipped of my code invoking the compiler:

  println( "compiling..." );
  let String sourcepath = temporary.getAbsolutePath();
  let String[] args = [
    "--sourcepath", sourcepath,
    "--destination", sourcepath,
    "--classpath", notNull( System.getProperty( "java.class.path" ) ),
    this.packageName.toString() ];
  let result = nice.tools.compiler.console.dispatch.compile( args );
  println( 0 == result || 3 == result ? "done!" : "error..." );
  return 0 == result || 3 == result;





-------------------------------------------------------
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/