1 23 package com.sun.enterprise.tools.verifier.web; 24 25 import java.io.File ; 26 import java.io.IOException ; 27 import java.util.Random ; 28 29 import com.sun.enterprise.deployment.Descriptor; 30 import com.sun.enterprise.deployment.WebBundleDescriptor; 31 import com.sun.enterprise.deployment.util.ModuleDescriptor; 32 import com.sun.enterprise.tools.verifier.BaseVerifier; 33 import com.sun.enterprise.tools.verifier.FrameworkContext; 34 import com.sun.enterprise.tools.verifier.SpecVersionMapper; 35 import com.sun.enterprise.tools.verifier.apiscan.classfile.ClassFileLoaderFactory; 36 import com.sun.enterprise.tools.verifier.apiscan.packaging.ClassPathBuilder; 37 import com.sun.enterprise.tools.verifier.apiscan.stdapis.WebClosureCompiler; 38 import com.sun.enterprise.util.FileUtil; 39 import com.sun.enterprise.util.io.FileUtils; 40 import com.sun.enterprise.loader.EJBClassLoader; 41 42 47 public class WebVerifier extends BaseVerifier { 48 49 private WebBundleDescriptor webd = null; 50 private String classPath; private boolean isASMode = false; 52 private File jspOutDir = null; 53 54 public WebVerifier(FrameworkContext frameworkContext, 55 WebBundleDescriptor webd) { 56 this.frameworkContext = frameworkContext; 57 this.webd = webd; 58 this.isASMode = !frameworkContext.isPortabilityMode(); 59 } 60 61 67 public void verify() throws Exception { 68 if (areTestsNotRequired(frameworkContext.isWeb()) && 69 areTestsNotRequired(frameworkContext.isWebServices()) && 70 areTestsNotRequired(frameworkContext.isWebServicesClient()) && 71 areTestsNotRequired(frameworkContext.isPersistenceUnits())) 72 return; 73 74 jspOutDir = getJspOutDir(); 75 try { 76 preVerification(); 77 context.setOutDir(jspOutDir); 78 createClosureCompiler(); 79 verify(webd, new WebCheckMgrImpl(frameworkContext)); 80 } finally { 81 if(frameworkContext.getJspOutDir()==null) 84 FileUtil.deleteDir(jspOutDir); 85 } 86 } 87 88 92 public Descriptor getDescriptor() { 93 return webd; 94 } 95 96 102 protected ClassLoader createClassLoader() 103 throws IOException { 104 EJBClassLoader ejbClassLoader = new EJBClassLoader(webd.getClassLoader()); 105 ejbClassLoader.appendURL(jspOutDir); 106 return ejbClassLoader; 107 } 108 109 113 protected String getArchiveUri() { 114 return FileUtils.makeFriendlyFileName(webd.getModuleDescriptor().getArchiveUri()); 115 } 116 117 120 protected String [] getDDString() { 121 String dd[] = {"WEB-INF/sun-web.xml", "WEB-INF/web.xml", "WEB-INF/webservices.xml"}; return dd; 124 } 125 126 133 protected String getClassPath() throws IOException { 134 if (classPath != null) return classPath; 135 136 if(isASMode) 137 return (classPath = getClassPath(frameworkContext.getClassPath()) + 138 File.pathSeparator + 139 jspOutDir.getAbsolutePath()); 140 141 String cp; 142 if (!webd.getModuleDescriptor().isStandalone()) { 143 String ear_uri = frameworkContext.getExplodedArchivePath(); 145 File ear = new File (ear_uri); 146 assert(ear.isDirectory()); 147 String earCP = ClassPathBuilder.buildClassPathForEar(ear); 148 String libdir = webd.getApplication().getLibraryDirectory(); 149 if (libdir!=null) { 150 earCP = getLibdirClasspath(ear_uri, libdir) + earCP; 151 } 152 String module_uri = webd.getModuleDescriptor().getArchiveUri(); File module = new File (module_uri); 154 assert(module.isFile() && !module.isAbsolute()); 155 File explodedModuleDir = new File (ear_uri, 157 FileUtils.makeFriendlyFileName(module_uri)); 158 String moduleCP = ClassPathBuilder.buildClassPathForWar( 159 explodedModuleDir); 160 cp = moduleCP + File.pathSeparator + earCP; 161 } else { 162 String module_uri = frameworkContext.getExplodedArchivePath(); File module = new File (module_uri); 164 assert(module.isDirectory() && module.isAbsolute()); 165 cp = ClassPathBuilder.buildClassPathForWar(module); 166 } 167 String as_lib_root=System.getProperty("com.sun.aas.installRoot")+File.separator+"lib"+File.separator; 168 if (frameworkContext.getJavaEEVersion().compareTo("5") >= 0) { cp += File.pathSeparator+as_lib_root+"jsf-impl.jar"+File.pathSeparator+ as_lib_root+"appserv-jstl.jar"+File.pathSeparator; } 172 cp = cp + File.pathSeparator + jspOutDir.getAbsolutePath(); 173 return (classPath = cp); 174 } 175 176 183 protected void createClosureCompiler() throws IOException { 184 String specVer = SpecVersionMapper.getWebAppVersion( 185 frameworkContext.getJavaEEVersion()); 186 Object arg = (isASMode)?context.getClassLoader():(Object )getClassPath(); 187 WebClosureCompiler cc = new WebClosureCompiler(specVer, 188 ClassFileLoaderFactory.newInstance(new Object []{arg})); 189 context.setClosureCompiler(cc); 190 } 191 192 198 private File getJspOutDir(){ 199 File jspOutDir = frameworkContext.getJspOutDir(); 202 if(jspOutDir != null) { 203 ModuleDescriptor moduleDescriptor = webd.getModuleDescriptor(); 204 if(moduleDescriptor.isStandalone()) 205 return jspOutDir; 206 return new File (jspOutDir, FileUtils.makeFriendlyFilename(moduleDescriptor.getArchiveUri())); 207 } 208 Random random=new Random (); 209 String prefix=System.getProperty("java.io.tmpdir")+File.separator+".jspc"; 210 do{ 211 float f=random.nextFloat(); 212 String outDirPath=new String (prefix+f); 213 File out=new File (outDirPath); 214 if(out.mkdirs()) 215 return out; 216 }while(true); 217 } 218 } 219 | Popular Tags |