KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > AllJSPsMustBeCompilable


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * AllJSPsMustBeCompilable.java
26  *
27  * Created on August 27, 2004, 11:57 AM
28  */

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 JavaDoc;
37 import java.util.logging.Level JavaDoc;
38 import java.util.List JavaDoc;
39
40 import org.apache.jasper.JspC;
41 import org.apache.jasper.JasperException;
42 /**
43  *
44  * @author ss141213
45  */

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         // initialize good result
53
addGoodDetails(result, compName);
54         result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed",
55                                 "All JSPs are compilable."));
56         // set default status to PASSED
57
result.setStatus(Result.PASSED);
58         // initialize error results.
59
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 JavaDoc[] {descriptor.getName()}));
63         for(JasperException e : compile(descriptor)){
64             result.failed(formatMessage(descriptor, e.toString()));
65         }
66         return result;
67     }
68
69     protected List JavaDoc<JasperException> compile(WebBundleDescriptor descriptor) {
70         String JavaDoc archiveUri = getAbstractArchiveUri(descriptor);
71         File JavaDoc outDir=getVerifierContext().getOutDir();
72         logger.log(Level.INFO, "Compiling JSPs in [ " +new File JavaDoc(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 JavaDoc as_lib_root=System.getProperty("com.sun.aas.installRoot")+File.separator+"lib"+File.separator;
79         String JavaDoc 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 JavaDoc<JasperException> errors = jspc.getJSPCompilationErrors();
93             errors.add(je);
94             return errors;
95         }
96         return jspc.getJSPCompilationErrors();
97     }
98     
99     private String JavaDoc formatMessage(WebBundleDescriptor descriptor, String JavaDoc message) {
100         if (message == null || descriptor == null) return null;
101         String JavaDoc formattedMessage = message;
102         String JavaDoc 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