git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270589 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -16,6 +16,7 @@ import java.net.URL; | |||||
| import javax.xml.parsers.DocumentBuilder; | import javax.xml.parsers.DocumentBuilder; | ||||
| import javax.xml.parsers.DocumentBuilderFactory; | import javax.xml.parsers.DocumentBuilderFactory; | ||||
| import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
| import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
| @@ -32,8 +33,8 @@ import org.w3c.dom.Element; | |||||
| * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | ||||
| */ | */ | ||||
| public class AggregateTransformer | public class AggregateTransformer | ||||
| extends AbstractLogEnabled | |||||
| { | { | ||||
| public final static String FRAMES = "frames"; | public final static String FRAMES = "frames"; | ||||
| public final static String NOFRAMES = "noframes"; | public final static String NOFRAMES = "noframes"; | ||||
| @@ -41,53 +42,40 @@ public class AggregateTransformer | |||||
| /** | /** | ||||
| * XML Parser factory | * XML Parser factory | ||||
| */ | */ | ||||
| protected final static DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); | |||||
| private final static DocumentBuilderFactory c_dbfactory = DocumentBuilderFactory.newInstance(); | |||||
| /** | /** | ||||
| * the xml document to process | * the xml document to process | ||||
| */ | */ | ||||
| protected Document document; | |||||
| private Document m_document; | |||||
| /** | /** | ||||
| * the format to use for the report. Must be <tt>FRAMES</tt> or <tt>NOFRAMES | * the format to use for the report. Must be <tt>FRAMES</tt> or <tt>NOFRAMES | ||||
| * </tt> | * </tt> | ||||
| */ | */ | ||||
| protected String format; | |||||
| private String m_format; | |||||
| /** | /** | ||||
| * the style directory. XSLs should be read from here if necessary | * the style directory. XSLs should be read from here if necessary | ||||
| */ | */ | ||||
| protected File styleDir; | |||||
| private File m_styleDir; | |||||
| /** | |||||
| * Task | |||||
| */ | |||||
| protected Task task; | |||||
| private Task m_task; | |||||
| /** | /** | ||||
| * the destination directory, this is the root from where html should be | * the destination directory, this is the root from where html should be | ||||
| * generated | * generated | ||||
| */ | */ | ||||
| protected File toDir; | |||||
| private File m_toDir; | |||||
| public AggregateTransformer( Task task ) | public AggregateTransformer( Task task ) | ||||
| { | { | ||||
| this.task = task; | |||||
| } | |||||
| /** | |||||
| * set the extension of the output files | |||||
| * | |||||
| * @param ext The new Extension value | |||||
| */ | |||||
| public void setExtension( String ext ) | |||||
| { | |||||
| task.getLogger().warn( "extension is not used anymore" ); | |||||
| m_task = task; | |||||
| } | } | ||||
| public void setFormat( Format format ) | public void setFormat( Format format ) | ||||
| { | { | ||||
| this.format = format.getValue(); | |||||
| m_format = format.getValue(); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -99,7 +87,7 @@ public class AggregateTransformer | |||||
| */ | */ | ||||
| public void setStyledir( File styledir ) | public void setStyledir( File styledir ) | ||||
| { | { | ||||
| this.styleDir = styledir; | |||||
| m_styleDir = styledir; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -109,12 +97,12 @@ public class AggregateTransformer | |||||
| */ | */ | ||||
| public void setTodir( File todir ) | public void setTodir( File todir ) | ||||
| { | { | ||||
| this.toDir = todir; | |||||
| m_toDir = todir; | |||||
| } | } | ||||
| public void setXmlDocument( Document doc ) | public void setXmlDocument( Document doc ) | ||||
| { | { | ||||
| this.document = doc; | |||||
| m_document = doc; | |||||
| } | } | ||||
| public void transform() | public void transform() | ||||
| @@ -124,7 +112,7 @@ public class AggregateTransformer | |||||
| final long t0 = System.currentTimeMillis(); | final long t0 = System.currentTimeMillis(); | ||||
| try | try | ||||
| { | { | ||||
| Element root = document.getDocumentElement(); | |||||
| Element root = m_document.getDocumentElement(); | |||||
| XalanExecutor executor = XalanExecutor.newInstance( this ); | XalanExecutor executor = XalanExecutor.newInstance( this ); | ||||
| executor.execute(); | executor.execute(); | ||||
| } | } | ||||
| @@ -148,7 +136,7 @@ public class AggregateTransformer | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| DocumentBuilder builder = dbfactory.newDocumentBuilder(); | |||||
| DocumentBuilder builder = c_dbfactory.newDocumentBuilder(); | |||||
| InputStream in = new FileInputStream( xmlfile ); | InputStream in = new FileInputStream( xmlfile ); | ||||
| try | try | ||||
| { | { | ||||
| @@ -178,12 +166,12 @@ public class AggregateTransformer | |||||
| throws IOException | throws IOException | ||||
| { | { | ||||
| String xslname = "junit-frames.xsl"; | String xslname = "junit-frames.xsl"; | ||||
| if( NOFRAMES.equals( format ) ) | |||||
| if( NOFRAMES.equals( m_format ) ) | |||||
| { | { | ||||
| xslname = "junit-noframes.xsl"; | xslname = "junit-noframes.xsl"; | ||||
| } | } | ||||
| URL url = null; | URL url = null; | ||||
| if( styleDir == null ) | |||||
| if( m_styleDir == null ) | |||||
| { | { | ||||
| url = getClass().getResource( "xsl/" + xslname ); | url = getClass().getResource( "xsl/" + xslname ); | ||||
| if( url == null ) | if( url == null ) | ||||
| @@ -193,7 +181,7 @@ public class AggregateTransformer | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| File file = new File( styleDir, xslname ); | |||||
| File file = new File( m_styleDir, xslname ); | |||||
| if( !file.exists() ) | if( !file.exists() ) | ||||
| { | { | ||||
| throw new FileNotFoundException( "Could not find file '" + file + "'" ); | throw new FileNotFoundException( "Could not find file '" + file + "'" ); | ||||
| @@ -212,16 +200,31 @@ public class AggregateTransformer | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| // set the destination directory relative from the project if needed. | // set the destination directory relative from the project if needed. | ||||
| if( toDir == null ) | |||||
| if( m_toDir == null ) | |||||
| { | { | ||||
| toDir = FileUtil.resolveFile( task.getBaseDirectory(), "." ); | |||||
| m_toDir = FileUtil.resolveFile( m_task.getBaseDirectory(), "." ); | |||||
| } | } | ||||
| else if( !toDir.isAbsolute() ) | |||||
| else if( !m_toDir.isAbsolute() ) | |||||
| { | { | ||||
| toDir = FileUtil.resolveFile( task.getBaseDirectory(), toDir.getPath() ); | |||||
| m_toDir = FileUtil.resolveFile( m_task.getBaseDirectory(), m_toDir.getPath() ); | |||||
| } | } | ||||
| } | } | ||||
| protected Document getDocument() | |||||
| { | |||||
| return m_document; | |||||
| } | |||||
| protected String getFormat() | |||||
| { | |||||
| return m_format; | |||||
| } | |||||
| protected File getToDir() | |||||
| { | |||||
| return m_toDir; | |||||
| } | |||||
| public static class Format extends EnumeratedAttribute | public static class Format extends EnumeratedAttribute | ||||
| { | { | ||||
| public String[] getValues() | public String[] getValues() | ||||
| @@ -18,9 +18,9 @@ import java.util.ArrayList; | |||||
| */ | */ | ||||
| public abstract class BaseTest | public abstract class BaseTest | ||||
| { | { | ||||
| protected boolean haltOnError = false; | |||||
| protected boolean haltOnFail = false; | |||||
| protected boolean filtertrace = true; | |||||
| protected boolean m_haltOnError = false; | |||||
| protected boolean m_haltOnFail = false; | |||||
| protected boolean m_filtertrace = true; | |||||
| protected boolean fork = false; | protected boolean fork = false; | ||||
| protected String ifProperty = null; | protected String ifProperty = null; | ||||
| protected String unlessProperty = null; | protected String unlessProperty = null; | ||||
| @@ -45,7 +45,7 @@ public abstract class BaseTest | |||||
| public void setFiltertrace( boolean value ) | public void setFiltertrace( boolean value ) | ||||
| { | { | ||||
| filtertrace = value; | |||||
| m_filtertrace = value; | |||||
| } | } | ||||
| public void setFork( boolean value ) | public void setFork( boolean value ) | ||||
| @@ -55,12 +55,12 @@ public abstract class BaseTest | |||||
| public void setHaltonerror( boolean value ) | public void setHaltonerror( boolean value ) | ||||
| { | { | ||||
| haltOnError = value; | |||||
| m_haltOnError = value; | |||||
| } | } | ||||
| public void setHaltonfailure( boolean value ) | public void setHaltonfailure( boolean value ) | ||||
| { | { | ||||
| haltOnFail = value; | |||||
| m_haltOnFail = value; | |||||
| } | } | ||||
| public void setIf( String propertyName ) | public void setIf( String propertyName ) | ||||
| @@ -95,7 +95,7 @@ public abstract class BaseTest | |||||
| public boolean getFiltertrace() | public boolean getFiltertrace() | ||||
| { | { | ||||
| return filtertrace; | |||||
| return m_filtertrace; | |||||
| } | } | ||||
| public boolean getFork() | public boolean getFork() | ||||
| @@ -105,12 +105,12 @@ public abstract class BaseTest | |||||
| public boolean getHaltonerror() | public boolean getHaltonerror() | ||||
| { | { | ||||
| return haltOnError; | |||||
| return m_haltOnError; | |||||
| } | } | ||||
| public boolean getHaltonfailure() | public boolean getHaltonfailure() | ||||
| { | { | ||||
| return haltOnFail; | |||||
| return m_haltOnFail; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -9,7 +9,9 @@ package org.apache.tools.ant.taskdefs.optional.junit; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Arrays; | |||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
| @@ -32,7 +34,6 @@ import org.apache.tools.ant.types.FileSet; | |||||
| */ | */ | ||||
| public final class BatchTest extends BaseTest | public final class BatchTest extends BaseTest | ||||
| { | { | ||||
| /** | /** | ||||
| * the list of filesets containing the testcase filename rules | * the list of filesets containing the testcase filename rules | ||||
| */ | */ | ||||
| @@ -74,9 +75,10 @@ public final class BatchTest extends BaseTest | |||||
| * JUnitTest</tt> instance. | * JUnitTest</tt> instance. | ||||
| */ | */ | ||||
| public final Iterator iterator() | public final Iterator iterator() | ||||
| throws TaskException | |||||
| { | { | ||||
| JUnitTest[] tests = createAllJUnitTest(); | |||||
| return Iterators.fromArray( tests ); | |||||
| final JUnitTest[] tests = createAllJUnitTest(); | |||||
| return Arrays.asList( tests ).iterator(); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -99,8 +101,9 @@ public final class BatchTest extends BaseTest | |||||
| * batch test. | * batch test. | ||||
| */ | */ | ||||
| final void addTestsTo( ArrayList v ) | final void addTestsTo( ArrayList v ) | ||||
| throws TaskException | |||||
| { | { | ||||
| JUnitTest[] tests = createAllJUnitTest(); | |||||
| final 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++ ) | ||||
| { | { | ||||
| @@ -121,6 +124,7 @@ public final class BatchTest extends BaseTest | |||||
| * it will return <tt>org/apache/Whatever</tt> . | * it will return <tt>org/apache/Whatever</tt> . | ||||
| */ | */ | ||||
| private String[] getFilenames() | private String[] getFilenames() | ||||
| throws TaskException | |||||
| { | { | ||||
| ArrayList v = new ArrayList(); | ArrayList v = new ArrayList(); | ||||
| final int size = this.filesets.size(); | final int size = this.filesets.size(); | ||||
| @@ -144,9 +148,7 @@ public final class BatchTest extends BaseTest | |||||
| } | } | ||||
| } | } | ||||
| String[] files = new String[ v.size() ]; | |||||
| v.copyInto( files ); | |||||
| return files; | |||||
| return (String[])v.toArray( new String[ v.size() ] ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -156,6 +158,7 @@ public final class BatchTest extends BaseTest | |||||
| * @return the array of all <tt>JUnitTest</tt> s that belongs to this batch. | * @return the array of all <tt>JUnitTest</tt> s that belongs to this batch. | ||||
| */ | */ | ||||
| private JUnitTest[] createAllJUnitTest() | private JUnitTest[] createAllJUnitTest() | ||||
| throws TaskException | |||||
| { | { | ||||
| String[] filenames = getFilenames(); | String[] filenames = getFilenames(); | ||||
| JUnitTest[] tests = new JUnitTest[ filenames.length ]; | JUnitTest[] tests = new JUnitTest[ filenames.length ]; | ||||
| @@ -179,9 +182,9 @@ public final class BatchTest extends BaseTest | |||||
| { | { | ||||
| JUnitTest test = new JUnitTest(); | JUnitTest test = new JUnitTest(); | ||||
| test.setName( classname ); | test.setName( classname ); | ||||
| test.setHaltonerror( this.haltOnError ); | |||||
| test.setHaltonfailure( this.haltOnFail ); | |||||
| test.setFiltertrace( this.filtertrace ); | |||||
| test.setHaltonerror( this.m_haltOnError ); | |||||
| test.setHaltonfailure( this.m_haltOnFail ); | |||||
| test.setFiltertrace( this.m_filtertrace ); | |||||
| test.setFork( this.fork ); | test.setFork( this.fork ); | ||||
| test.setIf( this.ifProperty ); | test.setIf( this.ifProperty ); | ||||
| test.setUnless( this.unlessProperty ); | test.setUnless( this.unlessProperty ); | ||||
| @@ -0,0 +1,100 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE.txt file. | |||||
| */ | |||||
| package org.apache.tools.ant.taskdefs.optional.junit; | |||||
| import java.util.Iterator; | |||||
| import java.util.NoSuchElementException; | |||||
| /** | |||||
| * Convenient enumeration over an array of enumeration. For example: <pre> | |||||
| * Iterator e1 = v1.iterator(); | |||||
| * while (e1.hasNext()){ | |||||
| * // do something | |||||
| * } | |||||
| * Iterator e2 = v2.iterator(); | |||||
| * while (e2.hasNext()){ | |||||
| * // do the same thing | |||||
| * } | |||||
| * </pre> can be written as: <pre> | |||||
| * Iterator[] enums = { v1.iterator(), v2.iterator() }; | |||||
| * Iterator e = Iterators.fromCompound(enums); | |||||
| * while (e.hasNext()){ | |||||
| * // do something | |||||
| * } | |||||
| * </pre> Note that the enumeration will skip null elements in the array. The | |||||
| * following is thus possible: <pre> | |||||
| * Iterator[] enums = { v1.iterator(), null, v2.iterator() }; // a null enumeration in the array | |||||
| * Iterator e = Iterators.fromCompound(enums); | |||||
| * while (e.hasNext()){ | |||||
| * // do something | |||||
| * } | |||||
| * </pre> | |||||
| * | |||||
| * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | |||||
| */ | |||||
| class CompoundIterator | |||||
| implements Iterator | |||||
| { | |||||
| /** | |||||
| * index in the enums array | |||||
| */ | |||||
| private int index = 0; | |||||
| /** | |||||
| * enumeration array | |||||
| */ | |||||
| private Iterator[] enumArray; | |||||
| public CompoundIterator( Iterator[] enumarray ) | |||||
| { | |||||
| this.enumArray = enumarray; | |||||
| } | |||||
| /** | |||||
| * Tests if this enumeration contains more elements. | |||||
| * | |||||
| * @return <code>true</code> if and only if this enumeration object contains | |||||
| * at least one more element to provide; <code>false</code> otherwise. | |||||
| */ | |||||
| public boolean hasNext() | |||||
| { | |||||
| while( index < enumArray.length ) | |||||
| { | |||||
| if( enumArray[ index ] != null && enumArray[ index ].hasNext() ) | |||||
| { | |||||
| return true; | |||||
| } | |||||
| index++; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /** | |||||
| * Returns the next element of this enumeration if this enumeration object | |||||
| * has at least one more element to provide. | |||||
| * | |||||
| * @return the next element of this enumeration. | |||||
| * @throws NoSuchElementException if no more elements exist. | |||||
| */ | |||||
| public Object next() | |||||
| throws NoSuchElementException | |||||
| { | |||||
| if( hasNext() ) | |||||
| { | |||||
| return enumArray[ index ].next(); | |||||
| } | |||||
| throw new NoSuchElementException(); | |||||
| } | |||||
| public void remove() | |||||
| throws UnsupportedOperationException | |||||
| { | |||||
| throw new UnsupportedOperationException(); | |||||
| } | |||||
| } | |||||
| @@ -7,7 +7,6 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs.optional.junit; | package org.apache.tools.ant.taskdefs.optional.junit; | ||||
| import java.util.ArrayList; | |||||
| import org.w3c.dom.Attr; | import org.w3c.dom.Attr; | ||||
| import org.w3c.dom.CDATASection; | import org.w3c.dom.CDATASection; | ||||
| import org.w3c.dom.Comment; | import org.w3c.dom.Comment; | ||||
| @@ -224,28 +223,4 @@ public final class DOMUtil | |||||
| boolean accept( Node node ); | boolean accept( Node node ); | ||||
| } | } | ||||
| /** | |||||
| * custom implementation of a nodelist | |||||
| * | |||||
| * @author RT | |||||
| */ | |||||
| public static class NodeListImpl extends ArrayList implements NodeList | |||||
| { | |||||
| public int getLength() | |||||
| { | |||||
| return size(); | |||||
| } | |||||
| public Node item( int i ) | |||||
| { | |||||
| try | |||||
| { | |||||
| return (Node)get( i ); | |||||
| } | |||||
| catch( ArrayIndexOutOfBoundsException e ) | |||||
| { | |||||
| return null;// conforming to NodeList interface | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -1,193 +0,0 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE.txt file. | |||||
| */ | |||||
| package org.apache.tools.ant.taskdefs.optional.junit; | |||||
| import java.util.Iterator; | |||||
| import java.util.NoSuchElementException; | |||||
| /** | |||||
| * A couple of methods related to enumerations that might be useful. This class | |||||
| * should probably disappear once the required JDK is set to 1.2 instead of 1.1. | |||||
| * | |||||
| * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | |||||
| */ | |||||
| public final class Iterators | |||||
| { | |||||
| private Iterators() | |||||
| { | |||||
| } | |||||
| /** | |||||
| * creates an enumeration from an array of objects. | |||||
| * | |||||
| * @param array the array of object to enumerate. | |||||
| * @return the enumeration over the array of objects. | |||||
| */ | |||||
| public static Iterator fromArray( Object[] array ) | |||||
| { | |||||
| return new ArrayIterator( array ); | |||||
| } | |||||
| /** | |||||
| * creates an enumeration from an array of enumeration. The created | |||||
| * enumeration will sequentially enumerate over all elements of each | |||||
| * enumeration and skip <tt>null</tt> enumeration elements in the array. | |||||
| * | |||||
| * @param enums the array of enumerations. | |||||
| * @return the enumeration over the array of enumerations. | |||||
| */ | |||||
| public static Iterator fromCompound( Iterator[] enums ) | |||||
| { | |||||
| return new CompoundIterator( enums ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Convenient enumeration over an array of objects. | |||||
| * | |||||
| * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | |||||
| */ | |||||
| class ArrayIterator implements Iterator | |||||
| { | |||||
| /** | |||||
| * object array | |||||
| */ | |||||
| private Object[] array; | |||||
| /** | |||||
| * current index | |||||
| */ | |||||
| private int pos; | |||||
| /** | |||||
| * Initialize a new enumeration that wraps an array. | |||||
| * | |||||
| * @param array the array of object to enumerate. | |||||
| */ | |||||
| public ArrayIterator( Object[] array ) | |||||
| { | |||||
| this.array = array; | |||||
| this.pos = 0; | |||||
| } | |||||
| /** | |||||
| * Tests if this enumeration contains more elements. | |||||
| * | |||||
| * @return <code>true</code> if and only if this enumeration object contains | |||||
| * at least one more element to provide; <code>false</code> otherwise. | |||||
| */ | |||||
| public boolean hasNext() | |||||
| { | |||||
| return ( pos < array.length ); | |||||
| } | |||||
| /** | |||||
| * Returns the next element of this enumeration if this enumeration object | |||||
| * has at least one more element to provide. | |||||
| * | |||||
| * @return the next element of this enumeration. | |||||
| * @throws NoSuchElementException if no more elements exist. | |||||
| */ | |||||
| public Object next() | |||||
| throws NoSuchElementException | |||||
| { | |||||
| if( hasNext() ) | |||||
| { | |||||
| Object o = array[ pos ]; | |||||
| pos++; | |||||
| return o; | |||||
| } | |||||
| throw new NoSuchElementException(); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Convenient enumeration over an array of enumeration. For example: <pre> | |||||
| * Iterator e1 = v1.iterator(); | |||||
| * while (e1.hasNext()){ | |||||
| * // do something | |||||
| * } | |||||
| * Iterator e2 = v2.iterator(); | |||||
| * while (e2.hasNext()){ | |||||
| * // do the same thing | |||||
| * } | |||||
| * </pre> can be written as: <pre> | |||||
| * Iterator[] enums = { v1.iterator(), v2.iterator() }; | |||||
| * Iterator e = Iterators.fromCompound(enums); | |||||
| * while (e.hasNext()){ | |||||
| * // do something | |||||
| * } | |||||
| * </pre> Note that the enumeration will skip null elements in the array. The | |||||
| * following is thus possible: <pre> | |||||
| * Iterator[] enums = { v1.iterator(), null, v2.iterator() }; // a null enumeration in the array | |||||
| * Iterator e = Iterators.fromCompound(enums); | |||||
| * while (e.hasNext()){ | |||||
| * // do something | |||||
| * } | |||||
| * </pre> | |||||
| * | |||||
| * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | |||||
| */ | |||||
| class CompoundIterator implements Iterator | |||||
| { | |||||
| /** | |||||
| * index in the enums array | |||||
| */ | |||||
| private int index = 0; | |||||
| /** | |||||
| * enumeration array | |||||
| */ | |||||
| private Iterator[] enumArray; | |||||
| public CompoundIterator( Iterator[] enumarray ) | |||||
| { | |||||
| this.enumArray = enumarray; | |||||
| } | |||||
| /** | |||||
| * Tests if this enumeration contains more elements. | |||||
| * | |||||
| * @return <code>true</code> if and only if this enumeration object contains | |||||
| * at least one more element to provide; <code>false</code> otherwise. | |||||
| */ | |||||
| public boolean hasNext() | |||||
| { | |||||
| while( index < enumArray.length ) | |||||
| { | |||||
| if( enumArray[ index ] != null && enumArray[ index ].hasNext() ) | |||||
| { | |||||
| return true; | |||||
| } | |||||
| index++; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /** | |||||
| * Returns the next element of this enumeration if this enumeration object | |||||
| * has at least one more element to provide. | |||||
| * | |||||
| * @return the next element of this enumeration. | |||||
| * @throws NoSuchElementException if no more elements exist. | |||||
| */ | |||||
| public Object next() | |||||
| throws NoSuchElementException | |||||
| { | |||||
| if( hasNext() ) | |||||
| { | |||||
| return enumArray[ index ].next(); | |||||
| } | |||||
| throw new NoSuchElementException(); | |||||
| } | |||||
| } | |||||
| @@ -21,7 +21,7 @@ import java.util.Properties; | |||||
| import java.util.Random; | import java.util.Random; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.taskdefs.exec.Execute; | |||||
| import org.apache.tools.ant.taskdefs.exec.Execute2; | |||||
| import org.apache.tools.ant.taskdefs.exec.LogOutputStream; | import org.apache.tools.ant.taskdefs.exec.LogOutputStream; | ||||
| import org.apache.tools.ant.types.Argument; | import org.apache.tools.ant.types.Argument; | ||||
| import org.apache.tools.ant.types.CommandlineJava; | import org.apache.tools.ant.types.CommandlineJava; | ||||
| @@ -348,7 +348,7 @@ public class JUnitTask extends Task | |||||
| */ | */ | ||||
| public Path createClasspath() | public Path createClasspath() | ||||
| { | { | ||||
| return commandline.createClasspath( getProject() ).createPath(); | |||||
| return commandline.createClasspath().createPath(); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -408,6 +408,7 @@ public class JUnitTask extends Task | |||||
| * @return The IndividualTests value | * @return The IndividualTests value | ||||
| */ | */ | ||||
| protected Iterator getIndividualTests() | protected Iterator getIndividualTests() | ||||
| throws TaskException | |||||
| { | { | ||||
| Iterator[] enums = new Iterator[ batchTests.size() + 1 ]; | Iterator[] enums = new Iterator[ batchTests.size() + 1 ]; | ||||
| for( int i = 0; i < batchTests.size(); i++ ) | for( int i = 0; i < batchTests.size(); i++ ) | ||||
| @@ -416,7 +417,7 @@ public class JUnitTask extends Task | |||||
| enums[ i ] = batchtest.iterator(); | enums[ i ] = batchtest.iterator(); | ||||
| } | } | ||||
| enums[ enums.length - 1 ] = tests.iterator(); | enums[ enums.length - 1 ] = tests.iterator(); | ||||
| return Iterators.fromCompound( enums ); | |||||
| return new CompoundIterator( enums ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -482,7 +483,7 @@ public class JUnitTask extends Task | |||||
| protected Iterator allTests() | protected Iterator allTests() | ||||
| { | { | ||||
| Iterator[] enums = {tests.iterator(), batchTests.iterator()}; | Iterator[] enums = {tests.iterator(), batchTests.iterator()}; | ||||
| return Iterator.fromCompound( enums ); | |||||
| return new CompoundIterator( enums ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -585,13 +586,11 @@ public class JUnitTask extends Task | |||||
| * @param watchdog the watchdog in charge of cancelling the test if it | * @param watchdog the watchdog in charge of cancelling the test if it | ||||
| * exceeds a certain amount of time. Can be <tt>null</tt> , in this | * exceeds a certain amount of time. Can be <tt>null</tt> , in this | ||||
| * case the test could probably hang forever. | * case the test could probably hang forever. | ||||
| * @return Description of the Returned Value | |||||
| * @exception TaskException Description of Exception | |||||
| */ | */ | ||||
| private int executeAsForked( JUnitTest test ) | private int executeAsForked( JUnitTest test ) | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| CommandlineJava cmd = (CommandlineJava)commandline.clone(); | |||||
| CommandlineJava cmd = commandline;//(CommandlineJava)commandline.clone(); | |||||
| cmd.setClassname( "org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" ); | cmd.setClassname( "org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" ); | ||||
| cmd.createArgument().setValue( test.getName() ); | cmd.createArgument().setValue( test.getName() ); | ||||
| @@ -642,10 +641,8 @@ public class JUnitTask extends Task | |||||
| throw new TaskException( "Error creating temporary properties file.", ioe ); | throw new TaskException( "Error creating temporary properties file.", ioe ); | ||||
| } | } | ||||
| final Execute exe = new Execute(); | |||||
| exe.setOutput( new LogOutputStream( getLogger(), false ) ); | |||||
| exe.setError( new LogOutputStream( getLogger(), true ) ); | |||||
| final Execute2 exe = new Execute2(); | |||||
| setupLogger( exe ); | |||||
| exe.setCommandline( cmd.getCommandline() ); | exe.setCommandline( cmd.getCommandline() ); | ||||
| if( dir != null ) | if( dir != null ) | ||||
| { | { | ||||
| @@ -673,10 +670,6 @@ public class JUnitTask extends Task | |||||
| /** | /** | ||||
| * Execute inside VM. | * Execute inside VM. | ||||
| * | |||||
| * @param test Description of Parameter | |||||
| * @return Description of the Returned Value | |||||
| * @exception TaskException Description of Exception | |||||
| */ | */ | ||||
| private int executeInVM( JUnitTest test ) | private int executeInVM( JUnitTest test ) | ||||
| throws TaskException | throws TaskException | ||||
| @@ -748,11 +741,9 @@ public class JUnitTask extends Task | |||||
| private FormatterElement[] mergeFormatters( JUnitTest test ) | private FormatterElement[] mergeFormatters( JUnitTest test ) | ||||
| { | { | ||||
| ArrayList feArrayList = (ArrayList)formatters.clone(); | |||||
| final ArrayList feArrayList = (ArrayList)formatters.clone(); | |||||
| test.addFormattersTo( feArrayList ); | test.addFormattersTo( feArrayList ); | ||||
| FormatterElement[] feArray = new FormatterElement[ feArrayList.size() ]; | |||||
| feArrayList.copyInto( feArray ); | |||||
| return feArray; | |||||
| return (FormatterElement[])feArrayList.toArray( new FormatterElement[ feArrayList.size() ] ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -29,25 +29,27 @@ import org.apache.tools.ant.Project; | |||||
| */ | */ | ||||
| public class JUnitTest extends BaseTest | public class JUnitTest extends BaseTest | ||||
| { | { | ||||
| /** | /** | ||||
| * the name of the test case | * the name of the test case | ||||
| */ | */ | ||||
| private String name = null; | |||||
| private String m_name; | |||||
| /** | /** | ||||
| * the name of the result file | * the name of the result file | ||||
| */ | */ | ||||
| private String outfile = null; | |||||
| private String m_outfile; | |||||
| // Snapshot of the system properties | // Snapshot of the system properties | ||||
| private Properties props = null; | |||||
| private long runTime; | |||||
| private Properties m_props; | |||||
| private long m_runTime; | |||||
| // @todo this is duplicating TestResult information. Only the time is not | // @todo this is duplicating TestResult information. Only the time is not | ||||
| // part of the result. So we'd better derive a new class from TestResult | // part of the result. So we'd better derive a new class from TestResult | ||||
| // and deal with it. (SB) | // and deal with it. (SB) | ||||
| private long runs, failures, errors; | |||||
| private long m_runs; | |||||
| private long m_failures; | |||||
| private long m_errors; | |||||
| public JUnitTest() | public JUnitTest() | ||||
| { | { | ||||
| @@ -55,64 +57,63 @@ public class JUnitTest extends BaseTest | |||||
| public JUnitTest( String name ) | public JUnitTest( String name ) | ||||
| { | { | ||||
| this.name = name; | |||||
| m_name = name; | |||||
| } | } | ||||
| public JUnitTest( String name, boolean haltOnError, boolean haltOnFailure, boolean filtertrace ) | |||||
| public JUnitTest( final String name, | |||||
| final boolean haltOnError, | |||||
| final boolean haltOnFailure, | |||||
| final boolean filtertrace ) | |||||
| { | { | ||||
| this.name = name; | |||||
| this.haltOnError = haltOnError; | |||||
| this.haltOnFail = haltOnFailure; | |||||
| this.filtertrace = filtertrace; | |||||
| m_name = name; | |||||
| m_haltOnError = haltOnError; | |||||
| m_haltOnFail = haltOnFailure; | |||||
| m_filtertrace = filtertrace; | |||||
| } | } | ||||
| public void setCounts( long runs, long failures, long errors ) | public void setCounts( long runs, long failures, long errors ) | ||||
| { | { | ||||
| this.runs = runs; | |||||
| this.failures = failures; | |||||
| this.errors = errors; | |||||
| m_runs = runs; | |||||
| m_failures = failures; | |||||
| m_errors = errors; | |||||
| } | } | ||||
| /** | /** | ||||
| * Set the name of the test class. | * Set the name of the test class. | ||||
| * | |||||
| * @param value The new Name value | |||||
| */ | */ | ||||
| public void setName( String value ) | |||||
| public void setName( final String value ) | |||||
| { | { | ||||
| name = value; | |||||
| m_name = value; | |||||
| } | } | ||||
| /** | /** | ||||
| * Set the name of the output file. | * Set the name of the output file. | ||||
| * | |||||
| * @param value The new Outfile value | |||||
| */ | */ | ||||
| public void setOutfile( String value ) | |||||
| public void setOutfile( final String value ) | |||||
| { | { | ||||
| outfile = value; | |||||
| m_outfile = value; | |||||
| } | } | ||||
| public void setProperties( Hashtable p ) | |||||
| public void setProperties( final Hashtable properties ) | |||||
| { | { | ||||
| props = new Properties(); | |||||
| for( Iterator enum = p.keys(); enum.hasNext(); ) | |||||
| m_props = new Properties(); | |||||
| final Iterator enum = properties.keySet().iterator(); | |||||
| while( enum.hasNext() ) | |||||
| { | { | ||||
| Object key = enum.next(); | |||||
| props.put( key, p.get( key ) ); | |||||
| final Object key = enum.next(); | |||||
| final Object value = properties.get( key ); | |||||
| m_props.put( key, value ); | |||||
| } | } | ||||
| } | } | ||||
| public void setRunTime( long runTime ) | |||||
| public void setRunTime( final long runTime ) | |||||
| { | { | ||||
| this.runTime = runTime; | |||||
| m_runTime = runTime; | |||||
| } | } | ||||
| public FormatterElement[] getFormatters() | public FormatterElement[] getFormatters() | ||||
| { | { | ||||
| FormatterElement[] fes = new FormatterElement[ formatters.size() ]; | |||||
| formatters.copyInto( fes ); | |||||
| return fes; | |||||
| return (FormatterElement[])formatters.toArray( new FormatterElement[ formatters.size() ] ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -122,7 +123,7 @@ public class JUnitTest extends BaseTest | |||||
| */ | */ | ||||
| public String getName() | public String getName() | ||||
| { | { | ||||
| return name; | |||||
| return m_name; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -132,32 +133,32 @@ public class JUnitTest extends BaseTest | |||||
| */ | */ | ||||
| public String getOutfile() | public String getOutfile() | ||||
| { | { | ||||
| return outfile; | |||||
| return m_outfile; | |||||
| } | } | ||||
| public Properties getProperties() | public Properties getProperties() | ||||
| { | { | ||||
| return props; | |||||
| return m_props; | |||||
| } | } | ||||
| public long getRunTime() | public long getRunTime() | ||||
| { | { | ||||
| return runTime; | |||||
| return m_runTime; | |||||
| } | } | ||||
| public long errorCount() | public long errorCount() | ||||
| { | { | ||||
| return errors; | |||||
| return m_errors; | |||||
| } | } | ||||
| public long failureCount() | public long failureCount() | ||||
| { | { | ||||
| return failures; | |||||
| return m_failures; | |||||
| } | } | ||||
| public long runCount() | public long runCount() | ||||
| { | { | ||||
| return runs; | |||||
| return m_runs; | |||||
| } | } | ||||
| public boolean shouldRun( Project p ) | public boolean shouldRun( Project p ) | ||||
| @@ -177,15 +178,9 @@ public class JUnitTest extends BaseTest | |||||
| /** | /** | ||||
| * Convenient method to add formatters to a vector | * Convenient method to add formatters to a vector | ||||
| * | |||||
| * @param v The feature to be added to the FormattersTo attribute | |||||
| */ | */ | ||||
| void addFormattersTo( ArrayList v ) | void addFormattersTo( ArrayList v ) | ||||
| { | { | ||||
| final int count = formatters.size(); | |||||
| for( int i = 0; i < count; i++ ) | |||||
| { | |||||
| v.add( formatters.get( i ) ); | |||||
| } | |||||
| v.addAll( formatters ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -19,7 +19,6 @@ import java.io.StringWriter; | |||||
| import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Hashtable; | import java.util.Hashtable; | ||||
| import java.util.Iterator; | |||||
| import java.util.Properties; | import java.util.Properties; | ||||
| import junit.framework.AssertionFailedError; | import junit.framework.AssertionFailedError; | ||||
| import junit.framework.Test; | import junit.framework.Test; | ||||
| @@ -46,10 +45,9 @@ import org.apache.myrmidon.api.TaskException; | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| * @author <a href="mailto:erik@hatcher.net">Erik Hatcher</a> | * @author <a href="mailto:erik@hatcher.net">Erik Hatcher</a> | ||||
| */ | */ | ||||
| public class JUnitTestRunner implements TestListener | |||||
| public class JUnitTestRunner | |||||
| implements TestListener | |||||
| { | { | ||||
| /** | /** | ||||
| * No problems with this test. | * No problems with this test. | ||||
| */ | */ | ||||
| @@ -70,7 +68,8 @@ public class JUnitTestRunner implements TestListener | |||||
| */ | */ | ||||
| private static boolean filtertrace = true; | private static boolean filtertrace = true; | ||||
| private final static String[] DEFAULT_TRACE_FILTERS = new String[]{ | |||||
| private final static String[] DEFAULT_TRACE_FILTERS = new String[] | |||||
| { | |||||
| "junit.framework.TestCase", | "junit.framework.TestCase", | ||||
| "junit.framework.TestResult", | "junit.framework.TestResult", | ||||
| "junit.framework.TestSuite", | "junit.framework.TestSuite", | ||||
| @@ -82,57 +81,57 @@ public class JUnitTestRunner implements TestListener | |||||
| "org.apache.tools.ant." | "org.apache.tools.ant." | ||||
| }; | }; | ||||
| private static ArrayList fromCmdLine = new ArrayList(); | |||||
| private static ArrayList m_fromCmdLine = new ArrayList(); | |||||
| /** | /** | ||||
| * Holds the registered formatters. | * Holds the registered formatters. | ||||
| */ | */ | ||||
| private ArrayList formatters = new ArrayList(); | |||||
| private ArrayList m_formatters = new ArrayList(); | |||||
| /** | /** | ||||
| * Do we stop on errors. | * Do we stop on errors. | ||||
| */ | */ | ||||
| private boolean haltOnError = false; | |||||
| private boolean m_haltOnError; | |||||
| /** | /** | ||||
| * Do we stop on test failures. | * Do we stop on test failures. | ||||
| */ | */ | ||||
| private boolean haltOnFailure = false; | |||||
| private boolean m_haltOnFailure; | |||||
| /** | /** | ||||
| * The corresponding testsuite. | * The corresponding testsuite. | ||||
| */ | */ | ||||
| private Test suite = null; | |||||
| private Test m_suite; | |||||
| /** | /** | ||||
| * Returncode | * Returncode | ||||
| */ | */ | ||||
| private int retCode = SUCCESS; | |||||
| private int m_retCode = SUCCESS; | |||||
| /** | /** | ||||
| * Exception caught in constructor. | * Exception caught in constructor. | ||||
| */ | */ | ||||
| private Exception exception; | |||||
| private Exception m_exception; | |||||
| /** | /** | ||||
| * The TestSuite we are currently running. | * The TestSuite we are currently running. | ||||
| */ | */ | ||||
| private JUnitTest junitTest; | |||||
| private JUnitTest m_junitTest; | |||||
| /** | /** | ||||
| * Collects TestResults. | * Collects TestResults. | ||||
| */ | */ | ||||
| private TestResult res; | |||||
| private TestResult m_res; | |||||
| /** | /** | ||||
| * output written during the test | * output written during the test | ||||
| */ | */ | ||||
| private PrintStream systemError; | |||||
| private PrintStream m_systemError; | |||||
| /** | /** | ||||
| * Error output during the test | * Error output during the test | ||||
| */ | */ | ||||
| private PrintStream systemOut; | |||||
| private PrintStream m_systemOut; | |||||
| /** | /** | ||||
| * Constructor for fork=true or when the user hasn't specified a classpath. | * Constructor for fork=true or when the user hasn't specified a classpath. | ||||
| @@ -142,8 +141,10 @@ public class JUnitTestRunner implements TestListener | |||||
| * @param filtertrace Description of Parameter | * @param filtertrace Description of Parameter | ||||
| * @param haltOnFailure Description of Parameter | * @param haltOnFailure Description of Parameter | ||||
| */ | */ | ||||
| public JUnitTestRunner( JUnitTest test, boolean haltOnError, boolean filtertrace, | |||||
| boolean haltOnFailure ) | |||||
| public JUnitTestRunner( final JUnitTest test, | |||||
| final boolean haltOnError, | |||||
| final boolean filtertrace, | |||||
| final boolean haltOnFailure ) | |||||
| { | { | ||||
| this( test, haltOnError, filtertrace, haltOnFailure, null ); | this( test, haltOnError, filtertrace, haltOnFailure, null ); | ||||
| } | } | ||||
| @@ -162,9 +163,9 @@ public class JUnitTestRunner implements TestListener | |||||
| { | { | ||||
| //JUnitTestRunner.filtertrace = filtertrace; | //JUnitTestRunner.filtertrace = filtertrace; | ||||
| this.filtertrace = filtertrace; | this.filtertrace = filtertrace; | ||||
| this.junitTest = test; | |||||
| this.haltOnError = haltOnError; | |||||
| this.haltOnFailure = haltOnFailure; | |||||
| this.m_junitTest = test; | |||||
| this.m_haltOnError = haltOnError; | |||||
| this.m_haltOnFailure = haltOnFailure; | |||||
| try | try | ||||
| { | { | ||||
| @@ -196,20 +197,20 @@ public class JUnitTestRunner implements TestListener | |||||
| // if there is a suite method available, then try | // if there is a suite method available, then try | ||||
| // to extract the suite from it. If there is an error | // to extract the suite from it. If there is an error | ||||
| // here it will be caught below and reported. | // here it will be caught below and reported. | ||||
| suite = (Test)suiteMethod.invoke( null, new Class[ 0 ] ); | |||||
| m_suite = (Test)suiteMethod.invoke( null, new Class[ 0 ] ); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| // try to extract a test suite automatically | // try to extract a test suite automatically | ||||
| // this will generate warnings if the class is no suitable Test | // this will generate warnings if the class is no suitable Test | ||||
| suite = new TestSuite( testClass ); | |||||
| m_suite = new TestSuite( testClass ); | |||||
| } | } | ||||
| } | } | ||||
| catch( Exception e ) | catch( Exception e ) | ||||
| { | { | ||||
| retCode = ERRORS; | |||||
| exception = e; | |||||
| m_retCode = ERRORS; | |||||
| m_exception = e; | |||||
| } | } | ||||
| } | } | ||||
| @@ -339,7 +340,7 @@ public class JUnitTestRunner implements TestListener | |||||
| * @exception IOException Description of Exception | * @exception IOException Description of Exception | ||||
| */ | */ | ||||
| public static void main( String[] args ) | public static void main( String[] args ) | ||||
| throws IOException | |||||
| throws IOException, TaskException | |||||
| { | { | ||||
| boolean exitAtEnd = true; | boolean exitAtEnd = true; | ||||
| boolean haltError = false; | boolean haltError = false; | ||||
| @@ -391,11 +392,7 @@ public class JUnitTestRunner implements TestListener | |||||
| // Add/overlay system properties on the properties from the Ant project | // Add/overlay system properties on the properties from the Ant project | ||||
| Hashtable p = System.getProperties(); | Hashtable p = System.getProperties(); | ||||
| for( Iterator enum = p.keys(); enum.hasNext(); ) | |||||
| { | |||||
| Object key = enum.next(); | |||||
| props.put( key, p.get( key ) ); | |||||
| } | |||||
| props.putAll( p ); | |||||
| t.setProperties( props ); | t.setProperties( props ); | ||||
| JUnitTestRunner runner = new JUnitTestRunner( t, haltError, stackfilter, haltFail ); | JUnitTestRunner runner = new JUnitTestRunner( t, haltError, stackfilter, haltFail ); | ||||
| @@ -426,7 +423,7 @@ public class JUnitTestRunner implements TestListener | |||||
| fe.setClassname( line.substring( 0, pos ) ); | fe.setClassname( line.substring( 0, pos ) ); | ||||
| fe.setOutfile( new File( line.substring( pos + 1 ) ) ); | fe.setOutfile( new File( line.substring( pos + 1 ) ) ); | ||||
| } | } | ||||
| fromCmdLine.add( fe.createFormatter() ); | |||||
| m_fromCmdLine.add( fe.createFormatter() ); | |||||
| } | } | ||||
| private static boolean filterLine( String line ) | private static boolean filterLine( String line ) | ||||
| @@ -443,9 +440,9 @@ public class JUnitTestRunner implements TestListener | |||||
| private static void transferFormatters( JUnitTestRunner runner ) | private static void transferFormatters( JUnitTestRunner runner ) | ||||
| { | { | ||||
| for( int i = 0; i < fromCmdLine.size(); i++ ) | |||||
| for( int i = 0; i < m_fromCmdLine.size(); i++ ) | |||||
| { | { | ||||
| runner.addFormatter( (JUnitResultFormatter)fromCmdLine.get( i ) ); | |||||
| runner.addFormatter( (JUnitResultFormatter)m_fromCmdLine.get( i ) ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -456,7 +453,7 @@ public class JUnitTestRunner implements TestListener | |||||
| */ | */ | ||||
| public int getRetCode() | public int getRetCode() | ||||
| { | { | ||||
| return retCode; | |||||
| return m_retCode; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -469,9 +466,9 @@ public class JUnitTestRunner implements TestListener | |||||
| */ | */ | ||||
| public void addError( Test test, Throwable t ) | public void addError( Test test, Throwable t ) | ||||
| { | { | ||||
| if( haltOnError ) | |||||
| if( m_haltOnError ) | |||||
| { | { | ||||
| res.stop(); | |||||
| m_res.stop(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -485,9 +482,9 @@ public class JUnitTestRunner implements TestListener | |||||
| */ | */ | ||||
| public void addFailure( Test test, Throwable t ) | public void addFailure( Test test, Throwable t ) | ||||
| { | { | ||||
| if( haltOnFailure ) | |||||
| if( m_haltOnFailure ) | |||||
| { | { | ||||
| res.stop(); | |||||
| m_res.stop(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -506,7 +503,7 @@ public class JUnitTestRunner implements TestListener | |||||
| public void addFormatter( JUnitResultFormatter f ) | public void addFormatter( JUnitResultFormatter f ) | ||||
| { | { | ||||
| formatters.add( f ); | |||||
| m_formatters.add( f ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -521,63 +518,65 @@ public class JUnitTestRunner implements TestListener | |||||
| } | } | ||||
| public void run() | public void run() | ||||
| throws TaskException | |||||
| { | { | ||||
| res = new TestResult(); | |||||
| res.addListener( this ); | |||||
| for( int i = 0; i < formatters.size(); i++ ) | |||||
| m_res = new TestResult(); | |||||
| m_res.addListener( this ); | |||||
| for( int i = 0; i < m_formatters.size(); i++ ) | |||||
| { | { | ||||
| res.addListener( (TestListener)formatters.get( i ) ); | |||||
| final TestListener listener = (TestListener)m_formatters.get( i ); | |||||
| m_res.addListener( listener ); | |||||
| } | } | ||||
| long start = System.currentTimeMillis(); | long start = System.currentTimeMillis(); | ||||
| fireStartTestSuite(); | fireStartTestSuite(); | ||||
| if( exception != null ) | |||||
| if( m_exception != null ) | |||||
| {// had an exception in the constructor | {// had an exception in the constructor | ||||
| for( int i = 0; i < formatters.size(); i++ ) | |||||
| for( int i = 0; i < m_formatters.size(); i++ ) | |||||
| { | { | ||||
| ( (TestListener)formatters.get( i ) ).addError( null, | |||||
| exception ); | |||||
| ( (TestListener)m_formatters.get( i ) ).addError( null, | |||||
| m_exception ); | |||||
| } | } | ||||
| junitTest.setCounts( 1, 0, 1 ); | |||||
| junitTest.setRunTime( 0 ); | |||||
| m_junitTest.setCounts( 1, 0, 1 ); | |||||
| m_junitTest.setRunTime( 0 ); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| ByteArrayOutputStream errStrm = new ByteArrayOutputStream(); | ByteArrayOutputStream errStrm = new ByteArrayOutputStream(); | ||||
| systemError = new PrintStream( errStrm ); | |||||
| m_systemError = new PrintStream( errStrm ); | |||||
| ByteArrayOutputStream outStrm = new ByteArrayOutputStream(); | ByteArrayOutputStream outStrm = new ByteArrayOutputStream(); | ||||
| systemOut = new PrintStream( outStrm ); | |||||
| m_systemOut = new PrintStream( outStrm ); | |||||
| try | try | ||||
| { | { | ||||
| suite.run( res ); | |||||
| m_suite.run( m_res ); | |||||
| } | } | ||||
| finally | finally | ||||
| { | { | ||||
| systemError.close(); | |||||
| systemError = null; | |||||
| systemOut.close(); | |||||
| systemOut = null; | |||||
| m_systemError.close(); | |||||
| m_systemError = null; | |||||
| m_systemOut.close(); | |||||
| m_systemOut = null; | |||||
| sendOutAndErr( new String( outStrm.toByteArray() ), | sendOutAndErr( new String( outStrm.toByteArray() ), | ||||
| new String( errStrm.toByteArray() ) ); | new String( errStrm.toByteArray() ) ); | ||||
| junitTest.setCounts( res.runCount(), res.failureCount(), | |||||
| res.errorCount() ); | |||||
| junitTest.setRunTime( System.currentTimeMillis() - start ); | |||||
| m_junitTest.setCounts( m_res.runCount(), m_res.failureCount(), | |||||
| m_res.errorCount() ); | |||||
| m_junitTest.setRunTime( System.currentTimeMillis() - start ); | |||||
| } | } | ||||
| } | } | ||||
| fireEndTestSuite(); | fireEndTestSuite(); | ||||
| if( retCode != SUCCESS || res.errorCount() != 0 ) | |||||
| if( m_retCode != SUCCESS || m_res.errorCount() != 0 ) | |||||
| { | { | ||||
| retCode = ERRORS; | |||||
| m_retCode = ERRORS; | |||||
| } | } | ||||
| else if( res.failureCount() != 0 ) | |||||
| else if( m_res.failureCount() != 0 ) | |||||
| { | { | ||||
| retCode = FAILURES; | |||||
| m_retCode = FAILURES; | |||||
| } | } | ||||
| } | } | ||||
| @@ -585,8 +584,6 @@ public class JUnitTestRunner implements TestListener | |||||
| * Interface TestListener. <p> | * Interface TestListener. <p> | ||||
| * | * | ||||
| * A new Test is started. | * A new Test is started. | ||||
| * | |||||
| * @param t Description of Parameter | |||||
| */ | */ | ||||
| public void startTest( Test t ) | public void startTest( Test t ) | ||||
| { | { | ||||
| @@ -594,46 +591,53 @@ public class JUnitTestRunner implements TestListener | |||||
| protected void handleErrorOutput( String line ) | protected void handleErrorOutput( String line ) | ||||
| { | { | ||||
| if( systemError != null ) | |||||
| if( m_systemError != null ) | |||||
| { | { | ||||
| systemError.println( line ); | |||||
| m_systemError.println( line ); | |||||
| } | } | ||||
| } | } | ||||
| protected void handleOutput( String line ) | protected void handleOutput( String line ) | ||||
| { | { | ||||
| if( systemOut != null ) | |||||
| if( m_systemOut != null ) | |||||
| { | { | ||||
| systemOut.println( line ); | |||||
| m_systemOut.println( line ); | |||||
| } | } | ||||
| } | } | ||||
| private void fireEndTestSuite() | private void fireEndTestSuite() | ||||
| throws TaskException | |||||
| { | { | ||||
| for( int i = 0; i < formatters.size(); i++ ) | |||||
| final int size = m_formatters.size(); | |||||
| for( int i = 0; i < size; i++ ) | |||||
| { | { | ||||
| ( (JUnitResultFormatter)formatters.get( i ) ).endTestSuite( junitTest ); | |||||
| final JUnitResultFormatter formatter = | |||||
| (JUnitResultFormatter)m_formatters.get( i ); | |||||
| formatter.endTestSuite( m_junitTest ); | |||||
| } | } | ||||
| } | } | ||||
| private void fireStartTestSuite() | private void fireStartTestSuite() | ||||
| throws TaskException | |||||
| { | { | ||||
| for( int i = 0; i < formatters.size(); i++ ) | |||||
| final int size = m_formatters.size(); | |||||
| for( int i = 0; i < size; i++ ) | |||||
| { | { | ||||
| ( (JUnitResultFormatter)formatters.get( i ) ).startTestSuite( junitTest ); | |||||
| final JUnitResultFormatter formatter = (JUnitResultFormatter)m_formatters.get( i ); | |||||
| formatter.startTestSuite( m_junitTest ); | |||||
| } | } | ||||
| } | } | ||||
| private void sendOutAndErr( String out, String err ) | private void sendOutAndErr( String out, String err ) | ||||
| { | { | ||||
| for( int i = 0; i < formatters.size(); i++ ) | |||||
| final int size = m_formatters.size(); | |||||
| for( int i = 0; i < size; i++ ) | |||||
| { | { | ||||
| JUnitResultFormatter formatter = | |||||
| ( (JUnitResultFormatter)formatters.get( i ) ); | |||||
| final JUnitResultFormatter formatter = | |||||
| (JUnitResultFormatter)m_formatters.get( i ); | |||||
| formatter.setSystemOutput( out ); | formatter.setSystemOutput( out ); | ||||
| formatter.setSystemError( err ); | formatter.setSystemError( err ); | ||||
| } | } | ||||
| } | } | ||||
| }// JUnitTestRunner | |||||
| } | |||||
| @@ -0,0 +1,37 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE.txt file. | |||||
| */ | |||||
| package org.apache.tools.ant.taskdefs.optional.junit; | |||||
| import java.util.ArrayList; | |||||
| import org.w3c.dom.Node; | |||||
| import org.w3c.dom.NodeList; | |||||
| /** | |||||
| * custom implementation of a nodelist | |||||
| */ | |||||
| public class NodeListImpl | |||||
| extends ArrayList | |||||
| implements NodeList | |||||
| { | |||||
| public int getLength() | |||||
| { | |||||
| return size(); | |||||
| } | |||||
| public Node item( final int i ) | |||||
| { | |||||
| try | |||||
| { | |||||
| return (Node)get( i ); | |||||
| } | |||||
| catch( final ArrayIndexOutOfBoundsException aioobe ) | |||||
| { | |||||
| return null;// conforming to NodeList interface | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -224,13 +224,14 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||||
| Properties props = suite.getProperties(); | Properties props = suite.getProperties(); | ||||
| if( props != null ) | if( props != null ) | ||||
| { | { | ||||
| Iterator e = props.propertyNames(); | |||||
| final Iterator e = props.keySet().iterator(); | |||||
| while( e.hasNext() ) | while( e.hasNext() ) | ||||
| { | { | ||||
| String name = (String)e.next(); | |||||
| Element propElement = doc.createElement( PROPERTY ); | |||||
| final String name = (String)e.next(); | |||||
| final String value = props.getProperty( name ); | |||||
| final Element propElement = doc.createElement( PROPERTY ); | |||||
| propElement.setAttribute( ATTR_NAME, name ); | propElement.setAttribute( ATTR_NAME, name ); | ||||
| propElement.setAttribute( ATTR_VALUE, props.getProperty( name ) ); | |||||
| propElement.setAttribute( ATTR_VALUE, value ); | |||||
| propsElement.appendChild( propElement ); | propsElement.appendChild( propElement ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -17,7 +17,6 @@ import java.util.ArrayList; | |||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import javax.xml.parsers.DocumentBuilder; | import javax.xml.parsers.DocumentBuilder; | ||||
| import javax.xml.parsers.DocumentBuilderFactory; | import javax.xml.parsers.DocumentBuilderFactory; | ||||
| import org.apache.avalon.excalibur.io.FileUtil; | |||||
| import org.apache.avalon.framework.ExceptionUtil; | import org.apache.avalon.framework.ExceptionUtil; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
| @@ -43,9 +42,10 @@ import org.xml.sax.SAXException; | |||||
| * | * | ||||
| * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | ||||
| */ | */ | ||||
| public class XMLResultAggregator extends Task implements XMLConstants | |||||
| public class XMLResultAggregator | |||||
| extends Task | |||||
| implements XMLConstants | |||||
| { | { | ||||
| /** | /** | ||||
| * the default directory: <tt>.</tt> . It is resolved from the project | * the default directory: <tt>.</tt> . It is resolved from the project | ||||
| * directory | * directory | ||||
| @@ -147,7 +147,7 @@ public class XMLResultAggregator extends Task implements XMLConstants | |||||
| public void execute() | public void execute() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| Element rootElement = createDocument(); | |||||
| final Element rootElement = createDocument(); | |||||
| File destFile = getDestinationFile(); | File destFile = getDestinationFile(); | ||||
| // write the document | // write the document | ||||
| try | try | ||||
| @@ -176,6 +176,7 @@ public class XMLResultAggregator extends Task implements XMLConstants | |||||
| * @return the destination file where should be written the result file. | * @return the destination file where should be written the result file. | ||||
| */ | */ | ||||
| protected File getDestinationFile() | protected File getDestinationFile() | ||||
| throws TaskException | |||||
| { | { | ||||
| if( toFile == null ) | if( toFile == null ) | ||||
| { | { | ||||
| @@ -183,7 +184,7 @@ public class XMLResultAggregator extends Task implements XMLConstants | |||||
| } | } | ||||
| if( toDir == null ) | if( toDir == null ) | ||||
| { | { | ||||
| toDir = FileUtil.resolveFile( getBaseDirectory(), DEFAULT_DIR ); | |||||
| toDir = resolveFile( DEFAULT_DIR ); | |||||
| } | } | ||||
| return new File( toDir, toFile ); | return new File( toDir, toFile ); | ||||
| } | } | ||||
| @@ -194,22 +195,23 @@ public class XMLResultAggregator extends Task implements XMLConstants | |||||
| * @return all files in the fileset that end with a '.xml'. | * @return all files in the fileset that end with a '.xml'. | ||||
| */ | */ | ||||
| protected File[] getFiles() | protected File[] getFiles() | ||||
| throws TaskException | |||||
| { | { | ||||
| ArrayList v = new ArrayList(); | |||||
| final ArrayList v = new ArrayList(); | |||||
| final int size = filesets.size(); | final int size = filesets.size(); | ||||
| for( int i = 0; i < size; i++ ) | for( int i = 0; i < size; i++ ) | ||||
| { | { | ||||
| FileSet fs = (FileSet)filesets.get( i ); | |||||
| DirectoryScanner ds = fs.getDirectoryScanner(); | |||||
| ds.scan(); | |||||
| String[] f = ds.getIncludedFiles(); | |||||
| for( int j = 0; j < f.length; j++ ) | |||||
| final FileSet fileSet = (FileSet)filesets.get( i ); | |||||
| final DirectoryScanner scanner = fileSet.getDirectoryScanner(); | |||||
| scanner.scan(); | |||||
| final String[] includes = scanner.getIncludedFiles(); | |||||
| for( int j = 0; j < includes.length; j++ ) | |||||
| { | { | ||||
| String pathname = f[ j ]; | |||||
| final String pathname = includes[ j ]; | |||||
| if( pathname.endsWith( ".xml" ) ) | if( pathname.endsWith( ".xml" ) ) | ||||
| { | { | ||||
| File file = new File( ds.getBasedir(), pathname ); | |||||
| file = FileUtil.resolveFile( getBaseDirectory(), file.getPath() ); | |||||
| File file = new File( scanner.getBasedir(), pathname ); | |||||
| file = resolveFile( file.getPath() ); | |||||
| v.add( file ); | v.add( file ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -257,6 +259,7 @@ public class XMLResultAggregator extends Task implements XMLConstants | |||||
| * @return the root element of DOM tree that aggregates all testsuites. | * @return the root element of DOM tree that aggregates all testsuites. | ||||
| */ | */ | ||||
| protected Element createDocument() | protected Element createDocument() | ||||
| throws TaskException | |||||
| { | { | ||||
| // create the dom tree | // create the dom tree | ||||
| DocumentBuilder builder = getDocumentBuilder(); | DocumentBuilder builder = getDocumentBuilder(); | ||||
| @@ -265,7 +268,7 @@ public class XMLResultAggregator extends Task implements XMLConstants | |||||
| doc.appendChild( rootElement ); | doc.appendChild( rootElement ); | ||||
| // get all files and add them to the document | // get all files and add them to the document | ||||
| File[] files = getFiles(); | |||||
| final File[] files = getFiles(); | |||||
| for( int i = 0; i < files.length; i++ ) | for( int i = 0; i < files.length; i++ ) | ||||
| { | { | ||||
| try | try | ||||
| @@ -27,8 +27,8 @@ public class Xalan1Executor extends XalanExecutor | |||||
| { | { | ||||
| XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); | XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); | ||||
| // need to quote otherwise it breaks because of "extra illegal tokens" | // need to quote otherwise it breaks because of "extra illegal tokens" | ||||
| processor.setStylesheetParam( "output.dir", "'" + caller.toDir.getAbsolutePath() + "'" ); | |||||
| XSLTInputSource xml_src = new XSLTInputSource( caller.document ); | |||||
| processor.setStylesheetParam( "output.dir", "'" + caller.getToDir().getAbsolutePath() + "'" ); | |||||
| XSLTInputSource xml_src = new XSLTInputSource( caller.getDocument() ); | |||||
| String system_id = caller.getStylesheetSystemId(); | String system_id = caller.getStylesheetSystemId(); | ||||
| XSLTInputSource xsl_src = new XSLTInputSource( system_id ); | XSLTInputSource xsl_src = new XSLTInputSource( system_id ); | ||||
| OutputStream os = getOutputStream(); | OutputStream os = getOutputStream(); | ||||
| @@ -31,9 +31,9 @@ public class Xalan2Executor extends XalanExecutor | |||||
| String system_id = caller.getStylesheetSystemId(); | String system_id = caller.getStylesheetSystemId(); | ||||
| Source xsl_src = new StreamSource( system_id ); | Source xsl_src = new StreamSource( system_id ); | ||||
| Transformer tformer = tfactory.newTransformer( xsl_src ); | Transformer tformer = tfactory.newTransformer( xsl_src ); | ||||
| Source xml_src = new DOMSource( caller.document ); | |||||
| Source xml_src = new DOMSource( caller.getDocument() ); | |||||
| OutputStream os = getOutputStream(); | OutputStream os = getOutputStream(); | ||||
| tformer.setParameter( "output.dir", caller.toDir.getAbsolutePath() ); | |||||
| tformer.setParameter( "output.dir", caller.getToDir().getAbsolutePath() ); | |||||
| Result result = new StreamResult( os ); | Result result = new StreamResult( os ); | ||||
| tformer.transform( xml_src, result ); | tformer.transform( xml_src, result ); | ||||
| } | } | ||||
| @@ -95,7 +95,7 @@ abstract class XalanExecutor | |||||
| protected OutputStream getOutputStream() | protected OutputStream getOutputStream() | ||||
| throws IOException | throws IOException | ||||
| { | { | ||||
| if( caller.FRAMES.equals( caller.format ) ) | |||||
| if( caller.FRAMES.equals( caller.getFormat() ) ) | |||||
| { | { | ||||
| // dummy output for the framed report | // dummy output for the framed report | ||||
| // it's all done by extension... | // it's all done by extension... | ||||
| @@ -103,7 +103,7 @@ abstract class XalanExecutor | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| return new FileOutputStream( new File( caller.toDir, "junit-noframes.html" ) ); | |||||
| return new FileOutputStream( new File( caller.getToDir(), "junit-noframes.html" ) ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -16,6 +16,7 @@ import java.net.URL; | |||||
| import javax.xml.parsers.DocumentBuilder; | import javax.xml.parsers.DocumentBuilder; | ||||
| import javax.xml.parsers.DocumentBuilderFactory; | import javax.xml.parsers.DocumentBuilderFactory; | ||||
| import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
| import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
| @@ -32,8 +33,8 @@ import org.w3c.dom.Element; | |||||
| * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | ||||
| */ | */ | ||||
| public class AggregateTransformer | public class AggregateTransformer | ||||
| extends AbstractLogEnabled | |||||
| { | { | ||||
| public final static String FRAMES = "frames"; | public final static String FRAMES = "frames"; | ||||
| public final static String NOFRAMES = "noframes"; | public final static String NOFRAMES = "noframes"; | ||||
| @@ -41,53 +42,40 @@ public class AggregateTransformer | |||||
| /** | /** | ||||
| * XML Parser factory | * XML Parser factory | ||||
| */ | */ | ||||
| protected final static DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); | |||||
| private final static DocumentBuilderFactory c_dbfactory = DocumentBuilderFactory.newInstance(); | |||||
| /** | /** | ||||
| * the xml document to process | * the xml document to process | ||||
| */ | */ | ||||
| protected Document document; | |||||
| private Document m_document; | |||||
| /** | /** | ||||
| * the format to use for the report. Must be <tt>FRAMES</tt> or <tt>NOFRAMES | * the format to use for the report. Must be <tt>FRAMES</tt> or <tt>NOFRAMES | ||||
| * </tt> | * </tt> | ||||
| */ | */ | ||||
| protected String format; | |||||
| private String m_format; | |||||
| /** | /** | ||||
| * the style directory. XSLs should be read from here if necessary | * the style directory. XSLs should be read from here if necessary | ||||
| */ | */ | ||||
| protected File styleDir; | |||||
| private File m_styleDir; | |||||
| /** | |||||
| * Task | |||||
| */ | |||||
| protected Task task; | |||||
| private Task m_task; | |||||
| /** | /** | ||||
| * the destination directory, this is the root from where html should be | * the destination directory, this is the root from where html should be | ||||
| * generated | * generated | ||||
| */ | */ | ||||
| protected File toDir; | |||||
| private File m_toDir; | |||||
| public AggregateTransformer( Task task ) | public AggregateTransformer( Task task ) | ||||
| { | { | ||||
| this.task = task; | |||||
| } | |||||
| /** | |||||
| * set the extension of the output files | |||||
| * | |||||
| * @param ext The new Extension value | |||||
| */ | |||||
| public void setExtension( String ext ) | |||||
| { | |||||
| task.getLogger().warn( "extension is not used anymore" ); | |||||
| m_task = task; | |||||
| } | } | ||||
| public void setFormat( Format format ) | public void setFormat( Format format ) | ||||
| { | { | ||||
| this.format = format.getValue(); | |||||
| m_format = format.getValue(); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -99,7 +87,7 @@ public class AggregateTransformer | |||||
| */ | */ | ||||
| public void setStyledir( File styledir ) | public void setStyledir( File styledir ) | ||||
| { | { | ||||
| this.styleDir = styledir; | |||||
| m_styleDir = styledir; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -109,12 +97,12 @@ public class AggregateTransformer | |||||
| */ | */ | ||||
| public void setTodir( File todir ) | public void setTodir( File todir ) | ||||
| { | { | ||||
| this.toDir = todir; | |||||
| m_toDir = todir; | |||||
| } | } | ||||
| public void setXmlDocument( Document doc ) | public void setXmlDocument( Document doc ) | ||||
| { | { | ||||
| this.document = doc; | |||||
| m_document = doc; | |||||
| } | } | ||||
| public void transform() | public void transform() | ||||
| @@ -124,7 +112,7 @@ public class AggregateTransformer | |||||
| final long t0 = System.currentTimeMillis(); | final long t0 = System.currentTimeMillis(); | ||||
| try | try | ||||
| { | { | ||||
| Element root = document.getDocumentElement(); | |||||
| Element root = m_document.getDocumentElement(); | |||||
| XalanExecutor executor = XalanExecutor.newInstance( this ); | XalanExecutor executor = XalanExecutor.newInstance( this ); | ||||
| executor.execute(); | executor.execute(); | ||||
| } | } | ||||
| @@ -148,7 +136,7 @@ public class AggregateTransformer | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| DocumentBuilder builder = dbfactory.newDocumentBuilder(); | |||||
| DocumentBuilder builder = c_dbfactory.newDocumentBuilder(); | |||||
| InputStream in = new FileInputStream( xmlfile ); | InputStream in = new FileInputStream( xmlfile ); | ||||
| try | try | ||||
| { | { | ||||
| @@ -178,12 +166,12 @@ public class AggregateTransformer | |||||
| throws IOException | throws IOException | ||||
| { | { | ||||
| String xslname = "junit-frames.xsl"; | String xslname = "junit-frames.xsl"; | ||||
| if( NOFRAMES.equals( format ) ) | |||||
| if( NOFRAMES.equals( m_format ) ) | |||||
| { | { | ||||
| xslname = "junit-noframes.xsl"; | xslname = "junit-noframes.xsl"; | ||||
| } | } | ||||
| URL url = null; | URL url = null; | ||||
| if( styleDir == null ) | |||||
| if( m_styleDir == null ) | |||||
| { | { | ||||
| url = getClass().getResource( "xsl/" + xslname ); | url = getClass().getResource( "xsl/" + xslname ); | ||||
| if( url == null ) | if( url == null ) | ||||
| @@ -193,7 +181,7 @@ public class AggregateTransformer | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| File file = new File( styleDir, xslname ); | |||||
| File file = new File( m_styleDir, xslname ); | |||||
| if( !file.exists() ) | if( !file.exists() ) | ||||
| { | { | ||||
| throw new FileNotFoundException( "Could not find file '" + file + "'" ); | throw new FileNotFoundException( "Could not find file '" + file + "'" ); | ||||
| @@ -212,16 +200,31 @@ public class AggregateTransformer | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| // set the destination directory relative from the project if needed. | // set the destination directory relative from the project if needed. | ||||
| if( toDir == null ) | |||||
| if( m_toDir == null ) | |||||
| { | { | ||||
| toDir = FileUtil.resolveFile( task.getBaseDirectory(), "." ); | |||||
| m_toDir = FileUtil.resolveFile( m_task.getBaseDirectory(), "." ); | |||||
| } | } | ||||
| else if( !toDir.isAbsolute() ) | |||||
| else if( !m_toDir.isAbsolute() ) | |||||
| { | { | ||||
| toDir = FileUtil.resolveFile( task.getBaseDirectory(), toDir.getPath() ); | |||||
| m_toDir = FileUtil.resolveFile( m_task.getBaseDirectory(), m_toDir.getPath() ); | |||||
| } | } | ||||
| } | } | ||||
| protected Document getDocument() | |||||
| { | |||||
| return m_document; | |||||
| } | |||||
| protected String getFormat() | |||||
| { | |||||
| return m_format; | |||||
| } | |||||
| protected File getToDir() | |||||
| { | |||||
| return m_toDir; | |||||
| } | |||||
| public static class Format extends EnumeratedAttribute | public static class Format extends EnumeratedAttribute | ||||
| { | { | ||||
| public String[] getValues() | public String[] getValues() | ||||
| @@ -18,9 +18,9 @@ import java.util.ArrayList; | |||||
| */ | */ | ||||
| public abstract class BaseTest | public abstract class BaseTest | ||||
| { | { | ||||
| protected boolean haltOnError = false; | |||||
| protected boolean haltOnFail = false; | |||||
| protected boolean filtertrace = true; | |||||
| protected boolean m_haltOnError = false; | |||||
| protected boolean m_haltOnFail = false; | |||||
| protected boolean m_filtertrace = true; | |||||
| protected boolean fork = false; | protected boolean fork = false; | ||||
| protected String ifProperty = null; | protected String ifProperty = null; | ||||
| protected String unlessProperty = null; | protected String unlessProperty = null; | ||||
| @@ -45,7 +45,7 @@ public abstract class BaseTest | |||||
| public void setFiltertrace( boolean value ) | public void setFiltertrace( boolean value ) | ||||
| { | { | ||||
| filtertrace = value; | |||||
| m_filtertrace = value; | |||||
| } | } | ||||
| public void setFork( boolean value ) | public void setFork( boolean value ) | ||||
| @@ -55,12 +55,12 @@ public abstract class BaseTest | |||||
| public void setHaltonerror( boolean value ) | public void setHaltonerror( boolean value ) | ||||
| { | { | ||||
| haltOnError = value; | |||||
| m_haltOnError = value; | |||||
| } | } | ||||
| public void setHaltonfailure( boolean value ) | public void setHaltonfailure( boolean value ) | ||||
| { | { | ||||
| haltOnFail = value; | |||||
| m_haltOnFail = value; | |||||
| } | } | ||||
| public void setIf( String propertyName ) | public void setIf( String propertyName ) | ||||
| @@ -95,7 +95,7 @@ public abstract class BaseTest | |||||
| public boolean getFiltertrace() | public boolean getFiltertrace() | ||||
| { | { | ||||
| return filtertrace; | |||||
| return m_filtertrace; | |||||
| } | } | ||||
| public boolean getFork() | public boolean getFork() | ||||
| @@ -105,12 +105,12 @@ public abstract class BaseTest | |||||
| public boolean getHaltonerror() | public boolean getHaltonerror() | ||||
| { | { | ||||
| return haltOnError; | |||||
| return m_haltOnError; | |||||
| } | } | ||||
| public boolean getHaltonfailure() | public boolean getHaltonfailure() | ||||
| { | { | ||||
| return haltOnFail; | |||||
| return m_haltOnFail; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -9,7 +9,9 @@ package org.apache.tools.ant.taskdefs.optional.junit; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Arrays; | |||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
| @@ -32,7 +34,6 @@ import org.apache.tools.ant.types.FileSet; | |||||
| */ | */ | ||||
| public final class BatchTest extends BaseTest | public final class BatchTest extends BaseTest | ||||
| { | { | ||||
| /** | /** | ||||
| * the list of filesets containing the testcase filename rules | * the list of filesets containing the testcase filename rules | ||||
| */ | */ | ||||
| @@ -74,9 +75,10 @@ public final class BatchTest extends BaseTest | |||||
| * JUnitTest</tt> instance. | * JUnitTest</tt> instance. | ||||
| */ | */ | ||||
| public final Iterator iterator() | public final Iterator iterator() | ||||
| throws TaskException | |||||
| { | { | ||||
| JUnitTest[] tests = createAllJUnitTest(); | |||||
| return Iterators.fromArray( tests ); | |||||
| final JUnitTest[] tests = createAllJUnitTest(); | |||||
| return Arrays.asList( tests ).iterator(); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -99,8 +101,9 @@ public final class BatchTest extends BaseTest | |||||
| * batch test. | * batch test. | ||||
| */ | */ | ||||
| final void addTestsTo( ArrayList v ) | final void addTestsTo( ArrayList v ) | ||||
| throws TaskException | |||||
| { | { | ||||
| JUnitTest[] tests = createAllJUnitTest(); | |||||
| final 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++ ) | ||||
| { | { | ||||
| @@ -121,6 +124,7 @@ public final class BatchTest extends BaseTest | |||||
| * it will return <tt>org/apache/Whatever</tt> . | * it will return <tt>org/apache/Whatever</tt> . | ||||
| */ | */ | ||||
| private String[] getFilenames() | private String[] getFilenames() | ||||
| throws TaskException | |||||
| { | { | ||||
| ArrayList v = new ArrayList(); | ArrayList v = new ArrayList(); | ||||
| final int size = this.filesets.size(); | final int size = this.filesets.size(); | ||||
| @@ -144,9 +148,7 @@ public final class BatchTest extends BaseTest | |||||
| } | } | ||||
| } | } | ||||
| String[] files = new String[ v.size() ]; | |||||
| v.copyInto( files ); | |||||
| return files; | |||||
| return (String[])v.toArray( new String[ v.size() ] ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -156,6 +158,7 @@ public final class BatchTest extends BaseTest | |||||
| * @return the array of all <tt>JUnitTest</tt> s that belongs to this batch. | * @return the array of all <tt>JUnitTest</tt> s that belongs to this batch. | ||||
| */ | */ | ||||
| private JUnitTest[] createAllJUnitTest() | private JUnitTest[] createAllJUnitTest() | ||||
| throws TaskException | |||||
| { | { | ||||
| String[] filenames = getFilenames(); | String[] filenames = getFilenames(); | ||||
| JUnitTest[] tests = new JUnitTest[ filenames.length ]; | JUnitTest[] tests = new JUnitTest[ filenames.length ]; | ||||
| @@ -179,9 +182,9 @@ public final class BatchTest extends BaseTest | |||||
| { | { | ||||
| JUnitTest test = new JUnitTest(); | JUnitTest test = new JUnitTest(); | ||||
| test.setName( classname ); | test.setName( classname ); | ||||
| test.setHaltonerror( this.haltOnError ); | |||||
| test.setHaltonfailure( this.haltOnFail ); | |||||
| test.setFiltertrace( this.filtertrace ); | |||||
| test.setHaltonerror( this.m_haltOnError ); | |||||
| test.setHaltonfailure( this.m_haltOnFail ); | |||||
| test.setFiltertrace( this.m_filtertrace ); | |||||
| test.setFork( this.fork ); | test.setFork( this.fork ); | ||||
| test.setIf( this.ifProperty ); | test.setIf( this.ifProperty ); | ||||
| test.setUnless( this.unlessProperty ); | test.setUnless( this.unlessProperty ); | ||||
| @@ -0,0 +1,100 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE.txt file. | |||||
| */ | |||||
| package org.apache.tools.ant.taskdefs.optional.junit; | |||||
| import java.util.Iterator; | |||||
| import java.util.NoSuchElementException; | |||||
| /** | |||||
| * Convenient enumeration over an array of enumeration. For example: <pre> | |||||
| * Iterator e1 = v1.iterator(); | |||||
| * while (e1.hasNext()){ | |||||
| * // do something | |||||
| * } | |||||
| * Iterator e2 = v2.iterator(); | |||||
| * while (e2.hasNext()){ | |||||
| * // do the same thing | |||||
| * } | |||||
| * </pre> can be written as: <pre> | |||||
| * Iterator[] enums = { v1.iterator(), v2.iterator() }; | |||||
| * Iterator e = Iterators.fromCompound(enums); | |||||
| * while (e.hasNext()){ | |||||
| * // do something | |||||
| * } | |||||
| * </pre> Note that the enumeration will skip null elements in the array. The | |||||
| * following is thus possible: <pre> | |||||
| * Iterator[] enums = { v1.iterator(), null, v2.iterator() }; // a null enumeration in the array | |||||
| * Iterator e = Iterators.fromCompound(enums); | |||||
| * while (e.hasNext()){ | |||||
| * // do something | |||||
| * } | |||||
| * </pre> | |||||
| * | |||||
| * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | |||||
| */ | |||||
| class CompoundIterator | |||||
| implements Iterator | |||||
| { | |||||
| /** | |||||
| * index in the enums array | |||||
| */ | |||||
| private int index = 0; | |||||
| /** | |||||
| * enumeration array | |||||
| */ | |||||
| private Iterator[] enumArray; | |||||
| public CompoundIterator( Iterator[] enumarray ) | |||||
| { | |||||
| this.enumArray = enumarray; | |||||
| } | |||||
| /** | |||||
| * Tests if this enumeration contains more elements. | |||||
| * | |||||
| * @return <code>true</code> if and only if this enumeration object contains | |||||
| * at least one more element to provide; <code>false</code> otherwise. | |||||
| */ | |||||
| public boolean hasNext() | |||||
| { | |||||
| while( index < enumArray.length ) | |||||
| { | |||||
| if( enumArray[ index ] != null && enumArray[ index ].hasNext() ) | |||||
| { | |||||
| return true; | |||||
| } | |||||
| index++; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /** | |||||
| * Returns the next element of this enumeration if this enumeration object | |||||
| * has at least one more element to provide. | |||||
| * | |||||
| * @return the next element of this enumeration. | |||||
| * @throws NoSuchElementException if no more elements exist. | |||||
| */ | |||||
| public Object next() | |||||
| throws NoSuchElementException | |||||
| { | |||||
| if( hasNext() ) | |||||
| { | |||||
| return enumArray[ index ].next(); | |||||
| } | |||||
| throw new NoSuchElementException(); | |||||
| } | |||||
| public void remove() | |||||
| throws UnsupportedOperationException | |||||
| { | |||||
| throw new UnsupportedOperationException(); | |||||
| } | |||||
| } | |||||
| @@ -7,7 +7,6 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs.optional.junit; | package org.apache.tools.ant.taskdefs.optional.junit; | ||||
| import java.util.ArrayList; | |||||
| import org.w3c.dom.Attr; | import org.w3c.dom.Attr; | ||||
| import org.w3c.dom.CDATASection; | import org.w3c.dom.CDATASection; | ||||
| import org.w3c.dom.Comment; | import org.w3c.dom.Comment; | ||||
| @@ -224,28 +223,4 @@ public final class DOMUtil | |||||
| boolean accept( Node node ); | boolean accept( Node node ); | ||||
| } | } | ||||
| /** | |||||
| * custom implementation of a nodelist | |||||
| * | |||||
| * @author RT | |||||
| */ | |||||
| public static class NodeListImpl extends ArrayList implements NodeList | |||||
| { | |||||
| public int getLength() | |||||
| { | |||||
| return size(); | |||||
| } | |||||
| public Node item( int i ) | |||||
| { | |||||
| try | |||||
| { | |||||
| return (Node)get( i ); | |||||
| } | |||||
| catch( ArrayIndexOutOfBoundsException e ) | |||||
| { | |||||
| return null;// conforming to NodeList interface | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -1,193 +0,0 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE.txt file. | |||||
| */ | |||||
| package org.apache.tools.ant.taskdefs.optional.junit; | |||||
| import java.util.Iterator; | |||||
| import java.util.NoSuchElementException; | |||||
| /** | |||||
| * A couple of methods related to enumerations that might be useful. This class | |||||
| * should probably disappear once the required JDK is set to 1.2 instead of 1.1. | |||||
| * | |||||
| * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | |||||
| */ | |||||
| public final class Iterators | |||||
| { | |||||
| private Iterators() | |||||
| { | |||||
| } | |||||
| /** | |||||
| * creates an enumeration from an array of objects. | |||||
| * | |||||
| * @param array the array of object to enumerate. | |||||
| * @return the enumeration over the array of objects. | |||||
| */ | |||||
| public static Iterator fromArray( Object[] array ) | |||||
| { | |||||
| return new ArrayIterator( array ); | |||||
| } | |||||
| /** | |||||
| * creates an enumeration from an array of enumeration. The created | |||||
| * enumeration will sequentially enumerate over all elements of each | |||||
| * enumeration and skip <tt>null</tt> enumeration elements in the array. | |||||
| * | |||||
| * @param enums the array of enumerations. | |||||
| * @return the enumeration over the array of enumerations. | |||||
| */ | |||||
| public static Iterator fromCompound( Iterator[] enums ) | |||||
| { | |||||
| return new CompoundIterator( enums ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Convenient enumeration over an array of objects. | |||||
| * | |||||
| * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | |||||
| */ | |||||
| class ArrayIterator implements Iterator | |||||
| { | |||||
| /** | |||||
| * object array | |||||
| */ | |||||
| private Object[] array; | |||||
| /** | |||||
| * current index | |||||
| */ | |||||
| private int pos; | |||||
| /** | |||||
| * Initialize a new enumeration that wraps an array. | |||||
| * | |||||
| * @param array the array of object to enumerate. | |||||
| */ | |||||
| public ArrayIterator( Object[] array ) | |||||
| { | |||||
| this.array = array; | |||||
| this.pos = 0; | |||||
| } | |||||
| /** | |||||
| * Tests if this enumeration contains more elements. | |||||
| * | |||||
| * @return <code>true</code> if and only if this enumeration object contains | |||||
| * at least one more element to provide; <code>false</code> otherwise. | |||||
| */ | |||||
| public boolean hasNext() | |||||
| { | |||||
| return ( pos < array.length ); | |||||
| } | |||||
| /** | |||||
| * Returns the next element of this enumeration if this enumeration object | |||||
| * has at least one more element to provide. | |||||
| * | |||||
| * @return the next element of this enumeration. | |||||
| * @throws NoSuchElementException if no more elements exist. | |||||
| */ | |||||
| public Object next() | |||||
| throws NoSuchElementException | |||||
| { | |||||
| if( hasNext() ) | |||||
| { | |||||
| Object o = array[ pos ]; | |||||
| pos++; | |||||
| return o; | |||||
| } | |||||
| throw new NoSuchElementException(); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Convenient enumeration over an array of enumeration. For example: <pre> | |||||
| * Iterator e1 = v1.iterator(); | |||||
| * while (e1.hasNext()){ | |||||
| * // do something | |||||
| * } | |||||
| * Iterator e2 = v2.iterator(); | |||||
| * while (e2.hasNext()){ | |||||
| * // do the same thing | |||||
| * } | |||||
| * </pre> can be written as: <pre> | |||||
| * Iterator[] enums = { v1.iterator(), v2.iterator() }; | |||||
| * Iterator e = Iterators.fromCompound(enums); | |||||
| * while (e.hasNext()){ | |||||
| * // do something | |||||
| * } | |||||
| * </pre> Note that the enumeration will skip null elements in the array. The | |||||
| * following is thus possible: <pre> | |||||
| * Iterator[] enums = { v1.iterator(), null, v2.iterator() }; // a null enumeration in the array | |||||
| * Iterator e = Iterators.fromCompound(enums); | |||||
| * while (e.hasNext()){ | |||||
| * // do something | |||||
| * } | |||||
| * </pre> | |||||
| * | |||||
| * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | |||||
| */ | |||||
| class CompoundIterator implements Iterator | |||||
| { | |||||
| /** | |||||
| * index in the enums array | |||||
| */ | |||||
| private int index = 0; | |||||
| /** | |||||
| * enumeration array | |||||
| */ | |||||
| private Iterator[] enumArray; | |||||
| public CompoundIterator( Iterator[] enumarray ) | |||||
| { | |||||
| this.enumArray = enumarray; | |||||
| } | |||||
| /** | |||||
| * Tests if this enumeration contains more elements. | |||||
| * | |||||
| * @return <code>true</code> if and only if this enumeration object contains | |||||
| * at least one more element to provide; <code>false</code> otherwise. | |||||
| */ | |||||
| public boolean hasNext() | |||||
| { | |||||
| while( index < enumArray.length ) | |||||
| { | |||||
| if( enumArray[ index ] != null && enumArray[ index ].hasNext() ) | |||||
| { | |||||
| return true; | |||||
| } | |||||
| index++; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /** | |||||
| * Returns the next element of this enumeration if this enumeration object | |||||
| * has at least one more element to provide. | |||||
| * | |||||
| * @return the next element of this enumeration. | |||||
| * @throws NoSuchElementException if no more elements exist. | |||||
| */ | |||||
| public Object next() | |||||
| throws NoSuchElementException | |||||
| { | |||||
| if( hasNext() ) | |||||
| { | |||||
| return enumArray[ index ].next(); | |||||
| } | |||||
| throw new NoSuchElementException(); | |||||
| } | |||||
| } | |||||
| @@ -21,7 +21,7 @@ import java.util.Properties; | |||||
| import java.util.Random; | import java.util.Random; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.taskdefs.exec.Execute; | |||||
| import org.apache.tools.ant.taskdefs.exec.Execute2; | |||||
| import org.apache.tools.ant.taskdefs.exec.LogOutputStream; | import org.apache.tools.ant.taskdefs.exec.LogOutputStream; | ||||
| import org.apache.tools.ant.types.Argument; | import org.apache.tools.ant.types.Argument; | ||||
| import org.apache.tools.ant.types.CommandlineJava; | import org.apache.tools.ant.types.CommandlineJava; | ||||
| @@ -348,7 +348,7 @@ public class JUnitTask extends Task | |||||
| */ | */ | ||||
| public Path createClasspath() | public Path createClasspath() | ||||
| { | { | ||||
| return commandline.createClasspath( getProject() ).createPath(); | |||||
| return commandline.createClasspath().createPath(); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -408,6 +408,7 @@ public class JUnitTask extends Task | |||||
| * @return The IndividualTests value | * @return The IndividualTests value | ||||
| */ | */ | ||||
| protected Iterator getIndividualTests() | protected Iterator getIndividualTests() | ||||
| throws TaskException | |||||
| { | { | ||||
| Iterator[] enums = new Iterator[ batchTests.size() + 1 ]; | Iterator[] enums = new Iterator[ batchTests.size() + 1 ]; | ||||
| for( int i = 0; i < batchTests.size(); i++ ) | for( int i = 0; i < batchTests.size(); i++ ) | ||||
| @@ -416,7 +417,7 @@ public class JUnitTask extends Task | |||||
| enums[ i ] = batchtest.iterator(); | enums[ i ] = batchtest.iterator(); | ||||
| } | } | ||||
| enums[ enums.length - 1 ] = tests.iterator(); | enums[ enums.length - 1 ] = tests.iterator(); | ||||
| return Iterators.fromCompound( enums ); | |||||
| return new CompoundIterator( enums ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -482,7 +483,7 @@ public class JUnitTask extends Task | |||||
| protected Iterator allTests() | protected Iterator allTests() | ||||
| { | { | ||||
| Iterator[] enums = {tests.iterator(), batchTests.iterator()}; | Iterator[] enums = {tests.iterator(), batchTests.iterator()}; | ||||
| return Iterator.fromCompound( enums ); | |||||
| return new CompoundIterator( enums ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -585,13 +586,11 @@ public class JUnitTask extends Task | |||||
| * @param watchdog the watchdog in charge of cancelling the test if it | * @param watchdog the watchdog in charge of cancelling the test if it | ||||
| * exceeds a certain amount of time. Can be <tt>null</tt> , in this | * exceeds a certain amount of time. Can be <tt>null</tt> , in this | ||||
| * case the test could probably hang forever. | * case the test could probably hang forever. | ||||
| * @return Description of the Returned Value | |||||
| * @exception TaskException Description of Exception | |||||
| */ | */ | ||||
| private int executeAsForked( JUnitTest test ) | private int executeAsForked( JUnitTest test ) | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| CommandlineJava cmd = (CommandlineJava)commandline.clone(); | |||||
| CommandlineJava cmd = commandline;//(CommandlineJava)commandline.clone(); | |||||
| cmd.setClassname( "org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" ); | cmd.setClassname( "org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" ); | ||||
| cmd.createArgument().setValue( test.getName() ); | cmd.createArgument().setValue( test.getName() ); | ||||
| @@ -642,10 +641,8 @@ public class JUnitTask extends Task | |||||
| throw new TaskException( "Error creating temporary properties file.", ioe ); | throw new TaskException( "Error creating temporary properties file.", ioe ); | ||||
| } | } | ||||
| final Execute exe = new Execute(); | |||||
| exe.setOutput( new LogOutputStream( getLogger(), false ) ); | |||||
| exe.setError( new LogOutputStream( getLogger(), true ) ); | |||||
| final Execute2 exe = new Execute2(); | |||||
| setupLogger( exe ); | |||||
| exe.setCommandline( cmd.getCommandline() ); | exe.setCommandline( cmd.getCommandline() ); | ||||
| if( dir != null ) | if( dir != null ) | ||||
| { | { | ||||
| @@ -673,10 +670,6 @@ public class JUnitTask extends Task | |||||
| /** | /** | ||||
| * Execute inside VM. | * Execute inside VM. | ||||
| * | |||||
| * @param test Description of Parameter | |||||
| * @return Description of the Returned Value | |||||
| * @exception TaskException Description of Exception | |||||
| */ | */ | ||||
| private int executeInVM( JUnitTest test ) | private int executeInVM( JUnitTest test ) | ||||
| throws TaskException | throws TaskException | ||||
| @@ -748,11 +741,9 @@ public class JUnitTask extends Task | |||||
| private FormatterElement[] mergeFormatters( JUnitTest test ) | private FormatterElement[] mergeFormatters( JUnitTest test ) | ||||
| { | { | ||||
| ArrayList feArrayList = (ArrayList)formatters.clone(); | |||||
| final ArrayList feArrayList = (ArrayList)formatters.clone(); | |||||
| test.addFormattersTo( feArrayList ); | test.addFormattersTo( feArrayList ); | ||||
| FormatterElement[] feArray = new FormatterElement[ feArrayList.size() ]; | |||||
| feArrayList.copyInto( feArray ); | |||||
| return feArray; | |||||
| return (FormatterElement[])feArrayList.toArray( new FormatterElement[ feArrayList.size() ] ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -29,25 +29,27 @@ import org.apache.tools.ant.Project; | |||||
| */ | */ | ||||
| public class JUnitTest extends BaseTest | public class JUnitTest extends BaseTest | ||||
| { | { | ||||
| /** | /** | ||||
| * the name of the test case | * the name of the test case | ||||
| */ | */ | ||||
| private String name = null; | |||||
| private String m_name; | |||||
| /** | /** | ||||
| * the name of the result file | * the name of the result file | ||||
| */ | */ | ||||
| private String outfile = null; | |||||
| private String m_outfile; | |||||
| // Snapshot of the system properties | // Snapshot of the system properties | ||||
| private Properties props = null; | |||||
| private long runTime; | |||||
| private Properties m_props; | |||||
| private long m_runTime; | |||||
| // @todo this is duplicating TestResult information. Only the time is not | // @todo this is duplicating TestResult information. Only the time is not | ||||
| // part of the result. So we'd better derive a new class from TestResult | // part of the result. So we'd better derive a new class from TestResult | ||||
| // and deal with it. (SB) | // and deal with it. (SB) | ||||
| private long runs, failures, errors; | |||||
| private long m_runs; | |||||
| private long m_failures; | |||||
| private long m_errors; | |||||
| public JUnitTest() | public JUnitTest() | ||||
| { | { | ||||
| @@ -55,64 +57,63 @@ public class JUnitTest extends BaseTest | |||||
| public JUnitTest( String name ) | public JUnitTest( String name ) | ||||
| { | { | ||||
| this.name = name; | |||||
| m_name = name; | |||||
| } | } | ||||
| public JUnitTest( String name, boolean haltOnError, boolean haltOnFailure, boolean filtertrace ) | |||||
| public JUnitTest( final String name, | |||||
| final boolean haltOnError, | |||||
| final boolean haltOnFailure, | |||||
| final boolean filtertrace ) | |||||
| { | { | ||||
| this.name = name; | |||||
| this.haltOnError = haltOnError; | |||||
| this.haltOnFail = haltOnFailure; | |||||
| this.filtertrace = filtertrace; | |||||
| m_name = name; | |||||
| m_haltOnError = haltOnError; | |||||
| m_haltOnFail = haltOnFailure; | |||||
| m_filtertrace = filtertrace; | |||||
| } | } | ||||
| public void setCounts( long runs, long failures, long errors ) | public void setCounts( long runs, long failures, long errors ) | ||||
| { | { | ||||
| this.runs = runs; | |||||
| this.failures = failures; | |||||
| this.errors = errors; | |||||
| m_runs = runs; | |||||
| m_failures = failures; | |||||
| m_errors = errors; | |||||
| } | } | ||||
| /** | /** | ||||
| * Set the name of the test class. | * Set the name of the test class. | ||||
| * | |||||
| * @param value The new Name value | |||||
| */ | */ | ||||
| public void setName( String value ) | |||||
| public void setName( final String value ) | |||||
| { | { | ||||
| name = value; | |||||
| m_name = value; | |||||
| } | } | ||||
| /** | /** | ||||
| * Set the name of the output file. | * Set the name of the output file. | ||||
| * | |||||
| * @param value The new Outfile value | |||||
| */ | */ | ||||
| public void setOutfile( String value ) | |||||
| public void setOutfile( final String value ) | |||||
| { | { | ||||
| outfile = value; | |||||
| m_outfile = value; | |||||
| } | } | ||||
| public void setProperties( Hashtable p ) | |||||
| public void setProperties( final Hashtable properties ) | |||||
| { | { | ||||
| props = new Properties(); | |||||
| for( Iterator enum = p.keys(); enum.hasNext(); ) | |||||
| m_props = new Properties(); | |||||
| final Iterator enum = properties.keySet().iterator(); | |||||
| while( enum.hasNext() ) | |||||
| { | { | ||||
| Object key = enum.next(); | |||||
| props.put( key, p.get( key ) ); | |||||
| final Object key = enum.next(); | |||||
| final Object value = properties.get( key ); | |||||
| m_props.put( key, value ); | |||||
| } | } | ||||
| } | } | ||||
| public void setRunTime( long runTime ) | |||||
| public void setRunTime( final long runTime ) | |||||
| { | { | ||||
| this.runTime = runTime; | |||||
| m_runTime = runTime; | |||||
| } | } | ||||
| public FormatterElement[] getFormatters() | public FormatterElement[] getFormatters() | ||||
| { | { | ||||
| FormatterElement[] fes = new FormatterElement[ formatters.size() ]; | |||||
| formatters.copyInto( fes ); | |||||
| return fes; | |||||
| return (FormatterElement[])formatters.toArray( new FormatterElement[ formatters.size() ] ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -122,7 +123,7 @@ public class JUnitTest extends BaseTest | |||||
| */ | */ | ||||
| public String getName() | public String getName() | ||||
| { | { | ||||
| return name; | |||||
| return m_name; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -132,32 +133,32 @@ public class JUnitTest extends BaseTest | |||||
| */ | */ | ||||
| public String getOutfile() | public String getOutfile() | ||||
| { | { | ||||
| return outfile; | |||||
| return m_outfile; | |||||
| } | } | ||||
| public Properties getProperties() | public Properties getProperties() | ||||
| { | { | ||||
| return props; | |||||
| return m_props; | |||||
| } | } | ||||
| public long getRunTime() | public long getRunTime() | ||||
| { | { | ||||
| return runTime; | |||||
| return m_runTime; | |||||
| } | } | ||||
| public long errorCount() | public long errorCount() | ||||
| { | { | ||||
| return errors; | |||||
| return m_errors; | |||||
| } | } | ||||
| public long failureCount() | public long failureCount() | ||||
| { | { | ||||
| return failures; | |||||
| return m_failures; | |||||
| } | } | ||||
| public long runCount() | public long runCount() | ||||
| { | { | ||||
| return runs; | |||||
| return m_runs; | |||||
| } | } | ||||
| public boolean shouldRun( Project p ) | public boolean shouldRun( Project p ) | ||||
| @@ -177,15 +178,9 @@ public class JUnitTest extends BaseTest | |||||
| /** | /** | ||||
| * Convenient method to add formatters to a vector | * Convenient method to add formatters to a vector | ||||
| * | |||||
| * @param v The feature to be added to the FormattersTo attribute | |||||
| */ | */ | ||||
| void addFormattersTo( ArrayList v ) | void addFormattersTo( ArrayList v ) | ||||
| { | { | ||||
| final int count = formatters.size(); | |||||
| for( int i = 0; i < count; i++ ) | |||||
| { | |||||
| v.add( formatters.get( i ) ); | |||||
| } | |||||
| v.addAll( formatters ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -19,7 +19,6 @@ import java.io.StringWriter; | |||||
| import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Hashtable; | import java.util.Hashtable; | ||||
| import java.util.Iterator; | |||||
| import java.util.Properties; | import java.util.Properties; | ||||
| import junit.framework.AssertionFailedError; | import junit.framework.AssertionFailedError; | ||||
| import junit.framework.Test; | import junit.framework.Test; | ||||
| @@ -46,10 +45,9 @@ import org.apache.myrmidon.api.TaskException; | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| * @author <a href="mailto:erik@hatcher.net">Erik Hatcher</a> | * @author <a href="mailto:erik@hatcher.net">Erik Hatcher</a> | ||||
| */ | */ | ||||
| public class JUnitTestRunner implements TestListener | |||||
| public class JUnitTestRunner | |||||
| implements TestListener | |||||
| { | { | ||||
| /** | /** | ||||
| * No problems with this test. | * No problems with this test. | ||||
| */ | */ | ||||
| @@ -70,7 +68,8 @@ public class JUnitTestRunner implements TestListener | |||||
| */ | */ | ||||
| private static boolean filtertrace = true; | private static boolean filtertrace = true; | ||||
| private final static String[] DEFAULT_TRACE_FILTERS = new String[]{ | |||||
| private final static String[] DEFAULT_TRACE_FILTERS = new String[] | |||||
| { | |||||
| "junit.framework.TestCase", | "junit.framework.TestCase", | ||||
| "junit.framework.TestResult", | "junit.framework.TestResult", | ||||
| "junit.framework.TestSuite", | "junit.framework.TestSuite", | ||||
| @@ -82,57 +81,57 @@ public class JUnitTestRunner implements TestListener | |||||
| "org.apache.tools.ant." | "org.apache.tools.ant." | ||||
| }; | }; | ||||
| private static ArrayList fromCmdLine = new ArrayList(); | |||||
| private static ArrayList m_fromCmdLine = new ArrayList(); | |||||
| /** | /** | ||||
| * Holds the registered formatters. | * Holds the registered formatters. | ||||
| */ | */ | ||||
| private ArrayList formatters = new ArrayList(); | |||||
| private ArrayList m_formatters = new ArrayList(); | |||||
| /** | /** | ||||
| * Do we stop on errors. | * Do we stop on errors. | ||||
| */ | */ | ||||
| private boolean haltOnError = false; | |||||
| private boolean m_haltOnError; | |||||
| /** | /** | ||||
| * Do we stop on test failures. | * Do we stop on test failures. | ||||
| */ | */ | ||||
| private boolean haltOnFailure = false; | |||||
| private boolean m_haltOnFailure; | |||||
| /** | /** | ||||
| * The corresponding testsuite. | * The corresponding testsuite. | ||||
| */ | */ | ||||
| private Test suite = null; | |||||
| private Test m_suite; | |||||
| /** | /** | ||||
| * Returncode | * Returncode | ||||
| */ | */ | ||||
| private int retCode = SUCCESS; | |||||
| private int m_retCode = SUCCESS; | |||||
| /** | /** | ||||
| * Exception caught in constructor. | * Exception caught in constructor. | ||||
| */ | */ | ||||
| private Exception exception; | |||||
| private Exception m_exception; | |||||
| /** | /** | ||||
| * The TestSuite we are currently running. | * The TestSuite we are currently running. | ||||
| */ | */ | ||||
| private JUnitTest junitTest; | |||||
| private JUnitTest m_junitTest; | |||||
| /** | /** | ||||
| * Collects TestResults. | * Collects TestResults. | ||||
| */ | */ | ||||
| private TestResult res; | |||||
| private TestResult m_res; | |||||
| /** | /** | ||||
| * output written during the test | * output written during the test | ||||
| */ | */ | ||||
| private PrintStream systemError; | |||||
| private PrintStream m_systemError; | |||||
| /** | /** | ||||
| * Error output during the test | * Error output during the test | ||||
| */ | */ | ||||
| private PrintStream systemOut; | |||||
| private PrintStream m_systemOut; | |||||
| /** | /** | ||||
| * Constructor for fork=true or when the user hasn't specified a classpath. | * Constructor for fork=true or when the user hasn't specified a classpath. | ||||
| @@ -142,8 +141,10 @@ public class JUnitTestRunner implements TestListener | |||||
| * @param filtertrace Description of Parameter | * @param filtertrace Description of Parameter | ||||
| * @param haltOnFailure Description of Parameter | * @param haltOnFailure Description of Parameter | ||||
| */ | */ | ||||
| public JUnitTestRunner( JUnitTest test, boolean haltOnError, boolean filtertrace, | |||||
| boolean haltOnFailure ) | |||||
| public JUnitTestRunner( final JUnitTest test, | |||||
| final boolean haltOnError, | |||||
| final boolean filtertrace, | |||||
| final boolean haltOnFailure ) | |||||
| { | { | ||||
| this( test, haltOnError, filtertrace, haltOnFailure, null ); | this( test, haltOnError, filtertrace, haltOnFailure, null ); | ||||
| } | } | ||||
| @@ -162,9 +163,9 @@ public class JUnitTestRunner implements TestListener | |||||
| { | { | ||||
| //JUnitTestRunner.filtertrace = filtertrace; | //JUnitTestRunner.filtertrace = filtertrace; | ||||
| this.filtertrace = filtertrace; | this.filtertrace = filtertrace; | ||||
| this.junitTest = test; | |||||
| this.haltOnError = haltOnError; | |||||
| this.haltOnFailure = haltOnFailure; | |||||
| this.m_junitTest = test; | |||||
| this.m_haltOnError = haltOnError; | |||||
| this.m_haltOnFailure = haltOnFailure; | |||||
| try | try | ||||
| { | { | ||||
| @@ -196,20 +197,20 @@ public class JUnitTestRunner implements TestListener | |||||
| // if there is a suite method available, then try | // if there is a suite method available, then try | ||||
| // to extract the suite from it. If there is an error | // to extract the suite from it. If there is an error | ||||
| // here it will be caught below and reported. | // here it will be caught below and reported. | ||||
| suite = (Test)suiteMethod.invoke( null, new Class[ 0 ] ); | |||||
| m_suite = (Test)suiteMethod.invoke( null, new Class[ 0 ] ); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| // try to extract a test suite automatically | // try to extract a test suite automatically | ||||
| // this will generate warnings if the class is no suitable Test | // this will generate warnings if the class is no suitable Test | ||||
| suite = new TestSuite( testClass ); | |||||
| m_suite = new TestSuite( testClass ); | |||||
| } | } | ||||
| } | } | ||||
| catch( Exception e ) | catch( Exception e ) | ||||
| { | { | ||||
| retCode = ERRORS; | |||||
| exception = e; | |||||
| m_retCode = ERRORS; | |||||
| m_exception = e; | |||||
| } | } | ||||
| } | } | ||||
| @@ -339,7 +340,7 @@ public class JUnitTestRunner implements TestListener | |||||
| * @exception IOException Description of Exception | * @exception IOException Description of Exception | ||||
| */ | */ | ||||
| public static void main( String[] args ) | public static void main( String[] args ) | ||||
| throws IOException | |||||
| throws IOException, TaskException | |||||
| { | { | ||||
| boolean exitAtEnd = true; | boolean exitAtEnd = true; | ||||
| boolean haltError = false; | boolean haltError = false; | ||||
| @@ -391,11 +392,7 @@ public class JUnitTestRunner implements TestListener | |||||
| // Add/overlay system properties on the properties from the Ant project | // Add/overlay system properties on the properties from the Ant project | ||||
| Hashtable p = System.getProperties(); | Hashtable p = System.getProperties(); | ||||
| for( Iterator enum = p.keys(); enum.hasNext(); ) | |||||
| { | |||||
| Object key = enum.next(); | |||||
| props.put( key, p.get( key ) ); | |||||
| } | |||||
| props.putAll( p ); | |||||
| t.setProperties( props ); | t.setProperties( props ); | ||||
| JUnitTestRunner runner = new JUnitTestRunner( t, haltError, stackfilter, haltFail ); | JUnitTestRunner runner = new JUnitTestRunner( t, haltError, stackfilter, haltFail ); | ||||
| @@ -426,7 +423,7 @@ public class JUnitTestRunner implements TestListener | |||||
| fe.setClassname( line.substring( 0, pos ) ); | fe.setClassname( line.substring( 0, pos ) ); | ||||
| fe.setOutfile( new File( line.substring( pos + 1 ) ) ); | fe.setOutfile( new File( line.substring( pos + 1 ) ) ); | ||||
| } | } | ||||
| fromCmdLine.add( fe.createFormatter() ); | |||||
| m_fromCmdLine.add( fe.createFormatter() ); | |||||
| } | } | ||||
| private static boolean filterLine( String line ) | private static boolean filterLine( String line ) | ||||
| @@ -443,9 +440,9 @@ public class JUnitTestRunner implements TestListener | |||||
| private static void transferFormatters( JUnitTestRunner runner ) | private static void transferFormatters( JUnitTestRunner runner ) | ||||
| { | { | ||||
| for( int i = 0; i < fromCmdLine.size(); i++ ) | |||||
| for( int i = 0; i < m_fromCmdLine.size(); i++ ) | |||||
| { | { | ||||
| runner.addFormatter( (JUnitResultFormatter)fromCmdLine.get( i ) ); | |||||
| runner.addFormatter( (JUnitResultFormatter)m_fromCmdLine.get( i ) ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -456,7 +453,7 @@ public class JUnitTestRunner implements TestListener | |||||
| */ | */ | ||||
| public int getRetCode() | public int getRetCode() | ||||
| { | { | ||||
| return retCode; | |||||
| return m_retCode; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -469,9 +466,9 @@ public class JUnitTestRunner implements TestListener | |||||
| */ | */ | ||||
| public void addError( Test test, Throwable t ) | public void addError( Test test, Throwable t ) | ||||
| { | { | ||||
| if( haltOnError ) | |||||
| if( m_haltOnError ) | |||||
| { | { | ||||
| res.stop(); | |||||
| m_res.stop(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -485,9 +482,9 @@ public class JUnitTestRunner implements TestListener | |||||
| */ | */ | ||||
| public void addFailure( Test test, Throwable t ) | public void addFailure( Test test, Throwable t ) | ||||
| { | { | ||||
| if( haltOnFailure ) | |||||
| if( m_haltOnFailure ) | |||||
| { | { | ||||
| res.stop(); | |||||
| m_res.stop(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -506,7 +503,7 @@ public class JUnitTestRunner implements TestListener | |||||
| public void addFormatter( JUnitResultFormatter f ) | public void addFormatter( JUnitResultFormatter f ) | ||||
| { | { | ||||
| formatters.add( f ); | |||||
| m_formatters.add( f ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -521,63 +518,65 @@ public class JUnitTestRunner implements TestListener | |||||
| } | } | ||||
| public void run() | public void run() | ||||
| throws TaskException | |||||
| { | { | ||||
| res = new TestResult(); | |||||
| res.addListener( this ); | |||||
| for( int i = 0; i < formatters.size(); i++ ) | |||||
| m_res = new TestResult(); | |||||
| m_res.addListener( this ); | |||||
| for( int i = 0; i < m_formatters.size(); i++ ) | |||||
| { | { | ||||
| res.addListener( (TestListener)formatters.get( i ) ); | |||||
| final TestListener listener = (TestListener)m_formatters.get( i ); | |||||
| m_res.addListener( listener ); | |||||
| } | } | ||||
| long start = System.currentTimeMillis(); | long start = System.currentTimeMillis(); | ||||
| fireStartTestSuite(); | fireStartTestSuite(); | ||||
| if( exception != null ) | |||||
| if( m_exception != null ) | |||||
| {// had an exception in the constructor | {// had an exception in the constructor | ||||
| for( int i = 0; i < formatters.size(); i++ ) | |||||
| for( int i = 0; i < m_formatters.size(); i++ ) | |||||
| { | { | ||||
| ( (TestListener)formatters.get( i ) ).addError( null, | |||||
| exception ); | |||||
| ( (TestListener)m_formatters.get( i ) ).addError( null, | |||||
| m_exception ); | |||||
| } | } | ||||
| junitTest.setCounts( 1, 0, 1 ); | |||||
| junitTest.setRunTime( 0 ); | |||||
| m_junitTest.setCounts( 1, 0, 1 ); | |||||
| m_junitTest.setRunTime( 0 ); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| ByteArrayOutputStream errStrm = new ByteArrayOutputStream(); | ByteArrayOutputStream errStrm = new ByteArrayOutputStream(); | ||||
| systemError = new PrintStream( errStrm ); | |||||
| m_systemError = new PrintStream( errStrm ); | |||||
| ByteArrayOutputStream outStrm = new ByteArrayOutputStream(); | ByteArrayOutputStream outStrm = new ByteArrayOutputStream(); | ||||
| systemOut = new PrintStream( outStrm ); | |||||
| m_systemOut = new PrintStream( outStrm ); | |||||
| try | try | ||||
| { | { | ||||
| suite.run( res ); | |||||
| m_suite.run( m_res ); | |||||
| } | } | ||||
| finally | finally | ||||
| { | { | ||||
| systemError.close(); | |||||
| systemError = null; | |||||
| systemOut.close(); | |||||
| systemOut = null; | |||||
| m_systemError.close(); | |||||
| m_systemError = null; | |||||
| m_systemOut.close(); | |||||
| m_systemOut = null; | |||||
| sendOutAndErr( new String( outStrm.toByteArray() ), | sendOutAndErr( new String( outStrm.toByteArray() ), | ||||
| new String( errStrm.toByteArray() ) ); | new String( errStrm.toByteArray() ) ); | ||||
| junitTest.setCounts( res.runCount(), res.failureCount(), | |||||
| res.errorCount() ); | |||||
| junitTest.setRunTime( System.currentTimeMillis() - start ); | |||||
| m_junitTest.setCounts( m_res.runCount(), m_res.failureCount(), | |||||
| m_res.errorCount() ); | |||||
| m_junitTest.setRunTime( System.currentTimeMillis() - start ); | |||||
| } | } | ||||
| } | } | ||||
| fireEndTestSuite(); | fireEndTestSuite(); | ||||
| if( retCode != SUCCESS || res.errorCount() != 0 ) | |||||
| if( m_retCode != SUCCESS || m_res.errorCount() != 0 ) | |||||
| { | { | ||||
| retCode = ERRORS; | |||||
| m_retCode = ERRORS; | |||||
| } | } | ||||
| else if( res.failureCount() != 0 ) | |||||
| else if( m_res.failureCount() != 0 ) | |||||
| { | { | ||||
| retCode = FAILURES; | |||||
| m_retCode = FAILURES; | |||||
| } | } | ||||
| } | } | ||||
| @@ -585,8 +584,6 @@ public class JUnitTestRunner implements TestListener | |||||
| * Interface TestListener. <p> | * Interface TestListener. <p> | ||||
| * | * | ||||
| * A new Test is started. | * A new Test is started. | ||||
| * | |||||
| * @param t Description of Parameter | |||||
| */ | */ | ||||
| public void startTest( Test t ) | public void startTest( Test t ) | ||||
| { | { | ||||
| @@ -594,46 +591,53 @@ public class JUnitTestRunner implements TestListener | |||||
| protected void handleErrorOutput( String line ) | protected void handleErrorOutput( String line ) | ||||
| { | { | ||||
| if( systemError != null ) | |||||
| if( m_systemError != null ) | |||||
| { | { | ||||
| systemError.println( line ); | |||||
| m_systemError.println( line ); | |||||
| } | } | ||||
| } | } | ||||
| protected void handleOutput( String line ) | protected void handleOutput( String line ) | ||||
| { | { | ||||
| if( systemOut != null ) | |||||
| if( m_systemOut != null ) | |||||
| { | { | ||||
| systemOut.println( line ); | |||||
| m_systemOut.println( line ); | |||||
| } | } | ||||
| } | } | ||||
| private void fireEndTestSuite() | private void fireEndTestSuite() | ||||
| throws TaskException | |||||
| { | { | ||||
| for( int i = 0; i < formatters.size(); i++ ) | |||||
| final int size = m_formatters.size(); | |||||
| for( int i = 0; i < size; i++ ) | |||||
| { | { | ||||
| ( (JUnitResultFormatter)formatters.get( i ) ).endTestSuite( junitTest ); | |||||
| final JUnitResultFormatter formatter = | |||||
| (JUnitResultFormatter)m_formatters.get( i ); | |||||
| formatter.endTestSuite( m_junitTest ); | |||||
| } | } | ||||
| } | } | ||||
| private void fireStartTestSuite() | private void fireStartTestSuite() | ||||
| throws TaskException | |||||
| { | { | ||||
| for( int i = 0; i < formatters.size(); i++ ) | |||||
| final int size = m_formatters.size(); | |||||
| for( int i = 0; i < size; i++ ) | |||||
| { | { | ||||
| ( (JUnitResultFormatter)formatters.get( i ) ).startTestSuite( junitTest ); | |||||
| final JUnitResultFormatter formatter = (JUnitResultFormatter)m_formatters.get( i ); | |||||
| formatter.startTestSuite( m_junitTest ); | |||||
| } | } | ||||
| } | } | ||||
| private void sendOutAndErr( String out, String err ) | private void sendOutAndErr( String out, String err ) | ||||
| { | { | ||||
| for( int i = 0; i < formatters.size(); i++ ) | |||||
| final int size = m_formatters.size(); | |||||
| for( int i = 0; i < size; i++ ) | |||||
| { | { | ||||
| JUnitResultFormatter formatter = | |||||
| ( (JUnitResultFormatter)formatters.get( i ) ); | |||||
| final JUnitResultFormatter formatter = | |||||
| (JUnitResultFormatter)m_formatters.get( i ); | |||||
| formatter.setSystemOutput( out ); | formatter.setSystemOutput( out ); | ||||
| formatter.setSystemError( err ); | formatter.setSystemError( err ); | ||||
| } | } | ||||
| } | } | ||||
| }// JUnitTestRunner | |||||
| } | |||||
| @@ -0,0 +1,37 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE.txt file. | |||||
| */ | |||||
| package org.apache.tools.ant.taskdefs.optional.junit; | |||||
| import java.util.ArrayList; | |||||
| import org.w3c.dom.Node; | |||||
| import org.w3c.dom.NodeList; | |||||
| /** | |||||
| * custom implementation of a nodelist | |||||
| */ | |||||
| public class NodeListImpl | |||||
| extends ArrayList | |||||
| implements NodeList | |||||
| { | |||||
| public int getLength() | |||||
| { | |||||
| return size(); | |||||
| } | |||||
| public Node item( final int i ) | |||||
| { | |||||
| try | |||||
| { | |||||
| return (Node)get( i ); | |||||
| } | |||||
| catch( final ArrayIndexOutOfBoundsException aioobe ) | |||||
| { | |||||
| return null;// conforming to NodeList interface | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -224,13 +224,14 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||||
| Properties props = suite.getProperties(); | Properties props = suite.getProperties(); | ||||
| if( props != null ) | if( props != null ) | ||||
| { | { | ||||
| Iterator e = props.propertyNames(); | |||||
| final Iterator e = props.keySet().iterator(); | |||||
| while( e.hasNext() ) | while( e.hasNext() ) | ||||
| { | { | ||||
| String name = (String)e.next(); | |||||
| Element propElement = doc.createElement( PROPERTY ); | |||||
| final String name = (String)e.next(); | |||||
| final String value = props.getProperty( name ); | |||||
| final Element propElement = doc.createElement( PROPERTY ); | |||||
| propElement.setAttribute( ATTR_NAME, name ); | propElement.setAttribute( ATTR_NAME, name ); | ||||
| propElement.setAttribute( ATTR_VALUE, props.getProperty( name ) ); | |||||
| propElement.setAttribute( ATTR_VALUE, value ); | |||||
| propsElement.appendChild( propElement ); | propsElement.appendChild( propElement ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -17,7 +17,6 @@ import java.util.ArrayList; | |||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import javax.xml.parsers.DocumentBuilder; | import javax.xml.parsers.DocumentBuilder; | ||||
| import javax.xml.parsers.DocumentBuilderFactory; | import javax.xml.parsers.DocumentBuilderFactory; | ||||
| import org.apache.avalon.excalibur.io.FileUtil; | |||||
| import org.apache.avalon.framework.ExceptionUtil; | import org.apache.avalon.framework.ExceptionUtil; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
| @@ -43,9 +42,10 @@ import org.xml.sax.SAXException; | |||||
| * | * | ||||
| * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | ||||
| */ | */ | ||||
| public class XMLResultAggregator extends Task implements XMLConstants | |||||
| public class XMLResultAggregator | |||||
| extends Task | |||||
| implements XMLConstants | |||||
| { | { | ||||
| /** | /** | ||||
| * the default directory: <tt>.</tt> . It is resolved from the project | * the default directory: <tt>.</tt> . It is resolved from the project | ||||
| * directory | * directory | ||||
| @@ -147,7 +147,7 @@ public class XMLResultAggregator extends Task implements XMLConstants | |||||
| public void execute() | public void execute() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| Element rootElement = createDocument(); | |||||
| final Element rootElement = createDocument(); | |||||
| File destFile = getDestinationFile(); | File destFile = getDestinationFile(); | ||||
| // write the document | // write the document | ||||
| try | try | ||||
| @@ -176,6 +176,7 @@ public class XMLResultAggregator extends Task implements XMLConstants | |||||
| * @return the destination file where should be written the result file. | * @return the destination file where should be written the result file. | ||||
| */ | */ | ||||
| protected File getDestinationFile() | protected File getDestinationFile() | ||||
| throws TaskException | |||||
| { | { | ||||
| if( toFile == null ) | if( toFile == null ) | ||||
| { | { | ||||
| @@ -183,7 +184,7 @@ public class XMLResultAggregator extends Task implements XMLConstants | |||||
| } | } | ||||
| if( toDir == null ) | if( toDir == null ) | ||||
| { | { | ||||
| toDir = FileUtil.resolveFile( getBaseDirectory(), DEFAULT_DIR ); | |||||
| toDir = resolveFile( DEFAULT_DIR ); | |||||
| } | } | ||||
| return new File( toDir, toFile ); | return new File( toDir, toFile ); | ||||
| } | } | ||||
| @@ -194,22 +195,23 @@ public class XMLResultAggregator extends Task implements XMLConstants | |||||
| * @return all files in the fileset that end with a '.xml'. | * @return all files in the fileset that end with a '.xml'. | ||||
| */ | */ | ||||
| protected File[] getFiles() | protected File[] getFiles() | ||||
| throws TaskException | |||||
| { | { | ||||
| ArrayList v = new ArrayList(); | |||||
| final ArrayList v = new ArrayList(); | |||||
| final int size = filesets.size(); | final int size = filesets.size(); | ||||
| for( int i = 0; i < size; i++ ) | for( int i = 0; i < size; i++ ) | ||||
| { | { | ||||
| FileSet fs = (FileSet)filesets.get( i ); | |||||
| DirectoryScanner ds = fs.getDirectoryScanner(); | |||||
| ds.scan(); | |||||
| String[] f = ds.getIncludedFiles(); | |||||
| for( int j = 0; j < f.length; j++ ) | |||||
| final FileSet fileSet = (FileSet)filesets.get( i ); | |||||
| final DirectoryScanner scanner = fileSet.getDirectoryScanner(); | |||||
| scanner.scan(); | |||||
| final String[] includes = scanner.getIncludedFiles(); | |||||
| for( int j = 0; j < includes.length; j++ ) | |||||
| { | { | ||||
| String pathname = f[ j ]; | |||||
| final String pathname = includes[ j ]; | |||||
| if( pathname.endsWith( ".xml" ) ) | if( pathname.endsWith( ".xml" ) ) | ||||
| { | { | ||||
| File file = new File( ds.getBasedir(), pathname ); | |||||
| file = FileUtil.resolveFile( getBaseDirectory(), file.getPath() ); | |||||
| File file = new File( scanner.getBasedir(), pathname ); | |||||
| file = resolveFile( file.getPath() ); | |||||
| v.add( file ); | v.add( file ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -257,6 +259,7 @@ public class XMLResultAggregator extends Task implements XMLConstants | |||||
| * @return the root element of DOM tree that aggregates all testsuites. | * @return the root element of DOM tree that aggregates all testsuites. | ||||
| */ | */ | ||||
| protected Element createDocument() | protected Element createDocument() | ||||
| throws TaskException | |||||
| { | { | ||||
| // create the dom tree | // create the dom tree | ||||
| DocumentBuilder builder = getDocumentBuilder(); | DocumentBuilder builder = getDocumentBuilder(); | ||||
| @@ -265,7 +268,7 @@ public class XMLResultAggregator extends Task implements XMLConstants | |||||
| doc.appendChild( rootElement ); | doc.appendChild( rootElement ); | ||||
| // get all files and add them to the document | // get all files and add them to the document | ||||
| File[] files = getFiles(); | |||||
| final File[] files = getFiles(); | |||||
| for( int i = 0; i < files.length; i++ ) | for( int i = 0; i < files.length; i++ ) | ||||
| { | { | ||||
| try | try | ||||
| @@ -27,8 +27,8 @@ public class Xalan1Executor extends XalanExecutor | |||||
| { | { | ||||
| XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); | XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); | ||||
| // need to quote otherwise it breaks because of "extra illegal tokens" | // need to quote otherwise it breaks because of "extra illegal tokens" | ||||
| processor.setStylesheetParam( "output.dir", "'" + caller.toDir.getAbsolutePath() + "'" ); | |||||
| XSLTInputSource xml_src = new XSLTInputSource( caller.document ); | |||||
| processor.setStylesheetParam( "output.dir", "'" + caller.getToDir().getAbsolutePath() + "'" ); | |||||
| XSLTInputSource xml_src = new XSLTInputSource( caller.getDocument() ); | |||||
| String system_id = caller.getStylesheetSystemId(); | String system_id = caller.getStylesheetSystemId(); | ||||
| XSLTInputSource xsl_src = new XSLTInputSource( system_id ); | XSLTInputSource xsl_src = new XSLTInputSource( system_id ); | ||||
| OutputStream os = getOutputStream(); | OutputStream os = getOutputStream(); | ||||
| @@ -31,9 +31,9 @@ public class Xalan2Executor extends XalanExecutor | |||||
| String system_id = caller.getStylesheetSystemId(); | String system_id = caller.getStylesheetSystemId(); | ||||
| Source xsl_src = new StreamSource( system_id ); | Source xsl_src = new StreamSource( system_id ); | ||||
| Transformer tformer = tfactory.newTransformer( xsl_src ); | Transformer tformer = tfactory.newTransformer( xsl_src ); | ||||
| Source xml_src = new DOMSource( caller.document ); | |||||
| Source xml_src = new DOMSource( caller.getDocument() ); | |||||
| OutputStream os = getOutputStream(); | OutputStream os = getOutputStream(); | ||||
| tformer.setParameter( "output.dir", caller.toDir.getAbsolutePath() ); | |||||
| tformer.setParameter( "output.dir", caller.getToDir().getAbsolutePath() ); | |||||
| Result result = new StreamResult( os ); | Result result = new StreamResult( os ); | ||||
| tformer.transform( xml_src, result ); | tformer.transform( xml_src, result ); | ||||
| } | } | ||||
| @@ -95,7 +95,7 @@ abstract class XalanExecutor | |||||
| protected OutputStream getOutputStream() | protected OutputStream getOutputStream() | ||||
| throws IOException | throws IOException | ||||
| { | { | ||||
| if( caller.FRAMES.equals( caller.format ) ) | |||||
| if( caller.FRAMES.equals( caller.getFormat() ) ) | |||||
| { | { | ||||
| // dummy output for the framed report | // dummy output for the framed report | ||||
| // it's all done by extension... | // it's all done by extension... | ||||
| @@ -103,7 +103,7 @@ abstract class XalanExecutor | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| return new FileOutputStream( new File( caller.toDir, "junit-noframes.html" ) ); | |||||
| return new FileOutputStream( new File( caller.getToDir(), "junit-noframes.html" ) ); | |||||
| } | } | ||||
| } | } | ||||