KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > sun > verification > StaticArchiveTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

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 JavaDoc;
31 import java.util.StringTokenizer JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.List JavaDoc;
34
35 /**
36  * This is the implementation for verifier invocation through Ant task.
37  * This task runs the following two classses -
38  * Invokes Verifier by passing the appropriate arguments,
39  * Invokes the GenReportTool class to generate the reports.
40  * <p>
41  * The attributes of this task are: <br>
42  * appName ="REQUIRED" <br>
43  * partitionOpts ="OPTIONAL" <br>
44  * jvmArgs ="OPTIONAL" (default: "Xss512k -Xms128m -Xmx256m") <br>
45  * failOnError="OPTIONAL" (default: true) <br>
46  * <p>
47  *
48  * These tasks require javke-ant.jar and sunone-appserv-ant.jar to be in
49  * AVK_HOME/lib and APPSERVER_HOME/lib diroctries respectively.
50  *
51  * @author Vikas Awasthi.
52  */

53 public class StaticArchiveTest extends AVKTasks {
54     
55     private File JavaDoc appName = null;
56     private String JavaDoc partitionOpts = null;
57     private String JavaDoc reportingOpts = null;
58
59     public void setAppName(File JavaDoc appName) {
60         this.appName = appName;
61     }
62
63     public void setPartitionOpts(String JavaDoc partitionOpts) {
64         this.partitionOpts = partitionOpts;
65     }
66
67     public void setReportingOpts(String JavaDoc reportingOpts) {
68     this.reportingOpts = reportingOpts;
69     }
70     // this api will not be documented. It is used by CTS.
71
public void setResultDir(String JavaDoc resultDir) {
72         super.setResultDir(resultDir);
73     }
74
75     /**
76      * This is called by the ant framework.
77      * @throws BuildException
78      */

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     /**
93      * Invokes the com.sun.enterprise.tools.verifier.Verifier
94      */

95     private void invokeVerifier() {
96         ExecTask exec = (ExecTask)project.createTask("exec");
97         String JavaDoc argument = "";
98         //adding the partitioning options
99
if(partitionOpts != null)
100             argument = addPartitionOptions();
101         //adding the fail/warning reporting option
102
if ((reportingOpts == null) || (reportingOpts.equals("")))
103             argument += " -rw";
104         else {// check for valid options a, w and f
105
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         //adding the result directory option
114
argument += " -d "+resultDir;
115         //do not run the runtime tests
116
argument += " -R";
117         // finally adding the application name in the options
118
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 JavaDoc(j2ee_home,"bin"));
124         exec.setVMLauncher(false);
125         //the exit status is non-zero if any assertion failed but
126
// we want to continue to invokeGenReportTool
127
exec.setFailonerror(false);
128         exec.execute();
129     }
130     
131     /**
132      * Invokes the com.sun.enterprise.appverification.tools.GenReportTool
133      * @return integer denoting the return status of the command. 1 is failure
134      */

135     private int invokeGenReportTool(Java java) {
136         List JavaDoc<String JavaDoc> list = new ArrayList JavaDoc<String JavaDoc>();
137         
138         list.add(resultDir + File.separator + appName.getName() + ".xml");
139         list.add(resultDir);
140         String JavaDoc[] 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 JavaDoc[] args = (String JavaDoc[])list.toArray(new String JavaDoc[1]);
151
152         // clear the args set in the invokeVerifier call.
153
java.clearArgs();
154         java.setClassname("com.sun.enterprise.appverification.tools.GenReportTool");
155         setArgs(java, args);
156
157         return java.executeJava();
158     }
159
160     /**
161      * Parse and add the partitioning options. It add "--" to the options.
162      * @return List
163      */

164     private String JavaDoc addPartitionOptions() {
165         StringTokenizer JavaDoc options = new StringTokenizer JavaDoc(partitionOpts, ",");
166         String JavaDoc args = "";
167         while(options.hasMoreTokens()) {
168             String JavaDoc 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