1 23 package org.apache.tools.ant.taskdefs.optional.sun.verification; 24 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.types.Commandline; 27 import org.apache.tools.ant.taskdefs.Java; 28 import org.apache.tools.ant.taskdefs.ExecTask; 29 30 import java.io.File ; 31 import java.util.StringTokenizer ; 32 import java.util.ArrayList ; 33 import java.util.List ; 34 35 53 public class StaticArchiveTest extends AVKTasks { 54 55 private File appName = null; 56 private String partitionOpts = null; 57 private String reportingOpts = null; 58 59 public void setAppName(File appName) { 60 this.appName = appName; 61 } 62 63 public void setPartitionOpts(String partitionOpts) { 64 this.partitionOpts = partitionOpts; 65 } 66 67 public void setReportingOpts(String reportingOpts) { 68 this.reportingOpts = reportingOpts; 69 } 70 public void setResultDir(String resultDir) { 72 super.setResultDir(resultDir); 73 } 74 75 79 public void execute() throws BuildException { 80 81 checkArgs(); 82 getInstallHomes(); 83 invokeVerifier(); 84 85 if(invokeGenReportTool(createJavaTask()) != 0 && failOnError) 86 throw new BuildException("Problem in executing GenReportTool command"); 87 88 echo.setMessage("See \""+resultDir+File.separator+"verifierSummary.html\" for results."); 89 echo.execute(); 90 } 91 92 95 private void invokeVerifier() { 96 ExecTask exec = (ExecTask)project.createTask("exec"); 97 String argument = ""; 98 if(partitionOpts != null) 100 argument = addPartitionOptions(); 101 if ((reportingOpts == null) || (reportingOpts.equals(""))) 103 argument += " -rw"; 104 else { if ( reportingOpts.equals("f") || reportingOpts.equals("w") 106 || reportingOpts.equals("a") ) 107 argument += " -r"+reportingOpts; 108 else 109 throw new BuildException("Provide a valid reporting option. " + 110 "Valid options are [f, w, a] "); 111 } 112 createResultDir("static"); 113 argument += " -d "+resultDir; 115 argument += " -R"; 117 argument += " "+appName.getAbsolutePath(); 119 120 Commandline.Argument arg = exec.createArg(); 121 arg.setLine(argument); 122 exec.setExecutable(j2ee_home+"/bin/verifier"); 123 exec.setDir(new File (j2ee_home,"bin")); 124 exec.setVMLauncher(false); 125 exec.setFailonerror(false); 128 exec.execute(); 129 } 130 131 135 private int invokeGenReportTool(Java java) { 136 List <String > list = new ArrayList <String >(); 137 138 list.add(resultDir + File.separator + appName.getName() + ".xml"); 139 list.add(resultDir); 140 String [] xsls = {"verifierSummary", "appFailureDetail", "appPassedDetail", 141 "appWarningDetail", "appNADetail", "ejbFailureDetail", 142 "ejbPassedDetail", "ejbWarningDetail", "ejbNADetail", 143 "acFailureDetail", "acPassedDetail", "acWarningDetail", 144 "acNADetail", "conFailureDetail", "conPassedDetail", 145 "conWarningDetail", "conNADetail", "errFailureDetail", 146 "webFailureDetail", "webPassedDetail", "webWarningDetail", 147 "webNADetail"}; 148 for (int i = 0; i < xsls.length; i++) 149 list.add(xsls[i]); 150 String [] args = (String [])list.toArray(new String [1]); 151 152 java.clearArgs(); 154 java.setClassname("com.sun.enterprise.appverification.tools.GenReportTool"); 155 setArgs(java, args); 156 157 return java.executeJava(); 158 } 159 160 164 private String addPartitionOptions() { 165 StringTokenizer options = new StringTokenizer (partitionOpts, ","); 166 String args = ""; 167 while(options.hasMoreTokens()) { 168 String option = options.nextToken().trim(); 169 if(!(option.equals("ejb") || 170 option.equals("web") || 171 option.equals("webservices") || 172 option.equals("connector") || 173 option.equals("app") || 174 option.equals("appclient") || 175 option.equals("webservicesclient"))) 176 throw new BuildException("Provide a valid parititioning option. " + 177 "Valid options are [ejb, web, app, webservices, " + 178 "webservicesclient, connector, appclient]"); 179 args += " --"+option; 180 } 181 return args; 182 } 183 184 private void checkArgs() throws BuildException { 185 if(appName == null || !appName.exists()) 186 throw new BuildException("Provide a valid fully qualified " + 187 "path of the application: appName="+appName); 188 } 189 } 190 | Popular Tags |