KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > csdl > jblanket > ant > JBlanketAppTask


1 package csdl.jblanket.ant;
2
3 import csdl.jblanket.modifier.MethodCollector;
4
5 import java.io.File JavaDoc;
6 import java.util.ArrayList JavaDoc;
7
8 /**
9  * Implements the JBlanket Apache Ant task definition that launches the application to exclude
10  * individual methods. The system covered is displayed as a tree, with methods as the leaves. The
11  * Font used to display each method is altered to reflect the category of the method, e.g., tested,
12  * untested, one-line, etc. Methods chosen to be excluded by the user within this application are
13  * stored in the directory specified by the jblanket.dir system property. If not set, the default
14  * directory is <user_home>/<user_account>/jblanket/.
15  * <p>
16  * <b>Required</b> nested element for the application task:
17  * <ul>
18  * <p>
19  * None.
20  * </ul>
21  * <p>
22  * <b>Optional</b> nested element for the application task:
23  * <ul>
24  * <p>
25  * 'sysproperty' - describes additional system properties not set in the environment. If
26  * jblanket.dir is not set as an environment variable, include this nested element
27  * to set it.
28  * <i>For example</i>: see <a HREF="http://jakarta.apache.org/ant/manual/index.html">Ant</a>
29  * </ul>
30  * <p>
31  * <b>Required</b> attribute for the application task:
32  * <ul>
33  * <p>
34  * None.
35  * </ul>
36  * <p>Optional</b> attributes for the application task:
37  * <ul>
38  * <p>
39  * 'enable' - describes if the application should be launched. Valid values include "true", "on",
40  * "yes" to launch the application or "false", "off", or "no" to not launch the
41  * application.
42  * <i>For example</i>: enable="true"
43  * <p>
44  * 'verbose' - describes if additional output should be sent to standard out.
45  * Valid values include "true", "on", "yes" for additional output
46  * or "false", "off", or "no" for no additional output.<br>
47  * <i>For example</i>: verbose="false"
48  * <p>
49  * 'excludeonelinemethods' - describes if methods with one line of code were excluded from coverage.
50  * Values include "true", "on", "yes" to identify the one-line methods
51  * or "false", "off", or "no" to not identify them.<br>
52  * <i>For example</i>: excludeonelinemethods="false"
53  * <p>
54  * 'excludeconstructors' - describes if constructors were excluded from coverage. Values include
55  * "true", "on", "yes" to identify constructors or "false", "off",
56  * or "no" to not identify them.<br>
57  * <i>For example</i>: excludeconstructors="false"
58  * <p>
59  * 'onelinefile' - name of XML file containing all one-line methods<br>
60  * <i>For example</i>: onelinefile="oneLineMethods.xml"
61  * <p>
62  * 'constructorfile' - name of XML file containing all cosntructors<br>
63  * <i>For example</i>: constructorfile="constructorsMethods.xml"
64  * <p>
65  * 'excludedindividualfile' - name of XML file to contain/containing all individually excluded
66  * methods<br>
67  * <i>For example</i>: excludedindividualfile="excludedIndividualMethods.xml"
68  * </ul>
69  * <p>
70  * If any of the optional attributes are not specified, their default values specified in the
71  * examples are used. For example, to distinguish methods with one line of source code from the
72  * coverage measurement, specify the 'excludeonelinemethods' attribute with a 'true' value.
73  * When not specified, one-line methods will not be distinguished in the application.
74  * <p>
75  * Use this class to execute JBlanket with Ant. One example of the 'jblanketapp' Ant target is:
76  * <pre>
77  * &lt;taskdef name="jblanketapp" classname="csdl.jblanket.ant.JBlanketAppTask"/&gt;
78  * &lt;jblanketapp&gt;
79  * &lt;sysproperty key="jblanket.dir" value="$jblanket.dir" /&gt;
80  * &lt;/jblanketapp&gt;
81  * </pre>
82  * From the example, only tested and untested methods from the files found in jblanket.dir are
83  * distinguished. No additional output will be sent to standard out.
84  * <p>
85  * Another example is:
86  * <pre>
87  * &lt;jblanketapp excludeonelinemethods="true"
88  * verbose="true" /&gt;
89  * </pre>
90  * where one-line methods are distinguished, but constructors are not. Additional output will be
91  * sent to standard out.
92  * <p>
93  * Individually excluded methods are always identified. Only the file in which they are stored can
94  * be changed.
95  * <p>
96  * NOTE: For JBlanket to successfully launch the application, all related files MUST exist in
97  * jblanket.dir.
98  *
99  * @author Joy M. Agustin
100  * @version $Id: JBlanketAppTask.java,v 1.1 2004/11/07 00:32:33 timshadel Exp $
101  */

102 public class JBlanketAppTask extends JBlanketTask {
103
104   /**
105    * Constructs a new JBlanketAppTask object.
106    */

107   public JBlanketAppTask() {
108     super();
109   }
110
111   /**
112    * Executes the application for excluding individual methods Ant taskdef.
113    */

114   public void execute() {
115     
116     // Return without launching application if jblanketapp is disabled.
117
if (!super.enable) {
118       if (super.verbose) {
119         System.out.println("jblanketapp disabled; application was not launched.");
120       }
121       return;
122     }
123     // Format JBlanketApp arguments.
124
ArrayList JavaDoc argsList = new ArrayList JavaDoc();
125     
126     // format the required arguments
127
argsList.add("java");
128     argsList.add("-D\"jblanket.dir\"=" + MethodCollector.getJBlanketDir());
129
130     // add classpath
131
argsList.add("-classpath");
132     String JavaDoc slash = File.separator;
133     String JavaDoc antLib = System.getProperty("ant.home") + slash + "lib" + slash;
134     String JavaDoc classPath = ".;" + antLib + "jblanket.jar;" + antLib + "jdom.jar;"
135                        + antLib + "xerces.jar";
136     argsList.add(classPath);
137     argsList.add("csdl.jblanket.app.ExcludeIndividualMethodApp");
138     
139     // add verbose
140
argsList.add("-verbose");
141     argsList.add(new Boolean JavaDoc(super.verbose).toString());
142
143     // add oneLineFile if user specified
144
if (super.excludeOneLineMethods) {
145       argsList.add("-excludeOneLineMethods");
146       argsList.add(new Boolean JavaDoc(super.excludeOneLineMethods).toString());
147       if (super.oneLineFile != null) {
148         argsList.add("-oneLineFile");
149         argsList.add(super.oneLineFile);
150       }
151     }
152     
153     // add contructorFile if user specified
154
if (super.excludeConstructors) {
155       argsList.add("-excludeConstructors");
156       argsList.add(new Boolean JavaDoc(super.excludeConstructors).toString());
157       if (super.constructorFile != null) {
158         argsList.add("-constructorFile");
159         argsList.add(super.constructorFile);
160       }
161     }
162     
163     // add excludedIndividualFile if user specified
164
if (super.excludedIndividualFile != null) {
165       argsList.add("-excludedIndividualFile");
166       argsList.add(super.excludedIndividualFile);
167     }
168     
169     // add total tested and untested methods
170
argsList.add("-total.testedFile");
171     argsList.add("-total.untestedFile");
172     
173     String JavaDoc[] args = (String JavaDoc[]) argsList.toArray(new String JavaDoc[argsList.size()]);
174     
175     //TODO write out Exceptions to a Log, and print error messages to the screen
176
Runtime JavaDoc runtime = Runtime.getRuntime();
177     try {
178       runtime.exec(args);
179     }
180     catch (Exception JavaDoc e) {
181       e.printStackTrace();
182     }
183   }
184 }
185
Popular Tags