1 23 package com.sun.enterprise.tools.verifier.tests.web; 24 25 import com.sun.enterprise.tools.verifier.tests.VerifierTest; 26 import com.sun.enterprise.tools.verifier.tests.*; 27 import com.sun.enterprise.tools.verifier.Verifier; 28 import com.sun.enterprise.tools.verifier.Result; 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.Context; 33 import com.sun.enterprise.util.io.FileUtils; 34 35 import java.io.*; 36 37 38 45 abstract public class WebTest extends VerifierTest implements VerifierCheck, WebCheck { 46 47 private boolean addedError = false; 49 private boolean addedGood = false; 50 private boolean addedNa = false; 51 private boolean addedWarning = false; 52 53 final String separator= System.getProperty("file.separator"); 54 Context context = null; 55 56 66 public Result check(Descriptor descriptor) { 67 return check((WebBundleDescriptor) descriptor); 68 } 69 70 80 public abstract Result check(WebBundleDescriptor descriptor); 81 82 89 public Result loadWarFile(WebBundleDescriptor descriptor) { 90 91 Result result = getInitializedResult(); 92 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 93 context = getVerifierContext(); 94 try { 95 WebTestsUtil webTestsUtil = WebTestsUtil.getUtil(context.getClassLoader()); 97 } catch (Throwable e) { 109 Verifier.debug(e); 111 result.addErrorDetails(smh.getLocalString 112 ("tests.componentNameConstructor", 113 "For [ {0} ]", 114 new Object [] {compName.toString()})); 115 result.addErrorDetails(smh.getLocalString 116 ("com.sun.enterprise.tools.verifier.tests.web.WebTest" + ".Exception", 117 "Error: Unexpected exception occurred [ {0} ]", 118 new Object [] {e.toString()})); 119 } 120 return result; 121 } 122 123 132 public Class loadClass(Result result, String className) { 133 134 try { 135 WebTestsUtil webTestsUtil = WebTestsUtil.getUtil(context.getClassLoader()); 136 return webTestsUtil.loadClass(className); 138 } catch (Throwable e) { 139 140 try { 142 ClassLoader cl = getVerifierContext().getAlternateClassLoader(); 143 if (cl == null) { 144 throw e; 145 } 146 Class c = cl.loadClass(className); 147 return c; 148 }catch(Throwable ex) { 149 155 } 156 } 157 return null; 158 } 159 160 163 164 protected void deleteDirectory(String oneDir) { 165 166 File[] listOfFiles; 167 File cleanDir; 168 169 cleanDir = new File(oneDir); 170 if (!cleanDir.exists()) { return; 172 } 173 listOfFiles = cleanDir.listFiles(); 174 if(listOfFiles != null) { 175 for(int countFiles = 0; countFiles < listOfFiles.length; countFiles++) { 176 if (listOfFiles[countFiles].isFile()) { 177 listOfFiles[countFiles].delete(); 178 } else { String nextCleanDir = cleanDir + separator + listOfFiles[countFiles].getName(); 180 File newCleanDir = new File(nextCleanDir); 181 deleteDirectory(newCleanDir.getAbsolutePath()); 182 } 183 } } cleanDir.delete(); 186 } 187 188 protected String getAbstractArchiveUri(WebBundleDescriptor desc) { 189 String archBase = getVerifierContext().getAbstractArchive(). 190 getArchiveUri(); 191 final ModuleDescriptor moduleDescriptor = desc.getModuleDescriptor(); 192 if (moduleDescriptor.isStandalone()) { 193 return archBase; } else { 195 return archBase + File.separator + 196 FileUtils.makeFriendlyFileName(moduleDescriptor.getArchiveUri()); 197 } 198 } 199 200 } 201 | Popular Tags |