maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1030636 - in /maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter: ./ output/
Date Wed, 03 Nov 2010 19:47:24 GMT
Author: krosenvold
Date: Wed Nov  3 19:47:24 2010
New Revision: 1030636

URL: http://svn.apache.org/viewvc?rev=1030636&view=rev
Log:
[SUREFIRE-640] Threading issue when redirectToOutputFile=true

Modified:
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/FileOutputConsumerProxy.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/ForkingStreamConsumer.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/OutputConsumerProxy.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/PrintWriterOutputConsumer.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/StandardOutputConsumer.java

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java?rev=1030636&r1=1030635&r2=1030636&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
Wed Nov  3 19:47:24 2010
@@ -186,7 +186,7 @@ public class SurefireBooter
     /**
      * Setting this to true will cause a failure if there are no tests to run
      *
-     * @param redirectTestOutputToFile
+     * @param failIfNoTests true if we should fail with no tests
      */
     public void setFailIfNoTests( boolean failIfNoTests )
     {

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/FileOutputConsumerProxy.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/FileOutputConsumerProxy.java?rev=1030636&r1=1030635&r2=1030636&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/FileOutputConsumerProxy.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/FileOutputConsumerProxy.java
Wed Nov  3 19:47:24 2010
@@ -39,82 +39,36 @@ public class FileOutputConsumerProxy
     extends OutputConsumerProxy
 {
 
-    private static final String USER_DIR = System.getProperty( "user.dir" );
-
     private static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
 
-    private File reportsDirectory;
+    private final File reportsDirectory;
 
-    private PrintWriter printWriter;
-    
-    private StringBuffer outputBuffer = new StringBuffer();
-    
-    /**
-     * Create a consumer that will write to a {@link File} for each test.
-     * Files will be saved in working directory.
-     */
-    public FileOutputConsumerProxy( OutputConsumer outputConsumer )
-    {
-        this( outputConsumer, new File( USER_DIR ) );
-    }
+    private final StringBuffer outputBuffer = new StringBuffer();
+
+    private volatile PrintWriter printWriter;
 
     /**
      * Create a consumer that will write to a {@link File} for each test
      *
+     * @param outputConsumer   the output consumer
      * @param reportsDirectory directory where files will be saved
      */
     public FileOutputConsumerProxy( OutputConsumer outputConsumer, File reportsDirectory
)
     {
         super( outputConsumer );
-        this.setReportsDirectory( reportsDirectory );
-    }
-
-    /**
-     * Set the directory where reports will be saved
-     *
-     * @param reportsDirectory the directory
-     */
-    public void setReportsDirectory( File reportsDirectory )
-    {
         this.reportsDirectory = reportsDirectory;
     }
 
-    /**
-     * Get the directory where reports will be saved
-     */
-    public File getReportsDirectory()
-    {
-        return reportsDirectory;
-    }
-
-    /**
-     * Set the {@link PrintWriter} used for the current test suite
-     *
-     * @param writer
-     */
-    public void setPrintWriter( PrintWriter writer )
-    {
-        this.printWriter = writer;
-    }
-
-    /**
-     * Get the {@link PrintWriter} used for the current test suite
-     */
-    public PrintWriter getPrintWriter()
-    {
-        return printWriter;
-    }
-
     public void testSetStarting( ReportEntry reportEntry )
     {
-        if ( getPrintWriter() != null )
+        if ( printWriter != null )
         {
             throw new IllegalStateException( "testSetStarting called twice" );
         }
-        File file = new File( getReportsDirectory(), reportEntry.getName() + "-output.txt"
);
+        File file = new File( reportsDirectory, reportEntry.getName() + "-output.txt" );
         try
         {
-            setPrintWriter( new PrintWriter( new BufferedWriter( new FileWriter( file ) )
) );
+            this.printWriter = new PrintWriter( new BufferedWriter( new FileWriter( file
) ) );
         }
         catch ( IOException e )
         {
@@ -125,41 +79,43 @@ public class FileOutputConsumerProxy
 
     public void testSetCompleted()
     {
-        if ( getPrintWriter() == null )
+        if ( printWriter == null )
         {
             throw new IllegalStateException( "testSetCompleted called before testSetStarting"
);
         }
         if ( outputBuffer.length() > 0 )
         {
-            getPrintWriter().write( outputBuffer.toString() );
-            getPrintWriter().write( LINE_SEPARATOR );
+            printWriter.write( outputBuffer.toString() );
+            printWriter.write( LINE_SEPARATOR );
             outputBuffer.setLength( 0 );
         }
-        getPrintWriter().close();
-        setPrintWriter( null );
+        printWriter.close();
+        this.printWriter = null;
         super.testSetCompleted();
     }
 
     /**
      * Write the output to the current test file
+     * <p/>
+     * This method may be called from multiple threads
      */
-    public void consumeOutputLine( String line )
+    public synchronized void consumeOutputLine( String line )
     {
-        if ( getPrintWriter() == null )
+        if ( printWriter == null )
         {
             outputBuffer.append( line );
             outputBuffer.append( LINE_SEPARATOR );
             return;
         }
-        
+
         if ( outputBuffer.length() > 0 )
         {
-            getPrintWriter().write( outputBuffer.toString() );
-            getPrintWriter().write( LINE_SEPARATOR );
+            printWriter.write( outputBuffer.toString() );
+            printWriter.write( LINE_SEPARATOR );
             outputBuffer.setLength( 0 );
         }
-        getPrintWriter().write( line );
-        getPrintWriter().write( LINE_SEPARATOR );
+        printWriter.write( line );
+        printWriter.write( LINE_SEPARATOR );
     }
 
 }

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/ForkingStreamConsumer.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/ForkingStreamConsumer.java?rev=1030636&r1=1030635&r2=1030636&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/ForkingStreamConsumer.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/ForkingStreamConsumer.java
Wed Nov  3 19:47:24 2010
@@ -39,7 +39,7 @@ public class ForkingStreamConsumer
 
     private final static int FOOTER_PREFIX_LENGTH = ForkingConsoleReporter.FORKING_PREFIX_FOOTER.length();
 
-    private OutputConsumer outputConsumer;
+    private final OutputConsumer outputConsumer;
 
     public ForkingStreamConsumer( OutputConsumer outputConsumer )
     {
@@ -77,6 +77,7 @@ public class ForkingStreamConsumer
 
     /**
      * Get the underlying output consumer.
+     * @return the output consumer
      */
     public OutputConsumer getOutputConsumer()
     {

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/OutputConsumerProxy.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/OutputConsumerProxy.java?rev=1030636&r1=1030635&r2=1030636&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/OutputConsumerProxy.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/OutputConsumerProxy.java
Wed Nov  3 19:47:24 2010
@@ -32,7 +32,7 @@ public class OutputConsumerProxy
     implements OutputConsumer
 {
 
-    private OutputConsumer outputConsumer;
+    private final OutputConsumer outputConsumer;
 
     /**
      * Create a output consumer that will delegate all calls to the proxied output consumer
@@ -41,16 +41,6 @@ public class OutputConsumerProxy
      */
     public OutputConsumerProxy( OutputConsumer outputConsumer )
     {
-        this.setOutputConsumer( outputConsumer );
-    }
-
-    /**
-     * {@link OutputConsumer} that calls will be delegated to
-     *
-     * @param outputConsumer the proxied {@link OutputConsumer}
-     */
-    public void setOutputConsumer( OutputConsumer outputConsumer )
-    {
         this.outputConsumer = outputConsumer;
     }
 

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/PrintWriterOutputConsumer.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/PrintWriterOutputConsumer.java?rev=1030636&r1=1030635&r2=1030636&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/PrintWriterOutputConsumer.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/PrintWriterOutputConsumer.java
Wed Nov  3 19:47:24 2010
@@ -35,14 +35,7 @@ public class PrintWriterOutputConsumer
     implements OutputConsumer
 {
 
-    private PrintWriter printWriter;
-
-    /**
-     * Create a consumer uninitialized, {@link #setPrintWriter(PrintWriter)} must be called
before using it
-     */
-    public PrintWriterOutputConsumer()
-    {
-    }
+    private final PrintWriter printWriter;
 
     /**
      * Create a consumer that will write to the specified {@link Writer}
@@ -51,21 +44,23 @@ public class PrintWriterOutputConsumer
      */
     public PrintWriterOutputConsumer( Writer writer )
     {
-        this.setPrintWriter( new PrintWriter( writer ) );
+        this( new PrintWriter( writer ) );
     }
 
     /**
-     * Set the {@link PrintWriter} used by this object
+     * Create a consumer that will write to the specified {@link Writer}
      *
-     * @param writer
+     * @param writer where to write to
      */
-    public void setPrintWriter( PrintWriter writer )
+    public PrintWriterOutputConsumer( PrintWriter writer )
     {
         this.printWriter = writer;
     }
 
     /**
      * Get the {@link PrintWriter} used by this object
+     *
+     * @return the printWriter
      */
     public PrintWriter getPrintWriter()
     {
@@ -111,7 +106,7 @@ public class PrintWriterOutputConsumer
     /**
      * Write a line and flush
      *
-     * @param line
+     * @param line the content to write
      */
     private void write( String line )
     {

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/StandardOutputConsumer.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/StandardOutputConsumer.java?rev=1030636&r1=1030635&r2=1030636&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/StandardOutputConsumer.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/StandardOutputConsumer.java
Wed Nov  3 19:47:24 2010
@@ -37,7 +37,7 @@ public class StandardOutputConsumer
      */
     public StandardOutputConsumer()
     {
-        setPrintWriter( new PrintWriter( System.out ) );
+        super( new PrintWriter( System.out ) );
     }
 
 }



Mime
View raw message