maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1098758 - in /maven/surefire/trunk/surefire-api/src: main/java/org/apache/maven/plugin/surefire/report/ main/java/org/apache/maven/surefire/booter/ main/java/org/apache/maven/surefire/report/ test/java/org/apache/maven/surefire/report/
Date Mon, 02 May 2011 19:27:22 GMT
Author: krosenvold
Date: Mon May  2 19:27:22 2011
New Revision: 1098758

URL: http://svn.apache.org/viewvc?rev=1098758&view=rev
Log:
o Simplified reporter construction

Modified:
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/report/ReporterManagerFactory.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/StartupReportConfiguration.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/BriefConsoleReporter.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/BriefFileReporter.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputDirectReporter.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputFileReporter.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleReporter.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DetailedConsoleReporter.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/FileReporter.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterConfiguration.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
    maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/XMLReporterTest.java

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/report/ReporterManagerFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/report/ReporterManagerFactory.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/report/ReporterManagerFactory.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/report/ReporterManagerFactory.java
Mon May  2 19:27:22 2011
@@ -19,7 +19,6 @@ package org.apache.maven.plugin.surefire
  * under the License.
  */
 
-import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -37,8 +36,6 @@ import org.apache.maven.surefire.report.
 import org.apache.maven.surefire.report.TestSetRunListener;
 import org.apache.maven.surefire.report.XMLReporter;
 import org.apache.maven.surefire.suite.RunResult;
-import org.apache.maven.surefire.util.ReflectionUtils;
-import org.apache.maven.surefire.util.SurefireReflectionException;
 
 /**
  * Provides RunListener implementations to the providers.
@@ -85,27 +82,37 @@ public class ReporterManagerFactory
 
     private AbstractConsoleReporter instantiateConsoleReporter()
     {
-        return (AbstractConsoleReporter) instantiateReport( reportConfiguration.getConsoleReporter()
);
+        return reportConfiguration.instantiateConsoleReporter();
     }
 
     private AbstractFileReporter instantiateFileReporter()
     {
-        return (AbstractFileReporter) instantiateReport( reportConfiguration.getFileReporter()
);
+        return reportConfiguration.instantiateFileReporter();
     }
 
     private XMLReporter instantiateXmlReporter()
     {
-        return (XMLReporter) instantiateReport( reportConfiguration.getXmlReporterName()
);
+        return reportConfiguration.instantiateXmlReporter();
     }
 
     private Reporter instantiateConsoleOutputFileReporter()
     {
-        return instantiateReport( reportConfiguration.getConsoleOutputFileReporterName()
);
+        return reportConfiguration.instantiateConsoleOutputFileReporterName(
+            reporterConfiguration.getOriginalSystemOut() );
     }
 
     private List instantiateReports()
     {
-        return instantiateReportsNewStyle( reportConfiguration.getReports(), reporterConfiguration,
surefireClassLoader );
+        List result = new ArrayList( );
+        addIfNotNull( result, instantiateConsoleReporter() );
+        addIfNotNull( result, instantiateFileReporter() );
+        addIfNotNull( result, instantiateXmlReporter() );
+        addIfNotNull( result, instantiateConsoleOutputFileReporter() );
+        return result;
+    }
+
+    private void addIfNotNull( List result, Reporter reporter){
+        if (reporter != null) result.add(  reporter );
     }
 
     public RunResult close()
@@ -114,63 +121,6 @@ public class ReporterManagerFactory
         return globalStats.getRunResult();
     }
 
-    private List instantiateReportsNewStyle( List reportDefinitions, ReporterConfiguration
reporterConfiguration,
-                                             ClassLoader classLoader )
-    {
-        List reports = new ArrayList();
-
-        for ( Iterator i = reportDefinitions.iterator(); i.hasNext(); )
-        {
-
-            String className = (String) i.next();
-
-            Reporter report = instantiateReportNewStyle( className, reporterConfiguration,
classLoader );
-
-            reports.add( report );
-        }
-
-        return reports;
-    }
-
-    public Reporter instantiateReport( String reportName )
-    {
-        if ( reportName == null )
-        {
-            return null;
-        }
-        return instantiateReportNewStyle( reportName, reporterConfiguration, surefireClassLoader
);
-    }
-
-    private static Reporter instantiateReportNewStyle( String className, ReporterConfiguration
params,
-                                                       ClassLoader classLoader )
-    {
-        Class clazz = ReflectionUtils.loadClass( classLoader, className );
-
-        if ( params != null )
-        {
-            Class[] paramTypes = new Class[1];
-            paramTypes[0] = ReflectionUtils.loadClass( classLoader, ReporterConfiguration.class.getName()
);
-            Constructor constructor = ReflectionUtils.getConstructor( clazz, paramTypes );
-            return (Reporter) ReflectionUtils.newInstance( constructor, new Object[]{ params
} );
-        }
-        else
-        {
-            try
-            {
-                return (Reporter) clazz.newInstance();
-            }
-            catch ( IllegalAccessException e )
-            {
-                throw new SurefireReflectionException( e );
-            }
-            catch ( InstantiationException e )
-            {
-                throw new SurefireReflectionException( e );
-            }
-        }
-
-    }
-
     public DirectConsoleReporter createConsoleReporter()
     {
         return new DefaultDirectConsoleReporter( reporterConfiguration.getOriginalSystemOut()
);

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/StartupReportConfiguration.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/StartupReportConfiguration.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/StartupReportConfiguration.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/StartupReportConfiguration.java
Mon May  2 19:27:22 2011
@@ -20,9 +20,12 @@ package org.apache.maven.surefire.booter
  */
 
 import java.io.File;
