1 23 24 29 30 package com.sun.enterprise.tools.verifier.tests.web; 31 32 import com.sun.enterprise.deployment.WebBundleDescriptor; 33 import com.sun.enterprise.tools.verifier.Result; 34 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 35 36 import java.io.File ; 37 import java.util.logging.Level ; 38 import java.util.List ; 39 40 import org.apache.jasper.JspC; 41 import org.apache.jasper.JasperException; 42 46 public class AllJSPsMustBeCompilable extends WebTest implements WebCheck{ 47 48 public Result check(WebBundleDescriptor descriptor) { 49 Result result = getInitializedResult(); 50 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 51 52 addGoodDetails(result, compName); 54 result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", 55 "All JSPs are compilable.")); 56 result.setStatus(Result.PASSED); 58 addErrorDetails(result, compName); 60 result.addErrorDetails(smh.getLocalString(getClass().getName() + ".exception", 61 "Error: Some JSPs bundled inside [ {0} ] could not be compiled. See details below.", 62 new Object [] {descriptor.getName()})); 63 for(JasperException e : compile(descriptor)){ 64 result.failed(formatMessage(descriptor, e.toString())); 65 } 66 return result; 67 } 68 69 protected List <JasperException> compile(WebBundleDescriptor descriptor) { 70 String archiveUri = getAbstractArchiveUri(descriptor); 71 File outDir=getVerifierContext().getOutDir(); 72 logger.log(Level.INFO, "Compiling JSPs in [ " +new File (archiveUri).getName()+ " ]"); 73 JspC jspc=new JspC(); 74 jspc.setUriroot(archiveUri); 75 jspc.setCompile(true); 76 jspc.setOutputDir(outDir.getAbsolutePath()); 77 jspc.setFailOnError(false); 78 String as_lib_root=System.getProperty("com.sun.aas.installRoot")+File.separator+"lib"+File.separator; 79 String cp = getVerifierContext().getClassPath(); 80 if (!getVerifierContext().isAppserverMode()) { 81 cp = as_lib_root+"javaee.jar"+ File.pathSeparator + cp; 82 } 83 logger.log(Level.FINE, "JSPC classpath "+cp); 84 jspc.setSystemClassPath(cp); 85 jspc.setSchemaResourcePrefix("/schemas/"); 86 jspc.setDtdResourcePrefix("/dtds/"); 87 if (logger.isLoggable(Level.FINEST)) 88 jspc.setVerbose(1); 89 try { 90 jspc.execute(); 91 } catch(JasperException je) { 92 List <JasperException> errors = jspc.getJSPCompilationErrors(); 93 errors.add(je); 94 return errors; 95 } 96 return jspc.getJSPCompilationErrors(); 97 } 98 99 private String formatMessage(WebBundleDescriptor descriptor, String message) { 100 if (message == null || descriptor == null) return null; 101 String formattedMessage = message; 102 String archiveUri = getAbstractArchiveUri(descriptor); 103 int index = message.indexOf(archiveUri); 104 if(index != -1) { 105 formattedMessage = message.substring(index + archiveUri.length() + 1); 106 } 107 return formattedMessage; 108 } 109 110 } 111 | Popular Tags |