1 2 3 package org.quilt.textui; 4 5 import java.io.File ; 6 import java.io.FileInputStream ; 7 import java.io.IOException ; 8 import java.util.Enumeration ; 9 import java.util.Hashtable ; 10 import java.util.Properties ; 11 import java.util.Vector ; 12 13 import org.apache.tools.ant.BuildException; 15 import org.apache.tools.ant.Project; 16 17 import org.quilt.cl.QuiltClassLoader; 18 import org.quilt.cover.stmt.StmtRegistry; 19 import org.quilt.framework.QuiltTest; 20 import org.quilt.reports.*; 21 import org.quilt.runner.*; 22 23 29 30 public abstract class Textui implements RunnerConst { 31 32 protected QuiltClassLoader quiltLoader = null; 33 34 protected StmtRegistry stmtReg = null; 35 36 40 45 public void usage () { 46 System.out.println ("usage:\n" 47 + "java [javaOptions] testName [testOptions]\n" 48 + "where the test options (all optional) are\n" 49 + " checkCoverage={true|false}\n" 50 + " checkIncludes={comma-separated list of class names}\n" 51 + " checkExcludes={comma-separated list of class names}\n" 52 + " haltOnError={true|false}\n" 53 + " haltOnFailure={true|false}\n" 54 + " filtertrace={true|false}\n" 55 + " formatter={className[,outputName]}\n" 56 + " propsfile={pathname}\n" 57 + " showOutput={true|false}\n" 58 + "Parameter values are not quoted. Anything in square brackets []\n" 59 + "is optional. Anything in curly braces {} is required.\n" 60 + "\n"); 61 System.exit(ERRORS); 62 } 63 64 69 78 protected int handleArgs (String [] args) { 79 int retCode = ERRORS; 80 try { 81 Vector myFormatters = new Vector (); 82 if (args.length == 0) { 83 usage(); 84 } 85 QuiltTest qt = new QuiltTest(args[0]); 87 qt.setFork(true); 89 Properties p = new Properties (); 90 for (int i = 1; i < args.length; i++) { 91 if (args[i].startsWith("checkCoverage=")) { 92 qt.setCheckCoverage ( 93 Project.toBoolean(args[i].substring(14))); 94 } else if (args[i].startsWith("checkExcludes=")) { 95 qt.setCheckExcludes (args[i].substring(14)); 96 } else if (args[i].startsWith("checkIncludes=")) { 97 qt.setCheckIncludes (args[i].substring(14)); 98 } else if (args[i].startsWith("haltOnError=")) { 99 qt.setHaltOnError ( 100 Project.toBoolean(args[i].substring(12))); 101 } else if (args[i].startsWith("haltOnFailure=")) { 102 qt.setHaltOnFailure ( 103 Project.toBoolean(args[i].substring(14))); 104 } else if (args[i].startsWith("filtertrace=")) { 105 qt.setFiltertrace ( 106 Project.toBoolean(args[i].substring(12))); 107 } else if (args[i].startsWith("formatter=")) { 108 110 try { 115 String selector = args[i].substring(10); 116 int commaAt = selector.indexOf(','); 117 FmtSelector fs = new FmtSelector(); 118 if ( commaAt < 0) { 119 fs.setClassname (selector); 120 } else { 121 fs.setClassname (selector.substring(0, commaAt)); 122 fs.setOutfile (new File ( 123 selector.substring(commaAt + 1))); 124 } 125 myFormatters.addElement ( fs ); 126 } catch (BuildException be) { 127 System.err.println(be.getMessage()); 128 System.exit(ERRORS); 129 } 130 } else if (args[i].startsWith("propsfile=")) { 131 FileInputStream in = new FileInputStream (args[i] 132 .substring(10)); 133 p.load(in); 134 in.close(); 135 } else if (args[i].startsWith("showoutput=")) { 136 qt.setShowOutput (Project.toBoolean(args[i].substring(11))); 137 } 138 } 139 Hashtable sysP = System.getProperties(); 140 Enumeration e = sysP.keys(); 141 while ( e.hasMoreElements()) { 142 String key = (String )e.nextElement(); 143 p.put(key, (String )sysP.get(key)); 144 } 145 qt.setProperties(p); 146 154 161 if (qt.getCheckCoverage() && (qt.getCheckIncludes() != null)) { 162 String myClasspath = System.getProperty("java.class.path"); 163 quiltLoader = new QuiltClassLoader ( 169 QuiltClassLoader.cpToURLs(myClasspath), 170 (ClassLoader )null, (String [])null, qt.getCheckIncludesArray(), qt.getCheckExcludesArray()); 175 stmtReg = (StmtRegistry) quiltLoader.addQuiltRegistry( 176 "org.quilt.cover.stmt.StmtRegistry"); 177 } 178 185 retCode = runWithIt (qt, myFormatters); 186 } catch (Exception e) { 187 System.out.println("EXCEPTION " + e); 188 e.printStackTrace(); 189 retCode = ERRORS; 190 } 191 return retCode; 192 } 193 198 int runWithIt (QuiltTest qt, Vector myFormatters) { 199 System.out.println ( 201 "Textui.runWithIt: you should never see this message"); 202 return ERRORS; 203 } 204 } 205 | Popular Tags |