+import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
+import org.apache.maven.surefire.report.AbstractConsoleReporter;
+import org.apache.maven.surefire.report.AbstractFileReporter;
 import org.apache.maven.surefire.report.BriefConsoleReporter;
 import org.apache.maven.surefire.report.BriefFileReporter;
 import org.apache.maven.surefire.report.ConsoleOutputDirectReporter;
@@ -30,6 +33,7 @@ import org.apache.maven.surefire.report.
 import org.apache.maven.surefire.report.ConsoleReporter;
 import org.apache.maven.surefire.report.DetailedConsoleReporter;
 import org.apache.maven.surefire.report.FileReporter;
+import org.apache.maven.surefire.report.Reporter;
 import org.apache.maven.surefire.report.XMLReporter;
 
 /**
@@ -125,6 +129,15 @@ public class StartupReportConfiguration
         return null;
     }
 
+    public XMLReporter instantiateXmlReporter()
+    {
+        if ( !isDisableXmlReport() )
+        {
+            return new XMLReporter(trimStackTrace, reportsDirectory);
+        }
+        return null;
+    }
+
     public String getFileReporter()
     {
         if ( isUseFile() )
@@ -141,6 +154,23 @@ public class StartupReportConfiguration
         return null;
     }
 
+    public AbstractFileReporter instantiateFileReporter()
+    {
+        if ( isUseFile() )
+        {
+            if ( BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
+            {
+                return new BriefFileReporter(trimStackTrace, reportsDirectory);
+            }
+            else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
+            {
+                return new FileReporter(trimStackTrace, reportsDirectory);
+            }
+        }
+        return null;
+    }
+
+
     /**
      * Returns the reporter that will write to the console
      *
@@ -160,10 +190,23 @@ public class StartupReportConfiguration
         {
             return DetailedConsoleReporter.class.getName();
         }
-/*        if (isRedirectTestOutputToFile())
+        return null;
+    }
+
+    public AbstractConsoleReporter instantiateConsoleReporter()
+    {
+        if ( isUseFile() )
+        {
+            return isPrintSummary() ? new ConsoleReporter(trimStackTrace) : null;
+        }
+        else if ( isRedirectTestOutputToFile() || BRIEF_REPORT_FORMAT.equals( getReportFormat()
) )
+        {
+            return new BriefConsoleReporter(trimStackTrace);
+        }
+        else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
         {
-            return null;
-        }*/
+            return new DetailedConsoleReporter(trimStackTrace );
+        }
         return null;
     }
 
