FileDocCategorySizeDatePackage
AllJSPsMustBeCompilable.javaAPI DocGlassfish v2 API6314Fri May 04 22:34:08 BST 2007com.sun.enterprise.tools.verifier.tests.web

AllJSPsMustBeCompilable

public class AllJSPsMustBeCompilable extends WebTest implements WebCheck
author
ss141213

Fields Summary
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.WebBundleDescriptor descriptor)

        Result result = getInitializedResult();
        ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();

        // initialize good result
        addGoodDetails(result, compName);
        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed",
                                "All JSPs are compilable."));
        // set default status to PASSED
        result.setStatus(Result.PASSED);
        // initialize error results.
        addErrorDetails(result, compName);
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".exception",
                "Error: Some JSPs bundled inside [ {0} ] could not be compiled. See details below.",
                new Object[] {descriptor.getName()}));
        for(JasperException e : compile(descriptor)){
            result.failed(formatMessage(descriptor, e.toString()));
        }
        return result;
    
protected java.util.Listcompile(com.sun.enterprise.deployment.WebBundleDescriptor descriptor)

        String archiveUri = getAbstractArchiveUri(descriptor);
        File outDir=getVerifierContext().getOutDir();
        logger.log(Level.INFO, "Compiling JSPs in [ " +new File(archiveUri).getName()+ " ]");
        JspC jspc=new JspC();
        jspc.setUriroot(archiveUri);
        jspc.setCompile(true);
        jspc.setOutputDir(outDir.getAbsolutePath());
        jspc.setFailOnError(false);
        setClassPath(jspc);
        jspc.setSchemaResourcePrefix("/schemas/");
        jspc.setDtdResourcePrefix("/dtds/");
        if (logger.isLoggable(Level.FINEST)) 
            jspc.setVerbose(1);
        try {
            jspc.execute();
        } catch(JasperException je) {
            List<JasperException> errors = jspc.getJSPCompilationErrors();
            errors.add(je);
            return errors;
        }
        return jspc.getJSPCompilationErrors();
    
private java.lang.StringformatMessage(com.sun.enterprise.deployment.WebBundleDescriptor descriptor, java.lang.String message)

        if (message == null || descriptor == null) return null;
        String formattedMessage = message;
        String archiveUri = getAbstractArchiveUri(descriptor);
        int index = message.indexOf(archiveUri);
        if(index != -1) {
            formattedMessage = message.substring(index + archiveUri.length() + 1);
        }
        return formattedMessage;
    
private voidsetClassPath(org.apache.jasper.JspC jspc)

param
jspc

        /*
        ClassPath settings of JspC is tricky.
        JspC has two classpath settings, viz: classPath and systemClassPath.
        systemClassPath defaults to the value set in java.class.path
        system property. It is not clear how they differ.
        From the JspC code, it looks like that JspC uses systemClassPath to
        construct what they call a systemCL and it uses classPath to construct
        what they call loader whose parent is set as systemCL. loader is set as
        ThreadContextClassLoader during jspc. More over, when JspC invokes
        javac, it combines classPath and systemClassPath sets that as
        javac classpath. So, it does not really matter what goes in which variable
        as long as the order is preserved.
        There are three different modes:
        1. standalone portable mode, 2. standalone appserver mode and
        3. deployment backend.
        In all the cases, we only set the classPath. systemClassPath is
        internally set correctly using java.class.path variable in JspC.
        Any way our WebArchiveClassesLoadable will take care of
        proprietary class linking.
        */
        String cp = getVerifierContext().getClassPath();
        logger.log(Level.FINE, "JSPC classpath "+ cp);
        jspc.setClassPath(cp);