Browse Source

checkstyle - mostly javadoc

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@473108 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 18 years ago
parent
commit
2c3c58bb7f
16 changed files with 304 additions and 43 deletions
  1. +2
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
  2. +72
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java
  3. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java
  4. +2
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java
  5. +11
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/DOMUtil.java
  6. +28
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
  7. +9
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitResultFormatter.java
  8. +69
    -7
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  9. +52
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirror.java
  10. +12
    -5
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
  11. +2
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java
  12. +12
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java
  13. +3
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/SummaryJUnitResultFormatter.java
  14. +8
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java
  15. +17
    -14
      src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan2Executor.java
  16. +2
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/XalanExecutor.java

+ 2
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java View File

@@ -79,6 +79,7 @@ public class AggregateTransformer {
}
}

// CheckStyle:VisibilityModifier OFF - bc
/** Task */
protected Task task;

@@ -123,6 +124,7 @@ public class AggregateTransformer {
privateDBFactory = DocumentBuilderFactory.newInstance();
dbfactory = privateDBFactory;
}
// CheckStyle:VisibilityModifier ON

/**
* constructor creating the transformer from the junitreport task.


+ 72
- 2
src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java View File

@@ -26,6 +26,7 @@ import java.util.Vector;
*
*/
public abstract class BaseTest {
// CheckStyle:VisibilityModifier OFF - bc
protected boolean haltOnError = false;
protected boolean haltOnFail = false;
protected boolean filtertrace = true;
@@ -38,59 +39,110 @@ public abstract class BaseTest {

protected String failureProperty;
protected String errorProperty;
// CheckStyle:VisibilityModifier ON

/**
* Set the filtertrace attribute.
* @param value a <code>boolean</code> value.
*/
public void setFiltertrace(boolean value) {
filtertrace = value;
}

/**
* Get the filtertrace attribute.
* @return the attribute.
*/
public boolean getFiltertrace() {
return filtertrace;
}

/**
* Set the fork attribute.
* @param value a <code>boolean</code> value.
*/
public void setFork(boolean value) {
fork = value;
}

/**
* Get the fork attribute.
* @return the attribute.
*/
public boolean getFork() {
return fork;
}

/**
* Set the haltonerror attribute.
* @param value a <code>boolean</code> value.
*/
public void setHaltonerror(boolean value) {
haltOnError = value;
}

/**
* Set the haltonfailure attribute.
* @param value a <code>boolean</code> value.
*/
public void setHaltonfailure(boolean value) {
haltOnFail = value;
}

/**
* Get the haltonerror attribute.
* @return the attribute.
*/
public boolean getHaltonerror() {
return haltOnError;
}

/**
* Get the haltonfailure attribute.
* @return the attribute.
*/
public boolean getHaltonfailure() {
return haltOnFail;
}

/**
* Set the if attribute.
* If this property is present in project,
* the test will be run.
* @param propertyName the name of the property to look for.
*/
public void setIf(String propertyName) {
ifProperty = propertyName;
}

/**
* Set the unless attribute.
* If this property is present in project,
* the test will *not* be run.
* @param propertyName the name of the property to look for.
*/
public void setUnless(String propertyName) {
unlessProperty = propertyName;
}

/**
* Allow a formatter nested element.
* @param elem a formatter nested element.
*/
public void addFormatter(FormatterElement elem) {
formatters.addElement(elem);
}

/**
* Sets the destination directory.
* @param destDir the destination directory.
*/
public void setTodir(File destDir) {
this.destDir = destDir;
}

/**
* Get the destination directory.
* @return the destination directory as an absolute path if it exists
* otherwise return <tt>null</tt>
*/
@@ -101,18 +153,36 @@ public abstract class BaseTest {
return null;
}

public java.lang.String getFailureProperty() {
/**
* Get the failure property name.
* @return the name of the property to set on failure.
*/
public String getFailureProperty() {
return failureProperty;
}

/**
* Set the name of the failure property.
* @param failureProperty the name of the property to set if
* the test fails.
*/
public void setFailureProperty(String failureProperty) {
this.failureProperty = failureProperty;
}

public java.lang.String getErrorProperty() {
/**
* Get the failure property name.
* @return the name of the property to set on failure.
*/
public String getErrorProperty() {
return errorProperty;
}

/**
* Set the name of the error property.
* @param errorProperty the name of the property to set if
* the test has an error.
*/
public void setErrorProperty(String errorProperty) {
this.errorProperty = errorProperty;
}


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java View File

@@ -97,7 +97,7 @@ public final class BatchTest extends BaseTest {
* @return an enumeration of all elements of this batchtest that are
* a <tt>JUnitTest</tt> instance.
*/
public final Enumeration elements() {
public Enumeration elements() {
JUnitTest[] tests = createAllJUnitTest();
return Enumerations.fromArray(tests);
}
@@ -108,7 +108,7 @@ public final class BatchTest extends BaseTest {
* @param v the vector to which should be added all individual tests of this
* batch test.
*/
final void addTestsTo(Vector v) {
void addTestsTo(Vector v) {
JUnitTest[] tests = createAllJUnitTest();
v.ensureCapacity(v.size() + tests.length);
for (int i = 0; i < tests.length; i++) {
@@ -168,7 +168,7 @@ public final class BatchTest extends BaseTest {
* @param filename the filename to "convert" to a classname.
* @return the classname matching the filename.
*/
public static final String javaToClass(String filename) {
public static String javaToClass(String filename) {
return filename.replace(File.separatorChar, '.').replace('/', '.')
.replace('\\', '.');
}


+ 2
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java View File

@@ -93,6 +93,7 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter {
/**
* @see JUnitResultFormatter#setSystemOutput(String)
*/
/** {@inheritDoc}. */
public void setSystemOutput(String out) {
systemOutput = out;
}
@@ -100,6 +101,7 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter {
/**
* @see JUnitResultFormatter#setSystemError(String)
*/
/** {@inheritDoc}. */
public void setSystemError(String err) {
systemError = err;
}


+ 11
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/DOMUtil.java View File

@@ -60,6 +60,7 @@ public final class DOMUtil {
* @param filter the filter that children should match.
* @param recurse <tt>true</tt> if you want the list to be made recursively
* otherwise <tt>false</tt>.
* @return the node list that matches the filter.
*/
public static NodeList listChildNodes(Node parent, NodeFilter filter, boolean recurse) {
NodeListImpl matches = new NodeListImpl();
@@ -85,9 +86,18 @@ public final class DOMUtil {

/** custom implementation of a nodelist */
public static class NodeListImpl extends Vector implements NodeList {
/**
* Get the number of nodes in the list.
* @return the length of the list.
*/
public int getLength() {
return size();
}
/**
* Get a particular node.
* @param i the index of the node to get.
* @return the node if the index is in bounds, null otherwise.
*/
public Node item(int i) {
try {
return (Node) elementAt(i);
@@ -205,6 +215,7 @@ public final class DOMUtil {
}
}
} catch (DOMException ignored) {
// Ignore
}

// bingo append it. (this should normally not be done here)


+ 28
- 3
src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java View File

@@ -59,10 +59,13 @@ public class FormatterElement {
private String ifProperty;
private String unlessProperty;

/** xml formatter class */
public static final String XML_FORMATTER_CLASS_NAME =
"org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter";
/** brief formatter class */
public static final String BRIEF_FORMATTER_CLASS_NAME =
"org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter";
/** plain formatter class */
public static final String PLAIN_FORMATTER_CLASS_NAME =
"org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter";

@@ -78,6 +81,7 @@ public class FormatterElement {
*
* <p> Sets <code>classname</code> attribute - so you can't use that
* attribute if you use this one.
* @param type the enumerated value to use.
*/
public void setType(TypeAttribute type) {
if ("xml".equals(type.getValue())) {
@@ -95,6 +99,7 @@ public class FormatterElement {
* <p> Set name of class to be used as the formatter.
*
* <p> This class must implement <code>JUnitResultFormatter</code>
* @param classname the name of the formatter class.
*/
public void setClassname(String classname) {
this.classname = classname;
@@ -109,15 +114,24 @@ public class FormatterElement {

/**
* Get name of class to be used as the formatter.
* @return the name of the class.
*/
public String getClassname() {
return classname;
}

/**
* Set the extension to use for the report file.
* @param ext the extension to use.
*/
public void setExtension(String ext) {
this.extension = ext;
}

/**
* Get the extension used for the report file.
* @return the extension.
*/
public String getExtension() {
return extension;
}
@@ -135,6 +149,7 @@ public class FormatterElement {
* <p> Set output stream for formatter to use.
*
* <p> Defaults to standard out.
* @param out the output stream to use.
*/
public void setOutput(OutputStream out) {
this.out = out;
@@ -142,6 +157,8 @@ public class FormatterElement {

/**
* Set whether the formatter should log to file.
* @param useFile if true use a file, if false send
* to standard out.
*/
public void setUseFile(boolean useFile) {
this.useFile = useFile;
@@ -176,6 +193,8 @@ public class FormatterElement {
/**
* Ensures that the selector passes the conditions placed
* on it with <code>if</code> and <code>unless</code> properties.
* @param t the task the this formatter is used in.
* @return true if the formatter should be used.
*/
public boolean shouldUse(Task t) {
if (ifProperty != null && t.getProject().getProperty(ifProperty) == null) {
@@ -215,9 +234,13 @@ public class FormatterElement {
f = Class.forName(classname, true, loader);
}
} catch (ClassNotFoundException e) {
throw new BuildException("Using loader " + loader + " on class " + classname + ": " + e, e);
throw new BuildException(
"Using loader " + loader + " on class " + classname
+ ": " + e, e);
} catch (NoClassDefFoundError e) {
throw new BuildException("Using loader " + loader + " on class " + classname + ": " + e, e);
throw new BuildException(
"Using loader " + loader + " on class " + classname
+ ": " + e, e);
}

Object o = null;
@@ -233,7 +256,8 @@ public class FormatterElement {
throw new BuildException(classname
+ " is not a JUnitResultFormatter");
}
JUnitTaskMirror.JUnitResultFormatterMirror r = (JUnitTaskMirror.JUnitResultFormatterMirror) o;
JUnitTaskMirror.JUnitResultFormatterMirror r =
(JUnitTaskMirror.JUnitResultFormatterMirror) o;
if (useFile && outFile != null) {
try {
out = new BufferedOutputStream(new FileOutputStream(outFile));
@@ -251,6 +275,7 @@ public class FormatterElement {
* <p> Use to enumerate options for <code>type</code> attribute.
*/
public static class TypeAttribute extends EnumeratedAttribute {
/** {@inheritDoc}. */
public String[] getValues() {
return new String[] {"plain", "xml", "brief"};
}


+ 9
- 1
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitResultFormatter.java View File

@@ -27,29 +27,37 @@ import org.apache.tools.ant.BuildException;
* testrun.
*
*/
public interface JUnitResultFormatter extends TestListener, JUnitTaskMirror.JUnitResultFormatterMirror {
public interface JUnitResultFormatter
extends TestListener, JUnitTaskMirror.JUnitResultFormatterMirror {
/**
* The whole testsuite started.
* @param suite the suite.
* @throws BuildException on error.
*/
void startTestSuite(JUnitTest suite) throws BuildException;

/**
* The whole testsuite ended.
* @param suite the suite.
* @throws BuildException on error.
*/
void endTestSuite(JUnitTest suite) throws BuildException;

/**
* Sets the stream the formatter is supposed to write its results to.
* @param out the output stream to use.
*/
void setOutput(OutputStream out);

/**
* This is what the test has written to System.out
* @param out the string to write.
*/
void setSystemOutput(String out);

/**
* This is what the test has written to System.err
* @param err the string to write.
*/
void setSystemError(String err);
}

+ 69
- 7
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -293,7 +293,7 @@ public class JUnitTask extends Task {
* 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.</p>
*
* @param mode the mode to use.
* @since Ant 1.6.2
*/
public void setForkMode(ForkMode mode) {
@@ -618,7 +618,7 @@ public class JUnitTask extends Task {
* a bootclaspath.
*
* <p>Doesn't have any effect unless fork is true.</p>
*
* @param cloneVm a <code>boolean</code> value.
* @since Ant 1.7
*/
public void setCloneVm(boolean cloneVm) {
@@ -822,6 +822,8 @@ public class JUnitTask extends Task {

/**
* Execute a list of tests in a single forked Java VM.
* @param tests the list of tests to execute.
* @throws BuildException on error.
*/
protected void execute(List tests) throws BuildException {
JUnitTest test = null;
@@ -1088,7 +1090,16 @@ public class JUnitTask extends Task {
}

/**
* Handle an input request by this task.
* @see Task#handleInput(byte[], int, int)
* This implementation delegates to a runner if it
* present.
* @param buffer the buffer into which data is to be read.
* @param offset the offset into the buffer at which data is stored.
* @param length the amount of data to read.
*
* @return the number of bytes read.
* @exception IOException if the data cannot be read.
*
* @since Ant 1.6
*/
@@ -1380,7 +1391,11 @@ public class JUnitTask extends Task {
*/

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);
logVmExit(
feArray, test,
"Timeout occurred. Please note the time in the report does"
+ " not reflect the time until the timeout.",
testCase);
}

/**
@@ -1391,7 +1406,11 @@ public class JUnitTask extends Task {
* @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);
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);
}

/**
@@ -1491,6 +1510,8 @@ public class JUnitTask extends Task {
}

/**
* Get the command line used to run the tests.
* @return the command line.
* @since Ant 1.6.2
*/
protected CommandlineJava getCommandline() {
@@ -1596,15 +1617,21 @@ public class JUnitTask extends Task {
*/
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};
}
@@ -1615,7 +1642,9 @@ public class JUnitTask extends Task {
* 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,
@@ -1645,7 +1674,10 @@ public class JUnitTask extends Task {
* 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,
@@ -1660,7 +1692,9 @@ public class JUnitTask extends Task {
* 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,
@@ -1692,23 +1726,44 @@ public class JUnitTask extends Task {
}
}

/**
* 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);
@@ -1719,9 +1774,16 @@ public class JUnitTask extends Task {
}

/**
* 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));


+ 52
- 4
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirror.java View File

@@ -40,27 +40,61 @@ import org.apache.tools.ant.types.Permissions;
*/
public interface JUnitTaskMirror {

/**
* Add the formatter to be called when the jvm exits before
* the test suite finishs.
* @param test the test.
* @param formatter the fomatter to use.
* @param out the output stream to use.
* @param message the message to write out.
* @param testCase the name of the test.
*/
void addVmExit(JUnitTest test, JUnitResultFormatterMirror formatter,
OutputStream out, String message, String testCase);

/**
* Create a new test runner for a test.
* @param test the test to run.
* @param haltOnError if true halt the tests if an error occurs.
* @param filterTrace if true filter the stack traces.
* @param haltOnFailure if true halt the test if a failure occurs.
* @param showOutput if true show output.
* @param logTestListenerEvents if true log test listener events.
* @param classLoader the classloader to use to create the runner.
* @return the test runner.
*/
JUnitTestRunnerMirror newJUnitTestRunner(JUnitTest test, boolean haltOnError,
boolean filterTrace, boolean haltOnFailure, boolean showOutput,
boolean logTestListenerEvents, AntClassLoader classLoader);

/**
* Create a summary result formatter.
* @return the created formatter.
*/
SummaryJUnitResultFormatterMirror newSummaryJUnitResultFormatter();

public interface JUnitResultFormatterMirror {

/** The interface that JUnitResultFormatter extends. */
public interface JUnitResultFormatterMirror {
/**
* Set the output stream.
* @param outputStream the stream to use.
*/
void setOutput(OutputStream outputStream);

}

public interface SummaryJUnitResultFormatterMirror extends JUnitResultFormatterMirror {
/** The interface that SummaryJUnitResultFormatter extends. */
public interface SummaryJUnitResultFormatterMirror
extends JUnitResultFormatterMirror {

/**
* Set where standard out and standard error should be included.
* @param value if true include the outputs in the summary.
*/
void setWithOutAndErr(boolean value);

}

/** Interface that test runners implement. */
public interface JUnitTestRunnerMirror {

/**
@@ -87,12 +121,26 @@ public interface JUnitTaskMirror {
*/
int ERRORS = 2;

/**
* Permissions for the test run.
* @param perm the permissions to use.
*/
void setPermissions(Permissions perm);

/** Run the test. */
void run();

/**
* Add a formatter to the test.
* @param formatter the formatter to use.
*/
void addFormatter(JUnitResultFormatterMirror formatter);

/**
* Returns what System.exit() would return in the standalone version.
*
* @return 2 if errors occurred, 1 if tests failed else 0.
*/
int getRetCode();

void handleErrorFlush(String output);


+ 12
- 5
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java View File

@@ -543,7 +543,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
/**
* Permissions for the test run.
* @since Ant 1.6
* @param permissions
* @param permissions the permissions to use.
*/
public void setPermissions(Permissions permissions) {
perm = permissions;
@@ -689,7 +689,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
} else if (args[i].startsWith(Constants.SHOWOUTPUT)) {
showOut = Project.toBoolean(args[i].substring(Constants.SHOWOUTPUT.length()));
} else if (args[i].startsWith(Constants.LOGTESTLISTENEREVENTS)) {
logTestListenerEvents = Project.toBoolean(args[i].substring(Constants.LOGTESTLISTENEREVENTS.length()));
logTestListenerEvents = Project.toBoolean(
args[i].substring(Constants.LOGTESTLISTENEREVENTS.length()));
} else if (args[i].startsWith(Constants.OUTPUT_TO_FORMATTERS)) {
outputToFormat = Project.toBoolean(
args[i].substring(Constants.OUTPUT_TO_FORMATTERS.length()));
@@ -828,6 +829,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
/**
* Returns a filtered stack trace.
* This is ripped out of junit.runner.BaseTestRunner.
* @param t the exception to filter.
* @return the filtered stack trace.
*/
public static String getFilteredTrace(Throwable t) {
String trace = StringUtils.getStackTrace(t);
@@ -836,6 +839,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR

/**
* Filters stack frames from internal JUnit and Ant classes
* @param stack the stack trace to filter.
*/
public static String filterStack(String stack) {
if (!filtertrace) {
@@ -936,7 +940,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
return new TestListener() {
public void addError(Test test, Throwable t) {
if (junit4 && t instanceof AssertionFailedError) {
// JUnit 4 does not distinguish between errors and failures even in the JUnit 3 adapter.
// JUnit 4 does not distinguish between errors and failures
// even in the JUnit 3 adapter.
// So we need to help it a bit to retain compatibility for JUnit 3 tests.
testListener.addFailure(test, (AssertionFailedError) t);
} else if (junit4 && t.getClass().getName().equals("java.lang.AssertionError")) {
@@ -949,7 +954,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
AssertionFailedError failure = msg != null
? new AssertionFailedError(msg) : new AssertionFailedError();
// To compile on pre-JDK 4 (even though this should always succeed):
Method initCause = Throwable.class.getMethod("initCause", new Class[] {Throwable.class});
Method initCause = Throwable.class.getMethod(
"initCause", new Class[] {Throwable.class});
initCause.invoke(failure, new Object[] {t});
testListener.addFailure(test, failure);
} catch (Exception e) {
@@ -996,7 +1002,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
e = res.errors();
while (e.hasMoreElements()) {
Throwable t = ((TestFailure) e.nextElement()).thrownException();
if (t instanceof AssertionFailedError || t.getClass().getName().equals("java.lang.AssertionError")) {
if (t instanceof AssertionFailedError
|| t.getClass().getName().equals("java.lang.AssertionError")) {
failures++;
} else {
errors++;


+ 2
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java View File

@@ -54,6 +54,8 @@ public class JUnitVersionHelper {
*
* <p>Since Ant 1.7 also checks for JUnit4TestCaseFacade explicitly.
* This is used by junit.framework.JUnit4TestAdapter.</p>
* @param t the test.
* @return the name of the test.
*/
public static String getTestCaseName(Test t) {
if (t != null && t.getClass().getName().equals("junit.framework.JUnit4TestCaseFacade")) {


+ 12
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java View File

@@ -68,19 +68,23 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter {
private String systemOutput = null;
private String systemError = null;

/** No arg constructor */
public PlainJUnitResultFormatter() {
inner = new StringWriter();
wri = new PrintWriter(inner);
}

/** {@inheritDoc}. */
public void setOutput(OutputStream out) {
this.out = out;
}

/** {@inheritDoc}. */
public void setSystemOutput(String out) {
systemOutput = out;
}

/** {@inheritDoc}. */
public void setSystemError(String err) {
systemError = err;
}
@@ -161,6 +165,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter {
* Interface TestListener.
*
* <p>A new Test is started.
* @param t the test.
*/
public void startTest(Test t) {
testStarts.put(t, new Long(System.currentTimeMillis()));
@@ -171,6 +176,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter {
* Interface TestListener.
*
* <p>A Test is finished.
* @param t the test.
*/
public void endTest(Test test) {
if (Boolean.TRUE.equals(failed.get(test))) {
@@ -195,6 +201,8 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter {
* Interface TestListener for JUnit &lt;= 3.4.
*
* <p>A Test failed.
* @param test the test.
* @param t the exception.
*/
public void addFailure(Test test, Throwable t) {
formatError("\tFAILED", test, t);
@@ -204,6 +212,8 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter {
* Interface TestListener for JUnit &gt; 3.4.
*
* <p>A Test failed.
* @param test the test.
* @param t the assertion that failed.
*/
public void addFailure(Test test, AssertionFailedError t) {
addFailure(test, (Throwable) t);
@@ -213,6 +223,8 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter {
* Interface TestListener.
*
* <p>An error occurred while running the test.
* @param test the test.
* @param t the exception.
*/
public void addError(Test test, Throwable t) {
formatError("\tCaused an ERROR", test, t);


+ 3
- 1
src/main/org/apache/tools/ant/taskdefs/optional/junit/SummaryJUnitResultFormatter.java View File

@@ -30,7 +30,9 @@ import org.apache.tools.ant.BuildException;
*
*/

public class SummaryJUnitResultFormatter implements JUnitResultFormatter, JUnitTaskMirror.SummaryJUnitResultFormatterMirror {
public class SummaryJUnitResultFormatter
implements JUnitResultFormatter
,JUnitTaskMirror.SummaryJUnitResultFormatterMirror {

/**
* Formatter for timings.


+ 8
- 3
src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java View File

@@ -57,6 +57,7 @@ import org.xml.sax.SAXException;
*/
public class XMLResultAggregator extends Task implements XMLConstants {

// CheckStyle:VisibilityModifier OFF - bc
/** the list of all filesets, that should contains the xml to aggregate */
protected Vector filesets = new Vector();

@@ -80,15 +81,19 @@ public class XMLResultAggregator extends Task implements XMLConstants {
/**
* text checked for in tests, {@value}
*/
static final String WARNING_IS_POSSIBLY_CORRUPTED = " is not a valid XML document. It is possibly corrupted.";
static final String WARNING_IS_POSSIBLY_CORRUPTED
= " is not a valid XML document. It is possibly corrupted.";
/**
* text checked for in tests, {@value}
*/
static final String WARNING_INVALID_ROOT_ELEMENT = " is not a valid testsuite XML document";
static final String WARNING_INVALID_ROOT_ELEMENT
= " is not a valid testsuite XML document";
/**
* text checked for in tests, {@value}
*/
static final String WARNING_EMPTY_FILE = " is empty.\nThis can be caused by the test JVM exiting unexpectedly";
static final String WARNING_EMPTY_FILE
= " is empty.\nThis can be caused by the test JVM exiting unexpectedly";
// CheckStyle:VisibilityModifier ON

/**
* Generate a report based on the document created by the merge.


+ 17
- 14
src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan2Executor.java View File

@@ -38,33 +38,35 @@ import org.apache.tools.ant.BuildException;
*/
public class Xalan2Executor extends XalanExecutor {

private static final String aPack = "org.apache.xalan.";
private static final String sPack = "com.sun.org.apache.xalan.";
private static final String APAC = "org.apache.xalan.";
private static final String SPAC = "com.sun.org.apache.xalan.";

private TransformerFactory tfactory = TransformerFactory.newInstance();

/** {@inheritDoc}. */
protected String getImplementation() throws BuildException {
return tfactory.getClass().getName();
}

/** {@inheritDoc}. */
protected String getProcVersion(String classNameImpl)
throws BuildException {
try {
// xalan 2
if (classNameImpl.equals(aPack + "processor.TransformerFactoryImpl")
if (classNameImpl.equals(APAC + "processor.TransformerFactoryImpl")
||
classNameImpl.equals(aPack + "xslt.XSLTProcessorFactory")) {
return getXalanVersion(aPack + "processor.XSLProcessorVersion");
classNameImpl.equals(APAC + "xslt.XSLTProcessorFactory")) {
return getXalanVersion(APAC + "processor.XSLProcessorVersion");
}
// xalan xsltc
if (classNameImpl.equals(aPack
if (classNameImpl.equals(APAC
+ "xsltc.trax.TransformerFactoryImpl")) {
return getXSLTCVersion(aPack + "xsltc.ProcessorVersion");
return getXSLTCVersion(APAC + "xsltc.ProcessorVersion");
}
// jdk 1.5 xsltc
if (classNameImpl
.equals(sPack + "internal.xsltc.trax.TransformerFactoryImpl")) {
return getXSLTCVersion(sPack
.equals(SPAC + "internal.xsltc.trax.TransformerFactoryImpl")) {
return getXSLTCVersion(SPAC
+ "internal.xsltc.ProcessorVersion");
}
throw new BuildException("Could not find a valid processor version"
@@ -76,16 +78,17 @@ public class Xalan2Executor extends XalanExecutor {
}
}

/** {@inheritDoc}. */
void execute() throws Exception {
String system_id = caller.getStylesheetSystemId();
Source xsl_src = new StreamSource(system_id);
Transformer tformer = tfactory.newTransformer(xsl_src);
Source xml_src = new DOMSource(caller.document);
String systemId = caller.getStylesheetSystemId();
Source xslSrc = new StreamSource(systemId);
Transformer tformer = tfactory.newTransformer(xslSrc);
Source xmlSrc = new DOMSource(caller.document);
OutputStream os = getOutputStream();
try {
tformer.setParameter("output.dir", caller.toDir.getAbsolutePath());
Result result = new StreamResult(os);
tformer.transform(xml_src, result);
tformer.transform(xmlSrc, result);
} finally {
os.close();
}


+ 2
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/XalanExecutor.java View File

@@ -37,8 +37,10 @@ abstract class XalanExecutor {
private static final String PACKAGE =
"org.apache.tools.ant.taskdefs.optional.junit.";

// CheckStyle:VisibilityModifier OFF - bc
/** the transformer caller */
protected AggregateTransformer caller;
// CheckStyle:VisibilityModifier ON

/** set the caller for this object. */
private void setCaller(AggregateTransformer caller) {


Loading…
Cancel
Save