@@ -179,6 +222,18 @@ public class StartupReportConfiguration
         }
     }
 
+    public Reporter instantiateConsoleOutputFileReporterName(PrintStream originalSystemOut)
+    {
+        if ( isRedirectTestOutputToFile() )
+        {
+            return new ConsoleOutputFileReporter(reportsDirectory);
+        }
+        else
+        {
+            return new ConsoleOutputDirectReporter(originalSystemOut);
+        }
+    }
+
 
     /**
      * A list of classnames representing runnable reports for this test-run.

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java
Mon May  2 19:27:22 2011
@@ -43,11 +43,6 @@ public abstract class AbstractFileReport
         this.deleteOnStarting = false;
     }
 
-    AbstractFileReporter( ReporterConfiguration reporterConfiguration, String format )
-    {
-        this( reporterConfiguration.isTrimStackTrace().booleanValue(), format, reporterConfiguration.getReportsDirectory());
-    }
-
     public void testSetStarting( ReportEntry report )
         throws ReporterException
     {

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/BriefConsoleReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/BriefConsoleReporter.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/BriefConsoleReporter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/BriefConsoleReporter.java
Mon May  2 19:27:22 2011
@@ -29,8 +29,9 @@ package org.apache.maven.surefire.report
 public class BriefConsoleReporter
     extends AbstractConsoleReporter
 {
-    public BriefConsoleReporter( ReporterConfiguration reporterConfiguration )
+
+    public BriefConsoleReporter( boolean trimStackTrace )
     {
-        super( reporterConfiguration.isTrimStackTrace().booleanValue(), BRIEF );
+        super( trimStackTrace, BRIEF );
     }
 }

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/BriefFileReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/BriefFileReporter.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/BriefFileReporter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/BriefFileReporter.java
Mon May  2 19:27:22 2011
@@ -19,6 +19,8 @@ package org.apache.maven.surefire.report
  * under the License.
  */
 
+import java.io.File;
+
 /**
  * Brief format file reporter.
  *
@@ -28,9 +30,9 @@ package org.apache.maven.surefire.report
 public class BriefFileReporter
     extends AbstractFileReporter
 {
-    public BriefFileReporter( ReporterConfiguration reporterConfiguration )
+
+    public BriefFileReporter( boolean trimStackTrace, File reportsDirectory )
     {
-        super( reporterConfiguration, BRIEF );
+        super( trimStackTrace, BRIEF, reportsDirectory );
     }
-
 }

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputDirectReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputDirectReporter.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputDirectReporter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputDirectReporter.java
Mon May  2 19:27:22 2011
@@ -34,9 +34,9 @@ public class ConsoleOutputDirectReporter
 {
     private final PrintStream reportsDirectory;
 
-    public ConsoleOutputDirectReporter( ReporterConfiguration reporterConfiguration )
+    public ConsoleOutputDirectReporter( PrintStream reportsDirectory )
     {
-        this.reportsDirectory = reporterConfiguration.getOriginalSystemOut();
+        this.reportsDirectory = reportsDirectory;
     }
 
     public void testSetStarting( ReportEntry reportEntry )

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputFileReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputFileReporter.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputFileReporter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputFileReporter.java
Mon May  2 19:27:22 2011
@@ -48,14 +48,9 @@ public class ConsoleOutputFileReporter
 
     private volatile PrintWriter printWriter;
 
-    /**
-     * Create a consumer that will write to a {@link java.io.File} for each test
-     * @param reporterConfiguration The configuration
-     */
-
-    public ConsoleOutputFileReporter( ReporterConfiguration reporterConfiguration )
+    public ConsoleOutputFileReporter( File reportsDirectory )
     {
-        this.reportsDirectory = reporterConfiguration.getReportsDirectory();
+        this.reportsDirectory = reportsDirectory;
     }
 
     public void testSetStarting( ReportEntry reportEntry )

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleReporter.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleReporter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleReporter.java
Mon May  2 19:27:22 2011
@@ -28,9 +28,9 @@ package org.apache.maven.surefire.report
 public class ConsoleReporter
     extends AbstractConsoleReporter
 {
-    public ConsoleReporter( ReporterConfiguration reporterConfiguration )
+
+    public ConsoleReporter( boolean trimStackTrace )
     {
-        super( reporterConfiguration.isTrimStackTrace().booleanValue(), SUMMARY);
+        super( trimStackTrace, SUMMARY );
     }
-
 }

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DetailedConsoleReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DetailedConsoleReporter.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DetailedConsoleReporter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DetailedConsoleReporter.java
Mon May  2 19:27:22 2011
@@ -28,8 +28,9 @@ package org.apache.maven.surefire.report
 public class DetailedConsoleReporter
     extends AbstractConsoleReporter
 {
-    public DetailedConsoleReporter( ReporterConfiguration reporterConfiguration )
+
+    public DetailedConsoleReporter( boolean trimStackTrace )
     {
-        super( reporterConfiguration.isTrimStackTrace().booleanValue(), PLAIN);
+        super( trimStackTrace, PLAIN );
     }
 }

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/FileReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/FileReporter.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/FileReporter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/FileReporter.java
Mon May  2 19:27:22 2011
@@ -19,6 +19,8 @@ package org.apache.maven.surefire.report
  * under the License.
  */
 
