if( debug > 10 ) log.log( "Before compile sync " + jspFile );
synchronized( handler ) {
// double check - maybe another thread did that for us
Dependency dep= handler.getServletInfo().getDependency();
if( dep!=null && ! dep.isExpired() ) {
// if the jspfile is older than the class - we're ok
return 0;
}
Context ctx=req.getContext();
// Mangle the names - expensive operation, but nothing
// compared with a compilation :-)
JasperMangler mangler=
new JasperMangler(ctx.getWorkDir().getAbsolutePath(),
ctx.getAbsolutePath(),
jspFile );
// If unsafe path or JSP file doesn't exist, return "not found"
// Avoids creating work directories for non-existent JSP files
String path=mangler.getJspFilePath();
if( path == null )
return 404;
File f = new File( path );
if( !f.exists() )
return 404;
// register the handler as dependent on the jspfile
if( dep==null ) {
dep=setDependency( ctx, mangler, handler );
// if dep is null then path is unsafe, return "not found"
if( dep == null ) {
return 404;
}
// update the servlet class name
handler.setServletClassName( mangler.getServletClassName() );
// check again - maybe we just found a compiled class from
// a previous run
if( ! dep.isExpired() )
return 0;
}
// if( debug > 3)
ctx.log( "Compiling: " + jspFile + " to " +
mangler.getServletClassName());
//XXX old servlet - destroy();
// jump version number - the file needs to be recompiled
// reset the handler error, un-initialize the servlet
handler.setErrorException( null );
handler.setState( Handler.STATE_ADDED );
// Move to the next class name
mangler.nextVersion();
// record time of attempted translate-and-compile
// if the compilation fails, we'll not try again
// until the jsp file changes
dep.setLastModified( System.currentTimeMillis() );
// Update the class name in wrapper
if( debug> 1 )
log.log( "Update class Name " + mangler.getServletClassName());
handler.setServletClassName( mangler.getServletClassName() );
// May be called from include, we need to set the context class
// loader
// for jaxp1.1 to work using the container class loader
//Extra test/warnings for tools.jar
ClassLoader savedContextCL= containerCCL( ctx.getContextManager()
.getContainerLoader() );
if( useWebAppCL ) {
try {
ctx.getClassLoader().loadClass( "sun.tools.javac.Main" );
if(debug>0) log.log( "Found javac using context loader");
} catch( ClassNotFoundException ex ) {
if(debug>0) log.log( "javac not found using context loader");
}
try {
ctx.getContextManager().getContainerLoader().
loadClass( "sun.tools.javac.Main" );
if( debug > 0 )
log.log( "Found javac using container loader");
} catch( ClassNotFoundException ex ) {
if( debug > 0 )
log.log( "javac not found using container loader");
}
}
try {
Options options=new JasperOptionsImpl(args);
JspCompilationContext ctxt=createCompilationContext(req,
jspFile,
options,
mangler);
jsp2java( mangler, ctxt );
javac( req, options, ctxt, mangler );
if(debug>0)log.log( "Generated " +
mangler.getClassFileName() );
} catch ( java.io.FileNotFoundException fnfex ){
containerCCL( savedContextCL );
return 404;
} catch( Exception ex ) {
if( ctx!=null )
ctx.log("compile error: req="+req, ex);
else
log.log("compile error: req="+req, ex);
handler.setErrorException(ex);
handler.setState(Handler.STATE_DISABLED);
// until the jsp cahnges, when it'll be enabled again
containerCCL( savedContextCL );
return 500;
}
containerCCL( savedContextCL );
dep.setExpired( false );
}
return 0;
}