diff -urN old/PRTI/bin/agents/runClasslib.sh new/PRTI/bin/agents/runClasslib.sh --- old/PRTI/bin/agents/runClasslib.sh 2007-07-09 14:22:38.762398300 +0700 +++ new/PRTI/bin/agents/runClasslib.sh 2007-07-10 12:16:39.862302000 +0700 @@ -45,9 +45,10 @@ exit 1 fi +export CLASSPATH="${BIN_DIR}/lib/PRTIJUnitTestRunner.jar${CPATH_DELIM}${ANT_HOME}/lib/ant-junit.jar" export ANT_OPTS="${GENERAL_VM_OPTIONS}" export ANT_CMD="${ANT_HOME}/bin/ant" -export ANT_PARAMS="-lib ${BIN_DIR}/lib/PRTIJUnitTestRunner.jar" +export ANT_PARAMS= export ANT_TARGET="test" export ANT_TARGET_PARAMS="-Dtest.jre.home=${RUNTIME_DIR} -Dhy.performance=${PERFORMANCE}" diff -urN old/PRTI/setup/src/PRTIJUnitTestRunner/JUnitTask.java new/PRTI/setup/src/PRTIJUnitTestRunner/JUnitTask.java --- old/PRTI/setup/src/PRTIJUnitTestRunner/JUnitTask.java 2007-06-27 17:06:22.063915200 +0700 +++ new/PRTI/setup/src/PRTIJUnitTestRunner/JUnitTask.java 1970-01-01 06:00:00.000000000 +0600 @@ -1,1796 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.taskdefs.optional.junit; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.lang.reflect.Constructor; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Vector; - -import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.taskdefs.Execute; -import org.apache.tools.ant.taskdefs.ExecuteWatchdog; -import org.apache.tools.ant.taskdefs.LogOutputStream; -import org.apache.tools.ant.taskdefs.PumpStreamHandler; -import org.apache.tools.ant.types.Assertions; -import org.apache.tools.ant.types.Commandline; -import org.apache.tools.ant.types.CommandlineJava; -import org.apache.tools.ant.types.EnumeratedAttribute; -import org.apache.tools.ant.types.Environment; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.Permissions; -import org.apache.tools.ant.types.PropertySet; -import org.apache.tools.ant.util.FileUtils; -import org.apache.tools.ant.util.LoaderUtils; - - -/** - * Runs JUnit tests. - * - *
JUnit is a framework to create unit tests. It has been initially - * created by Erich Gamma and Kent Beck. JUnit can be found at http://www.junit.org. - * - *
JUnitTask can run a single specific
- * JUnitTest using the test element.
- * <target name="test-int-chars" depends="jar-test">
- * <echo message="testing international characters"/>
- * <junit printsummary="no" haltonfailure="yes" fork="false">
- * <classpath refid="classpath"/>
- * <formatter type="plain" usefile="false" />
- * <test name="org.apache.ecs.InternationalCharTest" />
- * </junit>
- * </target>
- *
- * runs a single junit test
- * (org.apache.ecs.InternationalCharTest) in the current
- * VM using the path with id classpath as classpath and
- * presents the results formatted using the standard
- * plain formatter on the command line.
This task can also run batches of tests. The
- * batchtest element creates a BatchTest
- * based on a fileset. This allows, for example, all classes found in
- * directory to be run as testcases.
For example,
- * <target name="run-tests" depends="dump-info,compile-tests" if="junit.present">
- * <junit printsummary="no" haltonfailure="yes" fork="${junit.fork}">
- * <jvmarg value="-classic"/>
- * <classpath refid="tests-classpath"/>
- * <sysproperty key="build.tests" value="${build.tests}"/>
- * <formatter type="brief" usefile="false" />
- * <batchtest>
- * <fileset dir="${tests.dir}">
- * <include name="**/*Test*" />
- * </fileset>
- * </batchtest>
- * </junit>
- * </target>
- *
- * this target finds any classes with a test directory
- * anywhere in their path (under the top ${tests.dir}, of
- * course) and creates JUnitTest's for each one.
Of course, <junit> and
- * <batch> elements can be combined for more
- * complex tests. For an example, see the ant build.xml
- * target run-tests (the second example is an edited
- * version).
To spawn a new Java VM to prevent interferences between
- * different testcases, you need to enable fork. A
- * number of attributes and elements allow you to set up how this JVM
- * runs.
- *
- *
- * @since Ant 1.2
- *
- * @see JUnitTest
- * @see BatchTest
- */
-public class JUnitTask extends Task {
-
- private static final String CLASSPATH = "CLASSPATH=";
- private CommandlineJava commandline;
- private Vector tests = new Vector();
- private Vector batchTests = new Vector();
- private Vector formatters = new Vector();
- private File dir = null;
-
- private Integer timeout = null;
- private boolean summary = false;
- private boolean reloading = true;
- private String summaryValue = "";
- private JUnitTaskMirror.JUnitTestRunnerMirror runner = null;
-
- private boolean newEnvironment = false;
- private Environment env = new Environment();
-
- private boolean includeAntRuntime = true;
- private Path antRuntimeClasses = null;
-
- // Do we send output to System.out/.err in addition to the formatters?
- private boolean showOutput = true;
-
- // Do we send output to the formatters ?
- private boolean outputToFormatters = true;
-
- private File tmpDir;
- private AntClassLoader classLoader = null;
- private Permissions perm = null;
- private ForkMode forkMode = new ForkMode("perTest");
-
- private boolean splitJunit = false;
- private JUnitTaskMirror delegate;
-
- // Attributes for basetest
- private boolean haltOnError = false;
- private boolean haltOnFail = false;
- private boolean filterTrace = true;
- private boolean fork = false;
- private String failureProperty;
- private String errorProperty;
-
- private static final int STRING_BUFFER_SIZE = 128;
- /**
- * @since Ant 1.7
- */
- public static final String TESTLISTENER_PREFIX =
- "junit.framework.TestListener: ";
-
- private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
-
- /**
- * If true, force ant to re-classload all classes for each JUnit TestCase
- *
- * @param value force class reloading for each test case
- */
- public void setReloading(boolean value) {
- reloading = value;
- }
-
- /**
- * If true, smartly filter the stack frames of
- * JUnit errors and failures before reporting them.
- *
- *
This property is applied on all BatchTest (batchtest) and - * JUnitTest (test) however it can possibly be overridden by their - * own properties.
- * @param value false if it should not filter, otherwise - * true - * - * @since Ant 1.5 - */ - public void setFiltertrace(boolean value) { - this.filterTrace = value; - } - - /** - * If true, stop the build process when there is an error in a test. - * This property is applied on all BatchTest (batchtest) and JUnitTest - * (test) however it can possibly be overridden by their own - * properties. - * @param value true if it should halt, otherwise - * false - * - * @since Ant 1.2 - */ - public void setHaltonerror(boolean value) { - this.haltOnError = value; - } - - /** - * Property to set to "true" if there is a error in a test. - * - *This property is applied on all BatchTest (batchtest) and - * JUnitTest (test), however, it can possibly be overriden by - * their own properties.
- * @param propertyName the name of the property to set in the - * event of an error. - * - * @since Ant 1.4 - */ - public void setErrorProperty(String propertyName) { - this.errorProperty = propertyName; - } - - /** - * If true, stop the build process if a test fails - * (errors are considered failures as well). - * This property is applied on all BatchTest (batchtest) and - * JUnitTest (test) however it can possibly be overridden by their - * own properties. - * @param value true if it should halt, otherwise - * false - * - * @since Ant 1.2 - */ - public void setHaltonfailure(boolean value) { - this.haltOnFail = value; - } - - /** - * Property to set to "true" if there is a failure in a test. - * - *This property is applied on all BatchTest (batchtest) and - * JUnitTest (test), however, it can possibly be overriden by - * their own properties.
- * @param propertyName the name of the property to set in the - * event of an failure. - * - * @since Ant 1.4 - */ - public void setFailureProperty(String propertyName) { - this.failureProperty = propertyName; - } - - /** - * If true, JVM should be forked for each test. - * - *It avoids interference between testcases and possibly avoids - * hanging the build. this property is applied on all BatchTest - * (batchtest) and JUnitTest (test) however it can possibly be - * overridden by their own properties.
- * @param value true if a JVM should be forked, otherwise - * false - * @see #setTimeout - * - * @since Ant 1.2 - */ - public void setFork(boolean value) { - this.fork = value; - } - - /** - * Set the behavior when {@link #setFork fork} fork has been enabled. - * - *Possible values are "once", "perTest" and "perBatch". If - * set to "once", only a single Java VM will be forked for all - * tests, with "perTest" (the default) each test will run in a - * fresh Java VM and "perBatch" will run all tests from the same - * <batchtest> in the same Java VM.
- * - *This attribute will be ignored if tests run in the same VM - * as Ant.
- * - *Only tests with the same configuration of haltonerror, - * haltonfailure, errorproperty, failureproperty and filtertrace - * can share a forked Java VM, so even if you set the value to - * "once", Ant may need to fork mutliple VMs.
- * @param mode the mode to use. - * @since Ant 1.6.2 - */ - public void setForkMode(ForkMode mode) { - this.forkMode = mode; - } - - /** - * If true, print one-line statistics for each test, or "withOutAndErr" - * to also show standard output and error. - * - * Can take the values on, off, and withOutAndErr. - * @param value true to print a summary, - * withOutAndErr to include the test's output as - * well, false otherwise. - * @see SummaryJUnitResultFormatter - * - * @since Ant 1.2 - */ - public void setPrintsummary(SummaryAttribute value) { - summaryValue = value.getValue(); - summary = value.asBoolean(); - } - - /** - * Print summary enumeration values. - */ - public static class SummaryAttribute extends EnumeratedAttribute { - /** - * list the possible values - * @return array of allowed values - */ - public String[] getValues() { - return new String[] {"true", "yes", "false", "no", - "on", "off", "withOutAndErr"}; - } - - /** - * gives the boolean equivalent of the authorized values - * @return boolean equivalent of the value - */ - public boolean asBoolean() { - String v = getValue(); - return "true".equals(v) - || "on".equals(v) - || "yes".equals(v) - || "withOutAndErr".equals(v); - } - } - - /** - * Set the timeout value (in milliseconds). - * - *If the test is running for more than this value, the test - * will be canceled. (works only when in 'fork' mode).
- * @param value the maximum time (in milliseconds) allowed before - * declaring the test as 'timed-out' - * @see #setFork(boolean) - * - * @since Ant 1.2 - */ - public void setTimeout(Integer value) { - timeout = value; - } - - /** - * Set the maximum memory to be used by all forked JVMs. - * @param max the value as defined by -mx or -Xmx - * in the java command line options. - * - * @since Ant 1.2 - */ - public void setMaxmemory(String max) { - getCommandline().setMaxmemory(max); - } - - /** - * The command used to invoke the Java Virtual Machine, - * default is 'java'. The command is resolved by - * java.lang.Runtime.exec(). Ignored if fork is disabled. - * - * @param value the new VM to use instead of java - * @see #setFork(boolean) - * - * @since Ant 1.2 - */ - public void setJvm(String value) { - getCommandline().setVm(value); - } - - /** - * Adds a JVM argument; ignored if not forking. - * - * @return create a new JVM argument so that any argument can be - * passed to the JVM. - * @see #setFork(boolean) - * - * @since Ant 1.2 - */ - public Commandline.Argument createJvmarg() { - return getCommandline().createVmArgument(); - } - - /** - * The directory to invoke the VM in. Ignored if no JVM is forked. - * @param dir the directory to invoke the JVM from. - * @see #setFork(boolean) - * - * @since Ant 1.2 - */ - public void setDir(File dir) { - this.dir = dir; - } - - /** - * Adds a system property that tests can access. - * This might be useful to tranfer Ant properties to the - * testcases when JVM forking is not enabled. - * - * @since Ant 1.3 - * @deprecated since ant 1.6 - * @param sysp environment variable to add - */ - public void addSysproperty(Environment.Variable sysp) { - - getCommandline().addSysproperty(sysp); - } - - /** - * Adds a system property that tests can access. - * This might be useful to tranfer Ant properties to the - * testcases when JVM forking is not enabled. - * @param sysp new environment variable to add - * @since Ant 1.6 - */ - public void addConfiguredSysproperty(Environment.Variable sysp) { - // get a build exception if there is a missing key or value - // see bugzilla report 21684 - String testString = sysp.getContent(); - getProject().log("sysproperty added : " + testString, Project.MSG_DEBUG); - getCommandline().addSysproperty(sysp); - } - - /** - * Adds a set of properties that will be used as system properties - * that tests can access. - * - * This might be useful to tranfer Ant properties to the - * testcases when JVM forking is not enabled. - * - * @param sysp set of properties to be added - * @since Ant 1.6 - */ - public void addSyspropertyset(PropertySet sysp) { - getCommandline().addSyspropertyset(sysp); - } - - /** - * Adds path to classpath used for tests. - * - * @return reference to the classpath in the embedded java command line - * @since Ant 1.2 - */ - public Path createClasspath() { - return getCommandline().createClasspath(getProject()).createPath(); - } - - /** - * Adds a path to the bootclasspath. - * @return reference to the bootclasspath in the embedded java command line - * @since Ant 1.6 - */ - public Path createBootclasspath() { - return getCommandline().createBootclasspath(getProject()).createPath(); - } - - /** - * Adds an environment variable; used when forking. - * - *Will be ignored if we are not forking a new VM.
- * @param var environment variable to be added - * @since Ant 1.5 - */ - public void addEnv(Environment.Variable var) { - env.addVariable(var); - } - - /** - * If true, use a new environment when forked. - * - *Will be ignored if we are not forking a new VM.
- * - * @param newenv boolean indicating if setting a new environment is wished - * @since Ant 1.5 - */ - public void setNewenvironment(boolean newenv) { - newEnvironment = newenv; - } - - /** - * Preset the attributes of the test - * before configuration in the build - * script. - * This allows attributes in theOutput will always be passed to the formatters and not by - * shown by default. This option should for example be set for - * tests that are interactive and prompt the user to do - * something.
- * - * @param showOutput if true, send output to Ant's logging system too - * @since Ant 1.5 - */ - public void setShowOutput(boolean showOutput) { - this.showOutput = showOutput; - } - - /** - * If true, send any output generated by tests to the formatters. - * - * @param outputToFormatters if true, send output to formatters (Default - * is true). - * @since Ant 1.7.0 - */ - public void setOutputToFormatters(boolean outputToFormatters) { - this.outputToFormatters = outputToFormatters; - } - - /** - * Assertions to enable in this program (if fork=true) - * @since Ant 1.6 - * @param asserts assertion set - */ - public void addAssertions(Assertions asserts) { - if (getCommandline().getAssertions() != null) { - throw new BuildException("Only one assertion declaration is allowed"); - } - getCommandline().setAssertions(asserts); - } - - /** - * Sets the permissions for the application run inside the same JVM. - * @since Ant 1.6 - * @return . - */ - public Permissions createPermissions() { - if (perm == null) { - perm = new Permissions(); - } - return perm; - } - - /** - * If set, system properties will be copied to the cloned VM - as - * well as the bootclasspath unless you have explicitly specified - * a bootclaspath. - * - *Doesn't have any effect unless fork is true.
- * @param cloneVm aboolean value.
- * @since Ant 1.7
- */
- public void setCloneVm(boolean cloneVm) {
- getCommandline().setCloneVm(cloneVm);
- }
-
- /**
- * Creates a new JUnitRunner and enables fork of a new Java VM.
- *
- * @throws Exception under ??? circumstances
- * @since Ant 1.2
- */
- public JUnitTask() throws Exception {
- getCommandline()
- .setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner");
- }
-
- /**
- * Where Ant should place temporary files.
- *
- * @param tmpDir location where temporary files should go to
- * @since Ant 1.6
- */
- public void setTempdir(File tmpDir) {
- if (tmpDir != null) {
- if (!tmpDir.exists() || !tmpDir.isDirectory()) {
- throw new BuildException(tmpDir.toString()
- + " is not a valid temp directory");
- }
- }
- this.tmpDir = tmpDir;
- }
-
- /**
- * Adds the jars or directories containing Ant, this task and
- * JUnit to the classpath - this should make the forked JVM work
- * without having to specify them directly.
- *
- * @since Ant 1.4
- */
- public void init() {
- antRuntimeClasses = new Path(getProject());
- splitJunit = !addClasspathEntry("/junit/framework/TestCase.class");
- addClasspathEntry("/org/apache/tools/ant/launch/AntMain.class");
- addClasspathEntry("/org/apache/tools/ant/Task.class");
- addClasspathEntry("/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.class");
- addClasspathEntry("/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.class");
- }
-
- private static JUnitTaskMirror createMirror(JUnitTask task, ClassLoader loader) {
- try {
- loader.loadClass("junit.framework.Test"); // sanity check
- } catch (ClassNotFoundException e) {
- throw new BuildException(
- "The Doesn't work for archives in JDK 1.1 as the URL returned by - * getResource doesn't contain the name of the archive.
- * - * @param resource resource that one wants to lookup - * @return true if something was in fact added - * @since Ant 1.4 - */ - protected boolean addClasspathEntry(String resource) { - /* - * pre Ant 1.6 this method used to call getClass().getResource - * while Ant 1.6 will call ClassLoader.getResource(). - * - * The difference is that Class.getResource expects a leading - * slash for "absolute" resources and will strip it before - * delegating to ClassLoader.getResource - so we now have to - * emulate Class's behavior. - */ - if (resource.startsWith("/")) { - resource = resource.substring(1); - } else { - resource = "org/apache/tools/ant/taskdefs/optional/junit/" - + resource; - } - - File f = LoaderUtils.getResourceSource(getClass().getClassLoader(), - resource); - if (f != null) { - log("Found " + f.getAbsolutePath(), Project.MSG_DEBUG); - antRuntimeClasses.createPath().setLocation(f); - return true; - } else { - log("Couldn\'t find " + resource, Project.MSG_DEBUG); - return false; - } - } - - /** - * Take care that some output is produced in report files if the - * watchdog kills the test. - * - * @since Ant 1.5.2 - */ - - private void logTimeout(FormatterElement[] feArray, JUnitTest test, String testCase) { - logVmExit( - feArray, test, - "Timeout occurred. Please note the time in the report does" - + " not reflect the time until the timeout.", - testCase); - } - - /** - * Take care that some output is produced in report files if the - * forked machine exited before the test suite finished but the - * reason is not a timeout. - * - * @since Ant 1.7 - */ - private void logVmCrash(FormatterElement[] feArray, JUnitTest test, String testCase) { - logVmExit( - feArray, test, - "Forked Java VM exited abnormally. Please note the time in the report" - + " does not reflect the time until the VM exit.", - testCase); - } - - /** - * Take care that some output is produced in report files if the - * forked machine terminated before the test suite finished - * - * @since Ant 1.7 - */ - private void logVmExit(FormatterElement[] feArray, JUnitTest test, - String message, String testCase) { - try { - log("Using System properties " + System.getProperties(), - Project.MSG_VERBOSE); - if (splitJunit) { - classLoader = (AntClassLoader) delegate.getClass().getClassLoader(); - } else { - createClassLoader(); - } - if (classLoader != null) { - classLoader.setThreadContextLoader(); - } - - test.setCounts(1, 0, 1); - test.setProperties(getProject().getProperties()); - for (int i = 0; i < feArray.length; i++) { - FormatterElement fe = feArray[i]; - File outFile = getOutput(fe, test); - JUnitTaskMirror.JUnitResultFormatterMirror formatter = - fe.createFormatter(classLoader); - if (outFile != null && formatter != null) { - try { - OutputStream out = new FileOutputStream(outFile); - delegate.addVmExit(test, formatter, out, message, testCase); - } catch (IOException e) { - // ignore - } - } - } - if (summary) { - JUnitTaskMirror.SummaryJUnitResultFormatterMirror f = - delegate.newSummaryJUnitResultFormatter(); - f.setWithOutAndErr("withoutanderr".equalsIgnoreCase(summaryValue)); - delegate.addVmExit(test, f, getDefaultOutput(), message, testCase); - } - } finally { - if (classLoader != null) { - classLoader.resetThreadContextLoader(); - } - } - } - - /** - * Creates and configures an AntClassLoader instance from the - * nested classpath element. - * - * @since Ant 1.6 - */ - private void createClassLoader() { - Path userClasspath = getCommandline().getClasspath(); - if (userClasspath != null) { - if (reloading || classLoader == null) { - deleteClassLoader(); - Path classpath = (Path) userClasspath.clone(); - if (includeAntRuntime) { - log("Implicitly adding " + antRuntimeClasses - + " to CLASSPATH", Project.MSG_VERBOSE); - classpath.append(antRuntimeClasses); - } - classLoader = getProject().createClassLoader(classpath); - if (getClass().getClassLoader() != null - && getClass().getClassLoader() != Project.class.getClassLoader()) { - classLoader.setParent(getClass().getClassLoader()); - } - classLoader.setParentFirst(false); - classLoader.addJavaLibraries(); - log("Using CLASSPATH " + classLoader.getClasspath(), - Project.MSG_VERBOSE); - // make sure the test will be accepted as a TestCase - classLoader.addSystemPackageRoot("junit"); - // make sure the test annotation are accepted - classLoader.addSystemPackageRoot("org.junit"); - // will cause trouble in JDK 1.1 if omitted - classLoader.addSystemPackageRoot("org.apache.tools.ant"); - } - } - } - - /** - * Removes a classloader if needed. - * @since Ant 1.7 - */ - private void deleteClassLoader() { - if (classLoader != null) { - classLoader.cleanup(); - classLoader = null; - } - } - - /** - * Get the command line used to run the tests. - * @return the command line. - * @since Ant 1.6.2 - */ - protected CommandlineJava getCommandline() { - if (commandline == null) { - commandline = new CommandlineJava(); - } - return commandline; - } - - /** - * Forked test support - * @since Ant 1.6.2 - */ - private static final class ForkedTestConfiguration { - private boolean filterTrace; - private boolean haltOnError; - private boolean haltOnFailure; - private String errorProperty; - private String failureProperty; - - /** - * constructor for forked test configuration - * @param filterTrace - * @param haltOnError - * @param haltOnFailure - * @param errorProperty - * @param failureProperty - */ - ForkedTestConfiguration(boolean filterTrace, boolean haltOnError, - boolean haltOnFailure, String errorProperty, - String failureProperty) { - this.filterTrace = filterTrace; - this.haltOnError = haltOnError; - this.haltOnFailure = haltOnFailure; - this.errorProperty = errorProperty; - this.failureProperty = failureProperty; - } - - /** - * configure from a test; sets member variables to attributes of the test - * @param test - */ - ForkedTestConfiguration(JUnitTest test) { - this(test.getFiltertrace(), - test.getHaltonerror(), - test.getHaltonfailure(), - test.getErrorProperty(), - test.getFailureProperty()); - } - - /** - * equality test checks all the member variables - * @param other - * @return true if everything is equal - */ - public boolean equals(Object other) { - if (other == null - || other.getClass() != ForkedTestConfiguration.class) { - return false; - } - ForkedTestConfiguration o = (ForkedTestConfiguration) other; - return filterTrace == o.filterTrace - && haltOnError == o.haltOnError - && haltOnFailure == o.haltOnFailure - && ((errorProperty == null && o.errorProperty == null) - || - (errorProperty != null - && errorProperty.equals(o.errorProperty))) - && ((failureProperty == null && o.failureProperty == null) - || - (failureProperty != null - && failureProperty.equals(o.failureProperty))); - } - - /** - * hashcode is based only on the boolean members, and returns a value - * in the range 0-7. - * @return hash code value - */ - public int hashCode() { - return (filterTrace ? 1 : 0) - + (haltOnError ? 2 : 0) - + (haltOnFailure ? 4 : 0); - } - } - - /** - * These are the different forking options - * @since 1.6.2 - */ - public static final class ForkMode extends EnumeratedAttribute { - - /** - * fork once only - */ - public static final String ONCE = "once"; - /** - * fork once per test class - */ - public static final String PER_TEST = "perTest"; - /** - * fork once per batch of tests - */ - public static final String PER_BATCH = "perBatch"; - - /** No arg constructor. */ - public ForkMode() { - super(); - } - - /** - * Constructor using a value. - * @param value the value to use - once, perTest or perBatch. - */ - public ForkMode(String value) { - super(); - setValue(value); - } - - /** {@inheritDoc}. */ - public String[] getValues() { - return new String[] {ONCE, PER_TEST, PER_BATCH}; - } - } - - /** - * Executes all tests that don't need to be forked (or all tests - * if the runIndividual argument is true. Returns a collection of - * lists of tests that share the same VM configuration and haven't - * been executed yet. - * @param testList the list of tests to be executed or queued. - * @param runIndividual if true execute each test individually. - * @return a list of tasks to be executed. - * @since 1.6.2 - */ - protected Collection executeOrQueue(Enumeration testList, - boolean runIndividual) { - Map testConfigurations = new HashMap(); - while (testList.hasMoreElements()) { - JUnitTest test = (JUnitTest) testList.nextElement(); - if (test.shouldRun(getProject())) { - if (runIndividual || !test.getFork()) { - execute(test); - } else { - ForkedTestConfiguration c = - new ForkedTestConfiguration(test); - List l = (List) testConfigurations.get(c); - if (l == null) { - l = new ArrayList(); - testConfigurations.put(c, l); - } - l.add(test); - } - } - } - return testConfigurations.values(); - } - - /** - * Logs information about failed tests, potentially stops - * processing (by throwing a BuildException) if a failure/error - * occurred or sets a property. - * @param exitValue the exitValue of the test. - * @param wasKilled if true, the test had been killed. - * @param test the test in question. - * @param name the name of the test. - * @since Ant 1.6.2 - */ - protected void actOnTestResult(int exitValue, boolean wasKilled, - JUnitTest test, String name) { - TestResultHolder t = new TestResultHolder(); - t.exitCode = exitValue; - t.timedOut = wasKilled; - actOnTestResult(t, test, name); - } - - /** - * Logs information about failed tests, potentially stops - * processing (by throwing a BuildException) if a failure/error - * occurred or sets a property. - * @param result the result of the test. - * @param test the test in question. - * @param name the name of the test. - * @since Ant 1.7 - */ - protected void actOnTestResult(TestResultHolder result, JUnitTest test, - String name) { - // if there is an error/failure and that it should halt, stop - // everything otherwise just log a statement - boolean fatal = result.timedOut || result.crashed; - boolean errorOccurredHere = - result.exitCode == JUnitTaskMirror.JUnitTestRunnerMirror.ERRORS || fatal; - boolean failureOccurredHere = - result.exitCode != JUnitTaskMirror.JUnitTestRunnerMirror.SUCCESS || fatal; - if (errorOccurredHere || failureOccurredHere) { - if ((errorOccurredHere && test.getHaltonerror()) - || (failureOccurredHere && test.getHaltonfailure())) { - throw new BuildException(name + " failed" - + (result.timedOut ? " (timeout)" : "") - + (result.crashed ? " (crashed)" : ""), getLocation()); - } else { - log(name + " FAILED" - + (result.timedOut ? " (timeout)" : "") - + (result.crashed ? " (crashed)" : ""), Project.MSG_ERR); - if (errorOccurredHere && test.getErrorProperty() != null) { - getProject().setNewProperty(test.getErrorProperty(), "true"); - } - if (failureOccurredHere && test.getFailureProperty() != null) { - getProject().setNewProperty(test.getFailureProperty(), "true"); - } - } - } - } - - /** - * A value class that contains thee result of a test. - */ - protected class TestResultHolder { - // CheckStyle:VisibilityModifier OFF - bc - /** the exit code of the test. */ - public int exitCode = JUnitTaskMirror.JUnitTestRunnerMirror.ERRORS; - /** true if the test timed out */ - public boolean timedOut = false; - /** true if the test crashed */ - public boolean crashed = false; - // CheckStyle:VisibilityModifier ON - } - - /** - * A stream handler for handling the junit task. - * @since Ant 1.7 - */ - protected static class JUnitLogOutputStream extends LogOutputStream { - private Task task; // local copy since LogOutputStream.task is private - - /** - * Constructor. - * @param task the task being logged. - * @param level the log level used to log data written to this stream. - */ - public JUnitLogOutputStream(Task task, int level) { - super(task, level); - this.task = task; - } - - /** - * Logs a line. - * If the line starts with junit.framework.TestListener: set the level - * to MSG_VERBOSE. - * @param line the line to log. - * @param level the logging level to use. - */ - protected void processLine(String line, int level) { - if (line.startsWith(TESTLISTENER_PREFIX)) { - task.log(line, Project.MSG_VERBOSE); - } else { - super.processLine(line, level); - } - } - } - - /** - * A log stream handler for junit. - * @since Ant 1.7 - */ - protected static class JUnitLogStreamHandler extends PumpStreamHandler { - /** - * Constructor. - * @param task the task to log. - * @param outlevel the level to use for standard output. - * @param errlevel the level to use for error output. - */ - public JUnitLogStreamHandler(Task task, int outlevel, int errlevel) { - super(new JUnitLogOutputStream(task, outlevel), - new LogOutputStream(task, errlevel)); - } - } -}