+import java.io.File;
+
 /**
  * Text file reporter.
  *
@@ -28,8 +30,9 @@ package org.apache.maven.surefire.report
 public class FileReporter
     extends AbstractFileReporter
 {
-    public FileReporter( ReporterConfiguration reporterConfiguration )
+
+    public FileReporter( boolean trimStackTrace, File reportsDirectory )
     {
-        super( reporterConfiguration, PLAIN );
+        super( trimStackTrace, PLAIN, reportsDirectory );
     }
 }

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterConfiguration.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterConfiguration.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterConfiguration.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterConfiguration.java
Mon May  2 19:27:22 2011
@@ -23,10 +23,9 @@ import java.io.File;
 import java.io.PrintStream;
 
 /**
- * The configuration of the reporter. Most of this stuff is not relevant for the providers
- * and should be moved out of the api.
+ * Bits and pieces of reporting configuration that seem to be necessary on the provider side.
  * <p/>
- * This class seems to be the focal point of all the bad code smells left in reporting ;)
+ * Todo: Consider moving these fields elsewhere, this concept does not smell too good
  *
  * @author Kristian Rosenvold
  */

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
Mon May  2 19:27:22 2011
@@ -62,11 +62,6 @@ public class XMLReporter
         this.deleteOnStarting = false;
     }
 
-    public XMLReporter( ReporterConfiguration reporterConfiguration )
-    {
-        this( reporterConfiguration.isTrimStackTrace().booleanValue(), reporterConfiguration.getReportsDirectory()
);
-    }
-
 
     public void writeMessage( String message )
     {

Modified: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/XMLReporterTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/XMLReporterTest.java?rev=1098758&r1=1098757&r2=1098758&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/XMLReporterTest.java
(original)
+++ maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/XMLReporterTest.java
Mon May  2 19:27:22 2011
@@ -19,6 +19,7 @@ package org.apache.maven.surefire.report
  * under the License.
  */
 
+import java.io.File;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 
 import junit.framework.AssertionFailedError;
@@ -38,7 +39,7 @@ public class XMLReporterTest
         throws Exception
     {
         super.setUp();
-        reporter = new XMLReporter( new ReporterConfiguration( null, Boolean.TRUE ) );
+        reporter = new XMLReporter( true, new File( "." ));
         message = "junit.framework.AssertionFailedError";
         reportEntry = new SimpleReportEntry( this.getClass().getName(), "XMLReporterTest",
                                              new PojoStackTraceWriter( "", "", new AssertionFailedError()
) );



Mime
View raw message