git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@473108 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -79,6 +79,7 @@ public class AggregateTransformer { | |||||
| } | } | ||||
| } | } | ||||
| // CheckStyle:VisibilityModifier OFF - bc | |||||
| /** Task */ | /** Task */ | ||||
| protected Task task; | protected Task task; | ||||
| @@ -123,6 +124,7 @@ public class AggregateTransformer { | |||||
| privateDBFactory = DocumentBuilderFactory.newInstance(); | privateDBFactory = DocumentBuilderFactory.newInstance(); | ||||
| dbfactory = privateDBFactory; | dbfactory = privateDBFactory; | ||||
| } | } | ||||
| // CheckStyle:VisibilityModifier ON | |||||
| /** | /** | ||||
| * constructor creating the transformer from the junitreport task. | * constructor creating the transformer from the junitreport task. | ||||
| @@ -26,6 +26,7 @@ import java.util.Vector; | |||||
| * | * | ||||
| */ | */ | ||||
| public abstract class BaseTest { | public abstract class BaseTest { | ||||
| // CheckStyle:VisibilityModifier OFF - bc | |||||
| protected boolean haltOnError = false; | protected boolean haltOnError = false; | ||||
| protected boolean haltOnFail = false; | protected boolean haltOnFail = false; | ||||
| protected boolean filtertrace = true; | protected boolean filtertrace = true; | ||||
| @@ -38,59 +39,110 @@ public abstract class BaseTest { | |||||
| protected String failureProperty; | protected String failureProperty; | ||||
| protected String errorProperty; | protected String errorProperty; | ||||
| // CheckStyle:VisibilityModifier ON | |||||
| /** | |||||
| * Set the filtertrace attribute. | |||||
| * @param value a <code>boolean</code> value. | |||||
| */ | |||||
| public void setFiltertrace(boolean value) { | public void setFiltertrace(boolean value) { | ||||
| filtertrace = value; | filtertrace = value; | ||||
| } | } | ||||
| /** | |||||
| * Get the filtertrace attribute. | |||||
| * @return the attribute. | |||||
| */ | |||||
| public boolean getFiltertrace() { | public boolean getFiltertrace() { | ||||
| return filtertrace; | return filtertrace; | ||||
| } | } | ||||
| /** | |||||
| * Set the fork attribute. | |||||
| * @param value a <code>boolean</code> value. | |||||
| */ | |||||
| public void setFork(boolean value) { | public void setFork(boolean value) { | ||||
| fork = value; | fork = value; | ||||
| } | } | ||||
| /** | |||||
| * Get the fork attribute. | |||||
| * @return the attribute. | |||||
| */ | |||||
| public boolean getFork() { | public boolean getFork() { | ||||
| return fork; | return fork; | ||||
| } | } | ||||
| /** | |||||
| * Set the haltonerror attribute. | |||||
| * @param value a <code>boolean</code> value. | |||||
| */ | |||||
| public void setHaltonerror(boolean value) { | public void setHaltonerror(boolean value) { | ||||
| haltOnError = value; | haltOnError = value; | ||||
| } | } | ||||
| /** | |||||
| * Set the haltonfailure attribute. | |||||
| * @param value a <code>boolean</code> value. | |||||
| */ | |||||
| public void setHaltonfailure(boolean value) { | public void setHaltonfailure(boolean value) { | ||||
| haltOnFail = value; | haltOnFail = value; | ||||
| } | } | ||||
| /** | |||||
| * Get the haltonerror attribute. | |||||
| * @return the attribute. | |||||
| */ | |||||
| public boolean getHaltonerror() { | public boolean getHaltonerror() { | ||||
| return haltOnError; | return haltOnError; | ||||
| } | } | ||||
| /** | |||||
| * Get the haltonfailure attribute. | |||||
| * @return the attribute. | |||||
| */ | |||||
| public boolean getHaltonfailure() { | public boolean getHaltonfailure() { | ||||
| return haltOnFail; | 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) { | public void setIf(String propertyName) { | ||||
| ifProperty = 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) { | public void setUnless(String propertyName) { | ||||
| unlessProperty = propertyName; | unlessProperty = propertyName; | ||||
| } | } | ||||
| /** | |||||
| * Allow a formatter nested element. | |||||
| * @param elem a formatter nested element. | |||||
| */ | |||||
| public void addFormatter(FormatterElement elem) { | public void addFormatter(FormatterElement elem) { | ||||
| formatters.addElement(elem); | formatters.addElement(elem); | ||||
| } | } | ||||
| /** | /** | ||||
| * Sets the destination directory. | * Sets the destination directory. | ||||
| * @param destDir the destination directory. | |||||
| */ | */ | ||||
| public void setTodir(File destDir) { | public void setTodir(File destDir) { | ||||
| this.destDir = destDir; | this.destDir = destDir; | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the destination directory. | |||||
| * @return the destination directory as an absolute path if it exists | * @return the destination directory as an absolute path if it exists | ||||
| * otherwise return <tt>null</tt> | * otherwise return <tt>null</tt> | ||||
| */ | */ | ||||
| @@ -101,18 +153,36 @@ public abstract class BaseTest { | |||||
| return null; | 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; | 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) { | public void setFailureProperty(String failureProperty) { | ||||
| this.failureProperty = 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; | 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) { | public void setErrorProperty(String errorProperty) { | ||||
| this.errorProperty = errorProperty; | this.errorProperty = errorProperty; | ||||
| } | } | ||||
| @@ -97,7 +97,7 @@ public final class BatchTest extends BaseTest { | |||||
| * @return an enumeration of all elements of this batchtest that are | * @return an enumeration of all elements of this batchtest that are | ||||
| * a <tt>JUnitTest</tt> instance. | * a <tt>JUnitTest</tt> instance. | ||||
| */ | */ | ||||
| public final Enumeration elements() { | |||||
| public Enumeration elements() { | |||||
| JUnitTest[] tests = createAllJUnitTest(); | JUnitTest[] tests = createAllJUnitTest(); | ||||
| return Enumerations.fromArray(tests); | 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 | * @param v the vector to which should be added all individual tests of this | ||||
| * batch test. | * batch test. | ||||
| */ | */ | ||||
| final void addTestsTo(Vector v) { | |||||
| void addTestsTo(Vector v) { | |||||
| JUnitTest[] tests = createAllJUnitTest(); | JUnitTest[] tests = createAllJUnitTest(); | ||||
| v.ensureCapacity(v.size() + tests.length); | v.ensureCapacity(v.size() + tests.length); | ||||
| for (int i = 0; i < tests.length; i++) { | 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. | * @param filename the filename to "convert" to a classname. | ||||
| * @return the classname matching the filename. | * @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('/', '.') | return filename.replace(File.separatorChar, '.').replace('/', '.') | ||||
| .replace('\\', '.'); | .replace('\\', '.'); | ||||
| } | } | ||||
| @@ -93,6 +93,7 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter { | |||||
| /** | /** | ||||
| * @see JUnitResultFormatter#setSystemOutput(String) | * @see JUnitResultFormatter#setSystemOutput(String) | ||||
| */ | */ | ||||
| /** {@inheritDoc}. */ | |||||
| public void setSystemOutput(String out) { | public void setSystemOutput(String out) { | ||||
| systemOutput = out; | systemOutput = out; | ||||
| } | } | ||||
| @@ -100,6 +101,7 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter { | |||||
| /** | /** | ||||
| * @see JUnitResultFormatter#setSystemError(String) | * @see JUnitResultFormatter#setSystemError(String) | ||||
| */ | */ | ||||
| /** {@inheritDoc}. */ | |||||
| public void setSystemError(String err) { | public void setSystemError(String err) { | ||||
| systemError = err; | systemError = err; | ||||
| } | } | ||||
| @@ -60,6 +60,7 @@ public final class DOMUtil { | |||||
| * @param filter the filter that children should match. | * @param filter the filter that children should match. | ||||
| * @param recurse <tt>true</tt> if you want the list to be made recursively | * @param recurse <tt>true</tt> if you want the list to be made recursively | ||||
| * otherwise <tt>false</tt>. | * otherwise <tt>false</tt>. | ||||
| * @return the node list that matches the filter. | |||||
| */ | */ | ||||
| public static NodeList listChildNodes(Node parent, NodeFilter filter, boolean recurse) { | public static NodeList listChildNodes(Node parent, NodeFilter filter, boolean recurse) { | ||||
| NodeListImpl matches = new NodeListImpl(); | NodeListImpl matches = new NodeListImpl(); | ||||
| @@ -85,9 +86,18 @@ public final class DOMUtil { | |||||
| /** custom implementation of a nodelist */ | /** custom implementation of a nodelist */ | ||||
| public static class NodeListImpl extends Vector implements 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() { | public int getLength() { | ||||
| return size(); | 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) { | public Node item(int i) { | ||||
| try { | try { | ||||
| return (Node) elementAt(i); | return (Node) elementAt(i); | ||||
| @@ -205,6 +215,7 @@ public final class DOMUtil { | |||||
| } | } | ||||
| } | } | ||||
| } catch (DOMException ignored) { | } catch (DOMException ignored) { | ||||
| // Ignore | |||||
| } | } | ||||
| // bingo append it. (this should normally not be done here) | // bingo append it. (this should normally not be done here) | ||||
| @@ -59,10 +59,13 @@ public class FormatterElement { | |||||
| private String ifProperty; | private String ifProperty; | ||||
| private String unlessProperty; | private String unlessProperty; | ||||
| /** xml formatter class */ | |||||
| public static final String XML_FORMATTER_CLASS_NAME = | public static final String XML_FORMATTER_CLASS_NAME = | ||||
| "org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter"; | "org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter"; | ||||
| /** brief formatter class */ | |||||
| public static final String BRIEF_FORMATTER_CLASS_NAME = | public static final String BRIEF_FORMATTER_CLASS_NAME = | ||||
| "org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"; | "org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"; | ||||
| /** plain formatter class */ | |||||
| public static final String PLAIN_FORMATTER_CLASS_NAME = | public static final String PLAIN_FORMATTER_CLASS_NAME = | ||||
| "org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter"; | "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 | * <p> Sets <code>classname</code> attribute - so you can't use that | ||||
| * attribute if you use this one. | * attribute if you use this one. | ||||
| * @param type the enumerated value to use. | |||||
| */ | */ | ||||
| public void setType(TypeAttribute type) { | public void setType(TypeAttribute type) { | ||||
| if ("xml".equals(type.getValue())) { | if ("xml".equals(type.getValue())) { | ||||
| @@ -95,6 +99,7 @@ public class FormatterElement { | |||||
| * <p> Set name of class to be used as the formatter. | * <p> Set name of class to be used as the formatter. | ||||
| * | * | ||||
| * <p> This class must implement <code>JUnitResultFormatter</code> | * <p> This class must implement <code>JUnitResultFormatter</code> | ||||
| * @param classname the name of the formatter class. | |||||
| */ | */ | ||||
| public void setClassname(String classname) { | public void setClassname(String classname) { | ||||
| this.classname = classname; | this.classname = classname; | ||||
| @@ -109,15 +114,24 @@ public class FormatterElement { | |||||
| /** | /** | ||||
| * Get name of class to be used as the formatter. | * Get name of class to be used as the formatter. | ||||
| * @return the name of the class. | |||||
| */ | */ | ||||
| public String getClassname() { | public String getClassname() { | ||||
| return classname; | return classname; | ||||
| } | } | ||||
| /** | |||||
| * Set the extension to use for the report file. | |||||
| * @param ext the extension to use. | |||||
| */ | |||||
| public void setExtension(String ext) { | public void setExtension(String ext) { | ||||
| this.extension = ext; | this.extension = ext; | ||||
| } | } | ||||
| /** | |||||
| * Get the extension used for the report file. | |||||
| * @return the extension. | |||||
| */ | |||||
| public String getExtension() { | public String getExtension() { | ||||
| return extension; | return extension; | ||||
| } | } | ||||
| @@ -135,6 +149,7 @@ public class FormatterElement { | |||||
| * <p> Set output stream for formatter to use. | * <p> Set output stream for formatter to use. | ||||
| * | * | ||||
| * <p> Defaults to standard out. | * <p> Defaults to standard out. | ||||
| * @param out the output stream to use. | |||||
| */ | */ | ||||
| public void setOutput(OutputStream out) { | public void setOutput(OutputStream out) { | ||||
| this.out = out; | this.out = out; | ||||
| @@ -142,6 +157,8 @@ public class FormatterElement { | |||||
| /** | /** | ||||
| * Set whether the formatter should log to file. | * 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) { | public void setUseFile(boolean useFile) { | ||||
| this.useFile = useFile; | this.useFile = useFile; | ||||
| @@ -176,6 +193,8 @@ public class FormatterElement { | |||||
| /** | /** | ||||
| * Ensures that the selector passes the conditions placed | * Ensures that the selector passes the conditions placed | ||||
| * on it with <code>if</code> and <code>unless</code> properties. | * 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) { | public boolean shouldUse(Task t) { | ||||
| if (ifProperty != null && t.getProject().getProperty(ifProperty) == null) { | if (ifProperty != null && t.getProject().getProperty(ifProperty) == null) { | ||||
| @@ -215,9 +234,13 @@ public class FormatterElement { | |||||
| f = Class.forName(classname, true, loader); | f = Class.forName(classname, true, loader); | ||||
| } | } | ||||
| } catch (ClassNotFoundException e) { | } 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) { | } 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; | Object o = null; | ||||
| @@ -233,7 +256,8 @@ public class FormatterElement { | |||||
| throw new BuildException(classname | throw new BuildException(classname | ||||
| + " is not a JUnitResultFormatter"); | + " is not a JUnitResultFormatter"); | ||||
| } | } | ||||
| JUnitTaskMirror.JUnitResultFormatterMirror r = (JUnitTaskMirror.JUnitResultFormatterMirror) o; | |||||
| JUnitTaskMirror.JUnitResultFormatterMirror r = | |||||
| (JUnitTaskMirror.JUnitResultFormatterMirror) o; | |||||
| if (useFile && outFile != null) { | if (useFile && outFile != null) { | ||||
| try { | try { | ||||
| out = new BufferedOutputStream(new FileOutputStream(outFile)); | out = new BufferedOutputStream(new FileOutputStream(outFile)); | ||||
| @@ -251,6 +275,7 @@ public class FormatterElement { | |||||
| * <p> Use to enumerate options for <code>type</code> attribute. | * <p> Use to enumerate options for <code>type</code> attribute. | ||||
| */ | */ | ||||
| public static class TypeAttribute extends EnumeratedAttribute { | public static class TypeAttribute extends EnumeratedAttribute { | ||||
| /** {@inheritDoc}. */ | |||||
| public String[] getValues() { | public String[] getValues() { | ||||
| return new String[] {"plain", "xml", "brief"}; | return new String[] {"plain", "xml", "brief"}; | ||||
| } | } | ||||
| @@ -27,29 +27,37 @@ import org.apache.tools.ant.BuildException; | |||||
| * testrun. | * testrun. | ||||
| * | * | ||||
| */ | */ | ||||
| public interface JUnitResultFormatter extends TestListener, JUnitTaskMirror.JUnitResultFormatterMirror { | |||||
| public interface JUnitResultFormatter | |||||
| extends TestListener, JUnitTaskMirror.JUnitResultFormatterMirror { | |||||
| /** | /** | ||||
| * The whole testsuite started. | * The whole testsuite started. | ||||
| * @param suite the suite. | |||||
| * @throws BuildException on error. | |||||
| */ | */ | ||||
| void startTestSuite(JUnitTest suite) throws BuildException; | void startTestSuite(JUnitTest suite) throws BuildException; | ||||
| /** | /** | ||||
| * The whole testsuite ended. | * The whole testsuite ended. | ||||
| * @param suite the suite. | |||||
| * @throws BuildException on error. | |||||
| */ | */ | ||||
| void endTestSuite(JUnitTest suite) throws BuildException; | void endTestSuite(JUnitTest suite) throws BuildException; | ||||
| /** | /** | ||||
| * Sets the stream the formatter is supposed to write its results to. | * Sets the stream the formatter is supposed to write its results to. | ||||
| * @param out the output stream to use. | |||||
| */ | */ | ||||
| void setOutput(OutputStream out); | void setOutput(OutputStream out); | ||||
| /** | /** | ||||
| * This is what the test has written to System.out | * This is what the test has written to System.out | ||||
| * @param out the string to write. | |||||
| */ | */ | ||||
| void setSystemOutput(String out); | void setSystemOutput(String out); | ||||
| /** | /** | ||||
| * This is what the test has written to System.err | * This is what the test has written to System.err | ||||
| * @param err the string to write. | |||||
| */ | */ | ||||
| void setSystemError(String err); | void setSystemError(String err); | ||||
| } | } | ||||
| @@ -293,7 +293,7 @@ public class JUnitTask extends Task { | |||||
| * haltonfailure, errorproperty, failureproperty and filtertrace | * haltonfailure, errorproperty, failureproperty and filtertrace | ||||
| * can share a forked Java VM, so even if you set the value to | * can share a forked Java VM, so even if you set the value to | ||||
| * "once", Ant may need to fork mutliple VMs.</p> | * "once", Ant may need to fork mutliple VMs.</p> | ||||
| * | |||||
| * @param mode the mode to use. | |||||
| * @since Ant 1.6.2 | * @since Ant 1.6.2 | ||||
| */ | */ | ||||
| public void setForkMode(ForkMode mode) { | public void setForkMode(ForkMode mode) { | ||||
| @@ -618,7 +618,7 @@ public class JUnitTask extends Task { | |||||
| * a bootclaspath. | * a bootclaspath. | ||||
| * | * | ||||
| * <p>Doesn't have any effect unless fork is true.</p> | * <p>Doesn't have any effect unless fork is true.</p> | ||||
| * | |||||
| * @param cloneVm a <code>boolean</code> value. | |||||
| * @since Ant 1.7 | * @since Ant 1.7 | ||||
| */ | */ | ||||
| public void setCloneVm(boolean cloneVm) { | 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. | * 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 { | protected void execute(List tests) throws BuildException { | ||||
| JUnitTest test = null; | 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) | * @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 | * @since Ant 1.6 | ||||
| */ | */ | ||||
| @@ -1380,7 +1391,11 @@ public class JUnitTask extends Task { | |||||
| */ | */ | ||||
| private void logTimeout(FormatterElement[] feArray, JUnitTest test, String testCase) { | 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 | * @since Ant 1.7 | ||||
| */ | */ | ||||
| private void logVmCrash(FormatterElement[] feArray, JUnitTest test, String testCase) { | 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 | * @since Ant 1.6.2 | ||||
| */ | */ | ||||
| protected CommandlineJava getCommandline() { | protected CommandlineJava getCommandline() { | ||||
| @@ -1596,15 +1617,21 @@ public class JUnitTask extends Task { | |||||
| */ | */ | ||||
| public static final String PER_BATCH = "perBatch"; | public static final String PER_BATCH = "perBatch"; | ||||
| /** No arg constructor. */ | |||||
| public ForkMode() { | public ForkMode() { | ||||
| super(); | super(); | ||||
| } | } | ||||
| /** | |||||
| * Constructor using a value. | |||||
| * @param value the value to use - once, perTest or perBatch. | |||||
| */ | |||||
| public ForkMode(String value) { | public ForkMode(String value) { | ||||
| super(); | super(); | ||||
| setValue(value); | setValue(value); | ||||
| } | } | ||||
| /** {@inheritDoc}. */ | |||||
| public String[] getValues() { | public String[] getValues() { | ||||
| return new String[] {ONCE, PER_TEST, PER_BATCH}; | 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 | * if the runIndividual argument is true. Returns a collection of | ||||
| * lists of tests that share the same VM configuration and haven't | * lists of tests that share the same VM configuration and haven't | ||||
| * been executed yet. | * 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 | * @since 1.6.2 | ||||
| */ | */ | ||||
| protected Collection executeOrQueue(Enumeration testList, | protected Collection executeOrQueue(Enumeration testList, | ||||
| @@ -1645,7 +1674,10 @@ public class JUnitTask extends Task { | |||||
| * Logs information about failed tests, potentially stops | * Logs information about failed tests, potentially stops | ||||
| * processing (by throwing a BuildException) if a failure/error | * processing (by throwing a BuildException) if a failure/error | ||||
| * occurred or sets a property. | * 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 | * @since Ant 1.6.2 | ||||
| */ | */ | ||||
| protected void actOnTestResult(int exitValue, boolean wasKilled, | protected void actOnTestResult(int exitValue, boolean wasKilled, | ||||
| @@ -1660,7 +1692,9 @@ public class JUnitTask extends Task { | |||||
| * Logs information about failed tests, potentially stops | * Logs information about failed tests, potentially stops | ||||
| * processing (by throwing a BuildException) if a failure/error | * processing (by throwing a BuildException) if a failure/error | ||||
| * occurred or sets a property. | * 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 | * @since Ant 1.7 | ||||
| */ | */ | ||||
| protected void actOnTestResult(TestResultHolder result, JUnitTest test, | 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 { | protected class TestResultHolder { | ||||
| // CheckStyle:VisibilityModifier OFF - bc | |||||
| /** the exit code of the test. */ | |||||
| public int exitCode = JUnitTaskMirror.JUnitTestRunnerMirror.ERRORS; | public int exitCode = JUnitTaskMirror.JUnitTestRunnerMirror.ERRORS; | ||||
| /** true if the test timed out */ | |||||
| public boolean timedOut = false; | public boolean timedOut = false; | ||||
| /** true if the test crashed */ | |||||
| public boolean crashed = false; | public boolean crashed = false; | ||||
| // CheckStyle:VisibilityModifier ON | |||||
| } | } | ||||
| /** | /** | ||||
| * A stream handler for handling the junit task. | |||||
| * @since Ant 1.7 | * @since Ant 1.7 | ||||
| */ | */ | ||||
| protected static class JUnitLogOutputStream extends LogOutputStream { | protected static class JUnitLogOutputStream extends LogOutputStream { | ||||
| private Task task; // local copy since LogOutputStream.task is private | 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) { | public JUnitLogOutputStream(Task task, int level) { | ||||
| super(task, level); | super(task, level); | ||||
| this.task = task; | 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) { | protected void processLine(String line, int level) { | ||||
| if (line.startsWith(TESTLISTENER_PREFIX)) { | if (line.startsWith(TESTLISTENER_PREFIX)) { | ||||
| task.log(line, Project.MSG_VERBOSE); | 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 | * @since Ant 1.7 | ||||
| */ | */ | ||||
| protected static class JUnitLogStreamHandler extends PumpStreamHandler { | 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) { | public JUnitLogStreamHandler(Task task, int outlevel, int errlevel) { | ||||
| super(new JUnitLogOutputStream(task, outlevel), | super(new JUnitLogOutputStream(task, outlevel), | ||||
| new LogOutputStream(task, errlevel)); | new LogOutputStream(task, errlevel)); | ||||
| @@ -40,27 +40,61 @@ import org.apache.tools.ant.types.Permissions; | |||||
| */ | */ | ||||
| public interface JUnitTaskMirror { | 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, | void addVmExit(JUnitTest test, JUnitResultFormatterMirror formatter, | ||||
| OutputStream out, String message, String testCase); | 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, | JUnitTestRunnerMirror newJUnitTestRunner(JUnitTest test, boolean haltOnError, | ||||
| boolean filterTrace, boolean haltOnFailure, boolean showOutput, | boolean filterTrace, boolean haltOnFailure, boolean showOutput, | ||||
| boolean logTestListenerEvents, AntClassLoader classLoader); | boolean logTestListenerEvents, AntClassLoader classLoader); | ||||
| /** | |||||
| * Create a summary result formatter. | |||||
| * @return the created formatter. | |||||
| */ | |||||
| SummaryJUnitResultFormatterMirror newSummaryJUnitResultFormatter(); | 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); | 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); | void setWithOutAndErr(boolean value); | ||||
| } | } | ||||
| /** Interface that test runners implement. */ | |||||
| public interface JUnitTestRunnerMirror { | public interface JUnitTestRunnerMirror { | ||||
| /** | /** | ||||
| @@ -87,12 +121,26 @@ public interface JUnitTaskMirror { | |||||
| */ | */ | ||||
| int ERRORS = 2; | int ERRORS = 2; | ||||
| /** | |||||
| * Permissions for the test run. | |||||
| * @param perm the permissions to use. | |||||
| */ | |||||
| void setPermissions(Permissions perm); | void setPermissions(Permissions perm); | ||||
| /** Run the test. */ | |||||
| void run(); | void run(); | ||||
| /** | |||||
| * Add a formatter to the test. | |||||
| * @param formatter the formatter to use. | |||||
| */ | |||||
| void addFormatter(JUnitResultFormatterMirror formatter); | 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(); | int getRetCode(); | ||||
| void handleErrorFlush(String output); | void handleErrorFlush(String output); | ||||
| @@ -543,7 +543,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
| /** | /** | ||||
| * Permissions for the test run. | * Permissions for the test run. | ||||
| * @since Ant 1.6 | * @since Ant 1.6 | ||||
| * @param permissions | |||||
| * @param permissions the permissions to use. | |||||
| */ | */ | ||||
| public void setPermissions(Permissions permissions) { | public void setPermissions(Permissions permissions) { | ||||
| perm = permissions; | perm = permissions; | ||||
| @@ -689,7 +689,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
| } else if (args[i].startsWith(Constants.SHOWOUTPUT)) { | } else if (args[i].startsWith(Constants.SHOWOUTPUT)) { | ||||
| showOut = Project.toBoolean(args[i].substring(Constants.SHOWOUTPUT.length())); | showOut = Project.toBoolean(args[i].substring(Constants.SHOWOUTPUT.length())); | ||||
| } else if (args[i].startsWith(Constants.LOGTESTLISTENEREVENTS)) { | } 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)) { | } else if (args[i].startsWith(Constants.OUTPUT_TO_FORMATTERS)) { | ||||
| outputToFormat = Project.toBoolean( | outputToFormat = Project.toBoolean( | ||||
| args[i].substring(Constants.OUTPUT_TO_FORMATTERS.length())); | args[i].substring(Constants.OUTPUT_TO_FORMATTERS.length())); | ||||
| @@ -828,6 +829,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
| /** | /** | ||||
| * Returns a filtered stack trace. | * Returns a filtered stack trace. | ||||
| * This is ripped out of junit.runner.BaseTestRunner. | * 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) { | public static String getFilteredTrace(Throwable t) { | ||||
| String trace = StringUtils.getStackTrace(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 | * Filters stack frames from internal JUnit and Ant classes | ||||
| * @param stack the stack trace to filter. | |||||
| */ | */ | ||||
| public static String filterStack(String stack) { | public static String filterStack(String stack) { | ||||
| if (!filtertrace) { | if (!filtertrace) { | ||||
| @@ -936,7 +940,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
| return new TestListener() { | return new TestListener() { | ||||
| public void addError(Test test, Throwable t) { | public void addError(Test test, Throwable t) { | ||||
| if (junit4 && t instanceof AssertionFailedError) { | 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. | // So we need to help it a bit to retain compatibility for JUnit 3 tests. | ||||
| testListener.addFailure(test, (AssertionFailedError) t); | testListener.addFailure(test, (AssertionFailedError) t); | ||||
| } else if (junit4 && t.getClass().getName().equals("java.lang.AssertionError")) { | } 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 | AssertionFailedError failure = msg != null | ||||
| ? new AssertionFailedError(msg) : new AssertionFailedError(); | ? new AssertionFailedError(msg) : new AssertionFailedError(); | ||||
| // To compile on pre-JDK 4 (even though this should always succeed): | // 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}); | initCause.invoke(failure, new Object[] {t}); | ||||
| testListener.addFailure(test, failure); | testListener.addFailure(test, failure); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| @@ -996,7 +1002,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR | |||||
| e = res.errors(); | e = res.errors(); | ||||
| while (e.hasMoreElements()) { | while (e.hasMoreElements()) { | ||||
| Throwable t = ((TestFailure) e.nextElement()).thrownException(); | 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++; | failures++; | ||||
| } else { | } else { | ||||
| errors++; | errors++; | ||||
| @@ -54,6 +54,8 @@ public class JUnitVersionHelper { | |||||
| * | * | ||||
| * <p>Since Ant 1.7 also checks for JUnit4TestCaseFacade explicitly. | * <p>Since Ant 1.7 also checks for JUnit4TestCaseFacade explicitly. | ||||
| * This is used by junit.framework.JUnit4TestAdapter.</p> | * This is used by junit.framework.JUnit4TestAdapter.</p> | ||||
| * @param t the test. | |||||
| * @return the name of the test. | |||||
| */ | */ | ||||
| public static String getTestCaseName(Test t) { | public static String getTestCaseName(Test t) { | ||||
| if (t != null && t.getClass().getName().equals("junit.framework.JUnit4TestCaseFacade")) { | if (t != null && t.getClass().getName().equals("junit.framework.JUnit4TestCaseFacade")) { | ||||
| @@ -68,19 +68,23 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { | |||||
| private String systemOutput = null; | private String systemOutput = null; | ||||
| private String systemError = null; | private String systemError = null; | ||||
| /** No arg constructor */ | |||||
| public PlainJUnitResultFormatter() { | public PlainJUnitResultFormatter() { | ||||
| inner = new StringWriter(); | inner = new StringWriter(); | ||||
| wri = new PrintWriter(inner); | wri = new PrintWriter(inner); | ||||
| } | } | ||||
| /** {@inheritDoc}. */ | |||||
| public void setOutput(OutputStream out) { | public void setOutput(OutputStream out) { | ||||
| this.out = out; | this.out = out; | ||||
| } | } | ||||
| /** {@inheritDoc}. */ | |||||
| public void setSystemOutput(String out) { | public void setSystemOutput(String out) { | ||||
| systemOutput = out; | systemOutput = out; | ||||
| } | } | ||||
| /** {@inheritDoc}. */ | |||||
| public void setSystemError(String err) { | public void setSystemError(String err) { | ||||
| systemError = err; | systemError = err; | ||||
| } | } | ||||
| @@ -161,6 +165,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { | |||||
| * Interface TestListener. | * Interface TestListener. | ||||
| * | * | ||||
| * <p>A new Test is started. | * <p>A new Test is started. | ||||
| * @param t the test. | |||||
| */ | */ | ||||
| public void startTest(Test t) { | public void startTest(Test t) { | ||||
| testStarts.put(t, new Long(System.currentTimeMillis())); | testStarts.put(t, new Long(System.currentTimeMillis())); | ||||
| @@ -171,6 +176,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { | |||||
| * Interface TestListener. | * Interface TestListener. | ||||
| * | * | ||||
| * <p>A Test is finished. | * <p>A Test is finished. | ||||
| * @param t the test. | |||||
| */ | */ | ||||
| public void endTest(Test test) { | public void endTest(Test test) { | ||||
| if (Boolean.TRUE.equals(failed.get(test))) { | if (Boolean.TRUE.equals(failed.get(test))) { | ||||
| @@ -195,6 +201,8 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { | |||||
| * Interface TestListener for JUnit <= 3.4. | * Interface TestListener for JUnit <= 3.4. | ||||
| * | * | ||||
| * <p>A Test failed. | * <p>A Test failed. | ||||
| * @param test the test. | |||||
| * @param t the exception. | |||||
| */ | */ | ||||
| public void addFailure(Test test, Throwable t) { | public void addFailure(Test test, Throwable t) { | ||||
| formatError("\tFAILED", test, t); | formatError("\tFAILED", test, t); | ||||
| @@ -204,6 +212,8 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { | |||||
| * Interface TestListener for JUnit > 3.4. | * Interface TestListener for JUnit > 3.4. | ||||
| * | * | ||||
| * <p>A Test failed. | * <p>A Test failed. | ||||
| * @param test the test. | |||||
| * @param t the assertion that failed. | |||||
| */ | */ | ||||
| public void addFailure(Test test, AssertionFailedError t) { | public void addFailure(Test test, AssertionFailedError t) { | ||||
| addFailure(test, (Throwable) t); | addFailure(test, (Throwable) t); | ||||
| @@ -213,6 +223,8 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { | |||||
| * Interface TestListener. | * Interface TestListener. | ||||
| * | * | ||||
| * <p>An error occurred while running the test. | * <p>An error occurred while running the test. | ||||
| * @param test the test. | |||||
| * @param t the exception. | |||||
| */ | */ | ||||
| public void addError(Test test, Throwable t) { | public void addError(Test test, Throwable t) { | ||||
| formatError("\tCaused an ERROR", test, t); | formatError("\tCaused an ERROR", test, t); | ||||
| @@ -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. | * Formatter for timings. | ||||
| @@ -57,6 +57,7 @@ import org.xml.sax.SAXException; | |||||
| */ | */ | ||||
| public class XMLResultAggregator extends Task implements XMLConstants { | public class XMLResultAggregator extends Task implements XMLConstants { | ||||
| // CheckStyle:VisibilityModifier OFF - bc | |||||
| /** the list of all filesets, that should contains the xml to aggregate */ | /** the list of all filesets, that should contains the xml to aggregate */ | ||||
| protected Vector filesets = new Vector(); | protected Vector filesets = new Vector(); | ||||
| @@ -80,15 +81,19 @@ public class XMLResultAggregator extends Task implements XMLConstants { | |||||
| /** | /** | ||||
| * text checked for in tests, {@value} | * 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} | * 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} | * 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. | * Generate a report based on the document created by the merge. | ||||
| @@ -38,33 +38,35 @@ import org.apache.tools.ant.BuildException; | |||||
| */ | */ | ||||
| public class Xalan2Executor extends XalanExecutor { | 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(); | private TransformerFactory tfactory = TransformerFactory.newInstance(); | ||||
| /** {@inheritDoc}. */ | |||||
| protected String getImplementation() throws BuildException { | protected String getImplementation() throws BuildException { | ||||
| return tfactory.getClass().getName(); | return tfactory.getClass().getName(); | ||||
| } | } | ||||
| /** {@inheritDoc}. */ | |||||
| protected String getProcVersion(String classNameImpl) | protected String getProcVersion(String classNameImpl) | ||||
| throws BuildException { | throws BuildException { | ||||
| try { | try { | ||||
| // xalan 2 | // 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 | // xalan xsltc | ||||
| if (classNameImpl.equals(aPack | |||||
| if (classNameImpl.equals(APAC | |||||
| + "xsltc.trax.TransformerFactoryImpl")) { | + "xsltc.trax.TransformerFactoryImpl")) { | ||||
| return getXSLTCVersion(aPack + "xsltc.ProcessorVersion"); | |||||
| return getXSLTCVersion(APAC + "xsltc.ProcessorVersion"); | |||||
| } | } | ||||
| // jdk 1.5 xsltc | // jdk 1.5 xsltc | ||||
| if (classNameImpl | if (classNameImpl | ||||
| .equals(sPack + "internal.xsltc.trax.TransformerFactoryImpl")) { | |||||
| return getXSLTCVersion(sPack | |||||
| .equals(SPAC + "internal.xsltc.trax.TransformerFactoryImpl")) { | |||||
| return getXSLTCVersion(SPAC | |||||
| + "internal.xsltc.ProcessorVersion"); | + "internal.xsltc.ProcessorVersion"); | ||||
| } | } | ||||
| throw new BuildException("Could not find a valid processor version" | throw new BuildException("Could not find a valid processor version" | ||||
| @@ -76,16 +78,17 @@ public class Xalan2Executor extends XalanExecutor { | |||||
| } | } | ||||
| } | } | ||||
| /** {@inheritDoc}. */ | |||||
| void execute() throws Exception { | 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(); | OutputStream os = getOutputStream(); | ||||
| try { | try { | ||||
| tformer.setParameter("output.dir", caller.toDir.getAbsolutePath()); | tformer.setParameter("output.dir", caller.toDir.getAbsolutePath()); | ||||
| Result result = new StreamResult(os); | Result result = new StreamResult(os); | ||||
| tformer.transform(xml_src, result); | |||||
| tformer.transform(xmlSrc, result); | |||||
| } finally { | } finally { | ||||
| os.close(); | os.close(); | ||||
| } | } | ||||
| @@ -37,8 +37,10 @@ abstract class XalanExecutor { | |||||
| private static final String PACKAGE = | private static final String PACKAGE = | ||||
| "org.apache.tools.ant.taskdefs.optional.junit."; | "org.apache.tools.ant.taskdefs.optional.junit."; | ||||
| // CheckStyle:VisibilityModifier OFF - bc | |||||
| /** the transformer caller */ | /** the transformer caller */ | ||||
| protected AggregateTransformer caller; | protected AggregateTransformer caller; | ||||
| // CheckStyle:VisibilityModifier ON | |||||
| /** set the caller for this object. */ | /** set the caller for this object. */ | ||||
| private void setCaller(AggregateTransformer caller) { | private void setCaller(AggregateTransformer caller) { | ||||