001: package csdl.jblanket.ant;
002:
003: import csdl.jblanket.modifier.MethodCollector;
004:
005: import java.io.File;
006: import java.util.ArrayList;
007:
008: /**
009: * Implements the JBlanket Apache Ant task definition that launches the application to exclude
010: * individual methods. The system covered is displayed as a tree, with methods as the leaves. The
011: * Font used to display each method is altered to reflect the category of the method, e.g., tested,
012: * untested, one-line, etc. Methods chosen to be excluded by the user within this application are
013: * stored in the directory specified by the jblanket.dir system property. If not set, the default
014: * directory is <user_home>/<user_account>/jblanket/.
015: * <p>
016: * <b>Required</b> nested element for the application task:
017: * <ul>
018: * <p>
019: * None.
020: * </ul>
021: * <p>
022: * <b>Optional</b> nested element for the application task:
023: * <ul>
024: * <p>
025: * 'sysproperty' - describes additional system properties not set in the environment. If
026: * jblanket.dir is not set as an environment variable, include this nested element
027: * to set it.
028: * <i>For example</i>: see <a href="http://jakarta.apache.org/ant/manual/index.html">Ant</a>
029: * </ul>
030: * <p>
031: * <b>Required</b> attribute for the application task:
032: * <ul>
033: * <p>
034: * None.
035: * </ul>
036: * <p>Optional</b> attributes for the application task:
037: * <ul>
038: * <p>
039: * 'enable' - describes if the application should be launched. Valid values include "true", "on",
040: * "yes" to launch the application or "false", "off", or "no" to not launch the
041: * application.
042: * <i>For example</i>: enable="true"
043: * <p>
044: * 'verbose' - describes if additional output should be sent to standard out.
045: * Valid values include "true", "on", "yes" for additional output
046: * or "false", "off", or "no" for no additional output.<br>
047: * <i>For example</i>: verbose="false"
048: * <p>
049: * 'excludeonelinemethods' - describes if methods with one line of code were excluded from coverage.
050: * Values include "true", "on", "yes" to identify the one-line methods
051: * or "false", "off", or "no" to not identify them.<br>
052: * <i>For example</i>: excludeonelinemethods="false"
053: * <p>
054: * 'excludeconstructors' - describes if constructors were excluded from coverage. Values include
055: * "true", "on", "yes" to identify constructors or "false", "off",
056: * or "no" to not identify them.<br>
057: * <i>For example</i>: excludeconstructors="false"
058: * <p>
059: * 'onelinefile' - name of XML file containing all one-line methods<br>
060: * <i>For example</i>: onelinefile="oneLineMethods.xml"
061: * <p>
062: * 'constructorfile' - name of XML file containing all cosntructors<br>
063: * <i>For example</i>: constructorfile="constructorsMethods.xml"
064: * <p>
065: * 'excludedindividualfile' - name of XML file to contain/containing all individually excluded
066: * methods<br>
067: * <i>For example</i>: excludedindividualfile="excludedIndividualMethods.xml"
068: * </ul>
069: * <p>
070: * If any of the optional attributes are not specified, their default values specified in the
071: * examples are used. For example, to distinguish methods with one line of source code from the
072: * coverage measurement, specify the 'excludeonelinemethods' attribute with a 'true' value.
073: * When not specified, one-line methods will not be distinguished in the application.
074: * <p>
075: * Use this class to execute JBlanket with Ant. One example of the 'jblanketapp' Ant target is:
076: * <pre>
077: * <taskdef name="jblanketapp" classname="csdl.jblanket.ant.JBlanketAppTask"/>
078: * <jblanketapp>
079: * <sysproperty key="jblanket.dir" value="$jblanket.dir" />
080: * </jblanketapp>
081: * </pre>
082: * From the example, only tested and untested methods from the files found in jblanket.dir are
083: * distinguished. No additional output will be sent to standard out.
084: * <p>
085: * Another example is:
086: * <pre>
087: * <jblanketapp excludeonelinemethods="true"
088: * verbose="true" />
089: * </pre>
090: * where one-line methods are distinguished, but constructors are not. Additional output will be
091: * sent to standard out.
092: * <p>
093: * Individually excluded methods are always identified. Only the file in which they are stored can
094: * be changed.
095: * <p>
096: * NOTE: For JBlanket to successfully launch the application, all related files MUST exist in
097: * jblanket.dir.
098: *
099: * @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
120: .println("jblanketapp disabled; application was not launched.");
121: }
122: return;
123: }
124: // Format JBlanketApp arguments.
125: ArrayList argsList = new ArrayList();
126:
127: // format the required arguments
128: argsList.add("java");
129: argsList.add("-D\"jblanket.dir\"="
130: + MethodCollector.getJBlanketDir());
131:
132: // add classpath
133: argsList.add("-classpath");
134: String slash = File.separator;
135: String antLib = System.getProperty("ant.home") + slash + "lib"
136: + slash;
137: String classPath = ".;" + antLib + "jblanket.jar;" + antLib
138: + "jdom.jar;" + antLib + "xerces.jar";
139: argsList.add(classPath);
140: argsList.add("csdl.jblanket.app.ExcludeIndividualMethodApp");
141:
142: // add verbose
143: argsList.add("-verbose");
144: argsList.add(new Boolean(super .verbose).toString());
145:
146: // add oneLineFile if user specified
147: if (super .excludeOneLineMethods) {
148: argsList.add("-excludeOneLineMethods");
149: argsList.add(new Boolean(super .excludeOneLineMethods)
150: .toString());
151: if (super .oneLineFile != null) {
152: argsList.add("-oneLineFile");
153: argsList.add(super .oneLineFile);
154: }
155: }
156:
157: // add contructorFile if user specified
158: if (super .excludeConstructors) {
159: argsList.add("-excludeConstructors");
160: argsList.add(new Boolean(super .excludeConstructors)
161: .toString());
162: if (super .constructorFile != null) {
163: argsList.add("-constructorFile");
164: argsList.add(super .constructorFile);
165: }
166: }
167:
168: // add excludedIndividualFile if user specified
169: if (super .excludedIndividualFile != null) {
170: argsList.add("-excludedIndividualFile");
171: argsList.add(super .excludedIndividualFile);
172: }
173:
174: // add total tested and untested methods
175: argsList.add("-total.testedFile");
176: argsList.add("-total.untestedFile");
177:
178: String[] args = (String[]) argsList.toArray(new String[argsList
179: .size()]);
180:
181: //TODO write out Exceptions to a Log, and print error messages to the screen
182: Runtime runtime = Runtime.getRuntime();
183: try {
184: runtime.exec(args);
185: } catch (Exception e) {
186: e.printStackTrace();
187: }
188: }
189: }
|