1 23 package com.sun.enterprise.tools.verifier.tests.web; 24 25 import com.sun.enterprise.deployment.WebBundleDescriptor; 26 import com.sun.enterprise.deployment.WebComponentDescriptor; 27 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 28 import com.sun.enterprise.deployment.web.ServletFilter; 29 import com.sun.enterprise.deployment.web.AppListenerDescriptor; 30 import com.sun.enterprise.deployment.web.ErrorPageDescriptor; 31 import com.sun.enterprise.tools.verifier.Result; 32 import com.sun.enterprise.tools.verifier.apiscan.classfile.ClosureCompiler; 33 import com.sun.enterprise.tools.verifier.apiscan.classfile.ClosureCompilerImpl; 34 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 35 import com.sun.enterprise.tools.verifier.tests.util.WebArchiveLoadableHelper; 36 37 import java.util.*; 38 import java.io.File ; 39 40 48 public class WebArchiveClassesLoadable extends WebTest implements WebCheck { 49 public Result check(WebBundleDescriptor descriptor) { 50 Result result = getInitializedResult(); 51 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 52 String archiveUri = getAbstractArchiveUri(descriptor); 53 54 Iterator entries; 55 try{ 56 entries=getClassNames(descriptor).iterator(); 57 } catch(Exception e) { 58 result.failed(smh.getLocalString(getClass().getName() + ".exception", 60 "Error: [ {0} ] exception while loading the archive [ {1} ].", 61 new Object [] {e, descriptor.getName()})); 62 return result; 63 } 64 65 boolean allPassed = true; 66 ClosureCompiler closureCompiler=getVerifierContext().getClosureCompiler(); 67 ((ClosureCompilerImpl)closureCompiler).addExcludedPattern("org.apache.jasper"); 68 if(getVerifierContext().isAppserverMode()) 69 ((ClosureCompilerImpl)closureCompiler).addExcludedPattern("com.sun.enterprise"); 70 71 while (entries.hasNext()) { 72 String className=(String )entries.next(); 73 boolean status=closureCompiler.buildClosure(className); 74 allPassed=status && allPassed; 75 } 76 if (allPassed) { 77 result.setStatus(Result.PASSED); 78 addGoodDetails(result, compName); 79 result.passed(smh.getLocalString 80 (getClass().getName() + ".passed", 81 "All the classes are loadable within [ {0} ] without any linkage error.", 82 new Object [] {archiveUri})); 83 } else { 84 result.setStatus(Result.FAILED); 85 addErrorDetails(result, compName); 86 result.addErrorDetails(WebArchiveLoadableHelper.getFailedResults(closureCompiler, getVerifierContext().getOutDir())); 87 result.addErrorDetails(smh.getLocalString 88 ("com.sun.enterprise.tools.verifier.tests.loadableError", 89 "Please either bundle the above mentioned classes in the application " + 90 "or use optional packaging support for them.")); 91 } 92 return result; 93 } 94 95 104 private List getClassNames(WebBundleDescriptor descriptor) throws Exception { 105 final List<String > results=new LinkedList<String >(); 106 for(Object obj : descriptor.getServletDescriptors()) { 107 String servletClassName = (WebComponentDescriptor.class.cast(obj)) 108 .getWebComponentImplementation(); 109 results.add(servletClassName); 110 } 111 112 for (Object obj : descriptor.getServletFilterDescriptors()) { 113 String filterClassName = (ServletFilter.class.cast(obj)).getClassName(); 114 results.add(filterClassName); 115 } 116 117 for (Object obj : descriptor.getAppListenerDescriptors()) { 118 String listenerClassName = (AppListenerDescriptor.class.cast(obj)).getListener(); 119 results.add(listenerClassName); 120 } 121 122 results.addAll(getVerifierContext().getFacesConfigDescriptor().getManagedBeanClasses()); 123 124 Enumeration en = descriptor.getErrorPageDescriptors(); 125 while (en.hasMoreElements()) { 126 ErrorPageDescriptor errorPageDescriptor = (ErrorPageDescriptor) en.nextElement(); 127 String exceptionType = errorPageDescriptor.getExceptionType(); 128 if (exceptionType != null && !exceptionType.equals("")) 129 results.add(exceptionType); 130 } 131 132 File file = getVerifierContext().getOutDir(); 133 if(!file.exists()) 134 return results; 135 136 FileArchive arch= new FileArchive(); 137 arch.open(file.getAbsolutePath()); 138 Enumeration entries = arch.entries(); 139 while(entries.hasMoreElements()){ 140 String name=(String )entries.nextElement(); 141 if(name.startsWith("org/apache/jsp") && name.endsWith(".class")) 142 results.add(name.substring(0, name.lastIndexOf(".")).replace('/','.')); 143 } 144 return results; 145 } 146 147 } 148 | Popular Tags |