tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler Compiler.java
Date Wed, 12 Jun 2002 23:23:05 GMT
costin      2002/06/12 16:23:05

  Modified:    jasper2/src/share/org/apache/jasper/compiler Compiler.java
  Log:
  - create the Project object for ant compilation only if we actually need to compile
  the page.
  
  - support other compilers ( by using the old jspCompiler option ). It gets set to
  ant's build.compiler.
  
  - add an ant logger, so error messages from ant go in the same place with the
  jasper error messages ( whatever that is - it seems now is the Context.log )
  
  Revision  Changes    Path
  1.14      +40 -6     jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java
  
  Index: Compiler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Compiler.java	7 Jun 2002 20:04:27 -0000	1.13
  +++ Compiler.java	12 Jun 2002 23:23:05 -0000	1.14
  @@ -70,6 +70,8 @@
   import org.apache.tools.ant.BuildEvent;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.BuildListener;
  +import org.apache.tools.ant.BuildLogger;
  +import org.apache.tools.ant.DefaultLogger;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.taskdefs.Javac;
   import org.apache.tools.ant.types.Path;
  @@ -115,7 +117,7 @@
       private PageInfo pageInfo;
       private JspServletWrapper jsw;
   
  -    protected Project project;
  +    protected Project project=null;
   
       protected Options options;
   
  @@ -133,11 +135,39 @@
           this.ctxt = ctxt;
   	this.errDispatcher = new ErrorDispatcher();
           this.options = ctxt.getOptions();
  +    }
  +
  +    // Lazy eval - if we don't need to compile we probably don't need the project
  +    private Project getProject() {
  +        if( project!=null ) return project;
           // Initializing project
           project = new Project();
  +        // XXX We should use a specialized logger to redirect to jasperlog
  +        DefaultLogger bl=new JasperAntLogger();
  +        bl.setOutputPrintStream(System.out);
  +        bl.setErrorPrintStream(System.err);
  +
  +        if( Constants.jasperLog.getVerbosityLevel() >= Logger.DEBUG ) {
  +            bl.setMessageOutputLevel( Project.MSG_VERBOSE );
  +        }
  +        project.addBuildListener( bl );
  +        
  +        if( options.getCompiler() != null ) {
  +            Constants.jasperLog.log("Compiler " + options.getCompiler(), Logger.ERROR );
  +            project.setProperty("build.compiler", options.getCompiler() );
  +        }
           project.init();
  +        return project;
       }
   
  +    static class JasperAntLogger extends DefaultLogger {
  +        protected void printMessage(final String message,
  +                                    final PrintStream stream,
  +                                    final int priority) {
  +            Constants.jasperLog.log( message, Logger.INFORMATION );
  +        }
  +
  +    }
   
       // --------------------------------------------------------- Public Methods
   
  @@ -209,6 +239,7 @@
           boolean success = true;
   
           // Initializing javac task
  +        getProject();
           Javac javac = (Javac) project.createTask("javac");
   
           // Initializing classpath
  @@ -223,6 +254,7 @@
           // Configure the compiler object
           javac.setEncoding(javaEncoding);
           javac.setClasspath(path);
  +        //javac.setDestdir(new File(options.getScratchDir().getAbsolutePath()));
           javac.setDebug(ctxt.getOptions().getClassDebugInfo());
           javac.setSrcdir(srcPath);
           javac.setOptimize(true);
  @@ -241,21 +273,23 @@
           try {
               javac.execute();
           } catch (BuildException e) {
  +            e.printStackTrace();
               success = false;
           }
   
           // Stop capturing the System.err output for this thread
           errorReport = SystemLogHandler.unsetThread();
  -
  +        
           if (!ctxt.keepGenerated()) {
               File javaFile = new File(javaFileName);
               javaFile.delete();
           }
   
           if (!success) {
  +            Constants.jasperLog.log( "Error compiling file: " + javaFileName + " " + errorReport,
  +                               Logger.ERROR);
               errDispatcher.javacError(errorReport, javaFileName, pageNodes);
           }
  -
       }
   
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message