1 23 package com.sun.enterprise.tools.verifier; 24 25 import java.io.IOException ; 26 import java.io.File ; 27 import java.util.logging.Level ; 28 import java.util.logging.LogRecord ; 29 import java.util.logging.Logger ; 30 import java.util.List ; 31 32 import com.sun.enterprise.deployment.Application; 33 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 34 import com.sun.enterprise.deployment.Descriptor; 35 import com.sun.enterprise.logging.LogDomains; 36 import com.sun.enterprise.tools.verifier.gui.MainFrame; 37 import com.sun.enterprise.util.LocalStringManagerImpl; 38 39 46 public class Verifier { 47 48 private static boolean debug = false; 49 private static Logger logger = LogDomains.getLogger( 50 LogDomains.AVK_VERIFIER_LOGGER); 51 54 private FrameworkContext frameworkContext = null; 55 56 57 64 public Verifier(String [] args) { 65 StringManagerHelper.setLocalStringsManager(this.getClass()); 66 frameworkContext = new Initializer(args).getFrameworkContext(); 67 } 68 69 73 public Verifier() { 74 StringManagerHelper.setLocalStringsManager(this.getClass()); 75 frameworkContext = new FrameworkContext(); 76 frameworkContext.setUseTimeStamp(true); 77 frameworkContext.setOutputDirName(System.getProperty("com.sun.aas.instanceRoot") + File.separator + 79 "logs" + File.separator + 81 "verifier-results"); } 83 84 91 public static void main(String [] args) throws IOException { 92 Verifier verifier = new Verifier(args); 93 if (verifier.frameworkContext.isUsingGui()) { 94 MainFrame mf = new MainFrame( 95 verifier.frameworkContext.getJarFileName(), true, verifier); 96 mf.setSize(800, 600); 97 mf.setVisible(true); 98 } else { 99 LocalStringManagerImpl smh = StringManagerHelper.getLocalStringsManager(); 100 try { 101 verifier.verify(); 102 } catch (Exception e) { 103 LogRecord logRecord = new LogRecord (Level.SEVERE, 104 smh.getLocalString( 105 verifier.getClass().getName() + 106 ".verifyFailed", "Could not verify successfully.")); logRecord.setThrown(e); 109 verifier.frameworkContext.getResultManager().log(logRecord); 110 } 111 verifier.generateReports(); 112 int failedCount = verifier.frameworkContext.getResultManager() 113 .getFailedCount() + 114 verifier.frameworkContext.getResultManager().getErrorCount(); 115 if (failedCount != 0) 116 System.exit(failedCount); 117 } 118 } 119 120 126 private ResultManager verify() throws IOException { 127 VerificationHandler verificationHandler = 128 new VerificationHandler(frameworkContext); 129 ResultManager resultManager; 130 try { 131 resultManager = verificationHandler.verifyArchive(); 132 } finally { 133 verificationHandler.cleanup(); 134 } 135 return resultManager; 136 } 137 138 144 public ResultManager verify(String jarFile) throws IOException { 145 frameworkContext.setJarFileName(jarFile); 146 return verify(); 147 } 148 149 159 public int verify(Application application, 160 AbstractArchive abstractArchive, 161 List <String > classPath, 162 File jspOutDir) 163 throws IOException { 164 boolean originalBoundsChecking = Descriptor.isBoundsChecking(); 165 Descriptor.setBoundsChecking(false); 166 ResultManager rmanager=null; 167 frameworkContext.setJspOutDir(jspOutDir); 168 frameworkContext.setIsBackend(true); 169 VerificationHandler verificationHandler = null; 170 try { 171 if(application == null) { frameworkContext.setJarFileName(abstractArchive.getArchiveUri()); 173 verificationHandler = new VerificationHandler(frameworkContext); 174 } else 175 verificationHandler = new VerificationHandler(frameworkContext, 176 application, 177 abstractArchive, 178 classPath); 179 rmanager = verificationHandler.verifyArchive(); 180 } catch(Exception e) { 181 LocalStringManagerImpl smh = StringManagerHelper.getLocalStringsManager(); 182 LogRecord logRecord = 183 new LogRecord (Level.SEVERE, 184 smh.getLocalString(getClass().getName() + 185 ".verifyFailed", "Could not verify successfully.")); logRecord.setThrown(e); 188 frameworkContext.getResultManager().log(logRecord); 189 } finally { Descriptor.setBoundsChecking(originalBoundsChecking); 191 if(verificationHandler!=null) 192 verificationHandler.cleanup(); 193 } 194 generateReports(); 195 return rmanager.getErrorCount() + rmanager.getFailedCount(); 196 } 197 198 203 public void generateReports() throws IOException { 204 new ReportHandler(frameworkContext).generateAllReports(); 205 } 206 207 211 public static boolean isDebug() { 212 return debug; 213 } 214 215 219 public static void debug(Throwable t) { 220 logger.log(Level.FINEST, "Exception occurred", t); 221 } 222 } 223 | Popular Tags |