1 /* CallTest.java */
2
3 package org.quilt.frontend.ant;
4
5 import org.apache.tools.ant.AntClassLoader;
6 import org.apache.tools.ant.BuildException;
7 import org.apache.tools.ant.Project;
8 import org.apache.tools.ant.Task;
9 import org.apache.tools.ant.taskdefs.Execute;
10 import org.apache.tools.ant.types.CommandlineJava;
11 import org.apache.tools.ant.types.EnumeratedAttribute;
12 import org.apache.tools.ant.types.Environment;
13 import org.apache.tools.ant.types.Path;
14
15 import java.io.File;
16
17 import java.util.Enumeration;
18 import java.util.Hashtable;
19 import java.util.Properties;
20
21 import org.quilt.cl.QuiltClassLoader;
22 import org.quilt.framework.*;
23 import org.quilt.reports.*;
24 import org.quilt.runner.*;
25
26 /***
27 * Handles an individual QuiltTest suite by directly calling it
28 * rather than forking it.
29 */
30 public class CallTest {
31 private Project project = null;
32 private Task task = null;
33 private TaskControl tc = null;
34 private QuiltTest qt = null;
35
36 private CommandlineJava cmdLine = null;
37 private Runner runner;
38
39 /*** No-arg constructor. */
40 public CallTest() { }
41
42 /***
43 * Run the test suite in this Java virtual machine.
44 *
45 * @param test Data structure describing the individual test.
46 * @param tc Task control which sets parameters for the entire run.
47 */
48 protected int execTest (QuiltTest test, TaskControl tc)
49 throws BuildException {
50 // structure gets altered during the test run, so needs to be
51 // cloned
52 QuiltTest qt = (QuiltTest) test.clone();
53 this.tc = tc;
54 task = tc.getTask();
55 project = task.getProject();
56
57 boolean usingQuilt = (tc.getLoader() != null)
58 && qt.getCheckCoverage() && qt.getCheckIncludes() != null;
59
60 cmdLine = (CommandlineJava) tc.getCommandline().clone();
61 qt.setProperties(project.getProperties());
62 if (tc.getDir() != null) {
63 task.log(
64 "Dir attribute ignored, running in the same virtual machine",
65 Project.MSG_WARN);
66 }
67 if (tc.getNewEnvironment() || null != tc.getEnv().getVariables()) {
68 task.log( "Changes to environment variables are ignored, "
69 + "running in the same virtual machine.", Project.MSG_WARN);
70 }
71
72 CommandlineJava.SysProperties sysProperties =
73 cmdLine.getSystemProperties();
74 if (sysProperties != null) {
75 sysProperties.setSystem();
76 }
77 AntClassLoader antLoader = null;
78 QuiltClassLoader quiltLoader = tc.getLoader();
79 try {
80 task.log("Using System properties " + System.getProperties(),
81 Project.MSG_VERBOSE);
82 Path userClasspath = cmdLine.getClasspath();
83 Path classpath = userClasspath == null ?
84 null : (Path) userClasspath.clone();
85 if (usingQuilt) {
86 String pathForQuilt
87 = (classpath == null) ? null : classpath.toString();
88 quiltLoader.setClassPath(pathForQuilt);
89 quiltLoader.setIncluded(qt.getCheckIncludes());
90 quiltLoader.setExcluded(qt.getCheckExcludes());
91 } else if (classpath != null) {
92 // XXX either document the fact that this option isn't
93 // supported with Quilt - or support it
94 if (tc.getIncludeAntRuntime()) {
95 task.log("Adding " + tc.getAntRuntimeClasses()
96 + " to CLASSPATH", Project.MSG_VERBOSE);
97 classpath.append(tc.getAntRuntimeClasses());
98 }
99
100 antLoader = new AntClassLoader(null, project,
101 classpath, false);
102 task.log("Using CLASSPATH " + antLoader.getClasspath(),
103 Project.MSG_VERBOSE);
104
105 antLoader.addSystemPackageRoot("junit");
106 }
107 if (usingQuilt) {
108 // // DEBUG
109 // System.out.println(
110 // "CallTest invoking BaseTestRunner with classpath "
111 // + classpath);
112 // // END
113 runner = new BaseTestRunner(qt, quiltLoader);
114 } else {
115 runner = new BaseTestRunner(qt, antLoader);
116 }
117 if (tc.getSummary()) {
118 task.log("Running " + qt.getName(), Project.MSG_INFO);
119
120 SummaryFormatter fmt = new SummaryFormatter();
121 fmt.setWithOutAndErr("withoutanderr"
122 .equals(tc.getSummaryValue()));
123 fmt.setOutput(tc.getDefaultOutput());
124 runner.addFormatter(fmt);
125 }
126
127 final FmtSelector[] selectors = tc.mergeSelectors(qt);
128 for (int i = 0; i < selectors.length; i++) {
129 FmtSelector fs = selectors[i];
130 File outFile = tc.getOutput(fs, qt);
131 if (outFile != null) {
132 fs.setOutfile(outFile);
133 } else {
134 fs.setOutput(tc.getDefaultOutput());
135 }
136 runner.addFormatter(fs.createFormatter());
137 }
138 runner.run();
139 return runner.getRetCode();
140
141 } finally{
142 if (sysProperties != null) {
143 sysProperties.restoreSystem();
144 }
145 if (antLoader != null) {
146 antLoader.resetThreadContextLoader();
147 }
148 }
149 }
150 }
This page was automatically generated by Maven