maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tibordig...@apache.org
Subject [13/17] maven-surefire git commit: Revert "Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/maven-surefire"
Date Sun, 05 Feb 2017 13:55:44 GMT
Revert "Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/maven-surefire"

This reverts commit 780f91393046fd11129cd9ee5bd10ca1d59286f0, reversing
changes made to 4d3673c42e2af75c22f3abbaa2a0237a5c25e0ce.


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/90654a0a
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/90654a0a
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/90654a0a

Branch: refs/heads/SUREFIRE-1322
Commit: 90654a0ae2d5cae286b00badaa039cdaa0e05c4c
Parents: 45457a3
Author: Stephen Connolly <stephen.alan.connolly@gmail.com>
Authored: Mon Jan 23 10:55:35 2017 +0000
Committer: Stephen Connolly <stephen.alan.connolly@gmail.com>
Committed: Mon Jan 23 10:55:35 2017 +0000

----------------------------------------------------------------------
 .../plugin/surefire/SurefireProperties.java     | 28 +++-----
 .../booterclient/ForkConfiguration.java         | 22 +++---
 .../report/ConsoleOutputFileReporter.java       | 26 ++++---
 .../plugin/surefire/report/FileReporter.java    | 75 +++++++-------------
 .../surefire/report/TestSetRunListener.java     | 37 ++++------
 .../surefire/runorder/StatisticsReporter.java   |  7 +-
 .../surefire/util/DependenciesScannerTest.java  |  8 +--
 .../maven/surefire/report/FileReporterTest.java | 10 +--
 .../surefire/report/SurefireReportMojoTest.java |  2 -
 .../runorder/RunEntryStatisticsMap.java         | 58 ++++++---------
 .../surefire/booter/ForkingRunListener.java     | 15 ++--
 .../surefire/booter/MasterProcessCommand.java   |  2 +-
 .../maven/surefire/booter/ForkedBooter.java     | 16 +++--
 .../surefire/booter/SystemPropertyManager.java  | 41 ++---------
 .../maven/surefire/its/fixture/TestFile.java    |  6 +-
 .../src/test/java/it/BasicTest.java             | 20 ++----
 .../src/test/java/runListener/FileHelper.java   |  5 +-
 .../apache/maven/surefire/test/FailingTest.java | 17 +----
 .../maven/surefire/test/SucceedingTest.java     | 17 +----
 .../plugins/surefire/dumppid/DumpPidMojo.java   |  7 +-
 .../src/test/java/listenReport/FileHelper.java  |  4 +-
 .../java/testng/objectfactory/FileHelper.java   |  3 +-
 .../testng/testrunnerfactory/FileHelper.java    | 20 +++---
 23 files changed, 161 insertions(+), 285 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
index 0125aa4..53aa134 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
@@ -19,6 +19,10 @@ package org.apache.maven.plugin.surefire;
  * under the License.
  */
 
+import org.apache.maven.surefire.booter.Classpath;
+import org.apache.maven.surefire.booter.KeyValueSource;
+import org.apache.maven.surefire.util.internal.StringUtils;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -32,10 +36,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+
 import static java.util.Arrays.asList;
-import org.apache.maven.surefire.booter.Classpath;
-import org.apache.maven.surefire.booter.KeyValueSource;
-import org.apache.maven.surefire.util.internal.StringUtils;
+import static org.apache.maven.shared.utils.io.IOUtil.close;
 
 /**
  * A properties implementation that preserves insertion order.
@@ -225,30 +228,15 @@ public class SurefireProperties
     private static SurefireProperties loadProperties( final InputStream inStream )
         throws IOException
     {
-        InputStream in = inStream;
-
         try
         {
             final Properties p = new Properties();
-            p.load( in );
-            in.close();
-            in = null;
+            p.load( inStream );
             return new SurefireProperties( p );
         }
         finally
         {
-            // @todo use try-with-resources JDK7, search in all code
-            try
-            {
-                if ( in != null )
-                {
-                    in.close();
-                }
-            }
-            catch ( final IOException e )
-            {
-                // Suppressed, so that the exception thrown in the try block will be propagated.
-            }
+            close( inStream ); // @todo use try-with-resources JDK7, search in all code
         }
     }
 

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
index f42c8aa..6cb0fab 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
@@ -19,6 +19,16 @@ package org.apache.maven.plugin.surefire.booterclient;
  * under the License.
  */
 
+import org.apache.maven.plugin.surefire.AbstractSurefireMojo;
+import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.OutputStreamFlushableCommandline;
+import org.apache.maven.plugin.surefire.util.Relocator;
+import org.apache.maven.shared.utils.StringUtils;
+import org.apache.maven.shared.utils.io.IOUtil;
+import org.apache.maven.surefire.booter.Classpath;
+import org.apache.maven.surefire.booter.ForkedBooter;
+import org.apache.maven.surefire.booter.StartupConfiguration;
+import org.apache.maven.surefire.booter.SurefireBooterForkException;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -29,15 +39,6 @@ import java.util.Properties;
 import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
-import org.apache.maven.plugin.surefire.AbstractSurefireMojo;
-import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.OutputStreamFlushableCommandline;
-import org.apache.maven.plugin.surefire.util.Relocator;
-import org.apache.maven.shared.utils.StringUtils;
-import org.apache.maven.shared.utils.io.IOUtil;
-import org.apache.maven.surefire.booter.Classpath;
-import org.apache.maven.surefire.booter.ForkedBooter;
-import org.apache.maven.surefire.booter.StartupConfiguration;
-import org.apache.maven.surefire.booter.SurefireBooterForkException;
 
 /**
  * Configuration for forking tests.
@@ -297,9 +298,6 @@ public class ForkConfiguration
             man.getMainAttributes().putValue( "Main-Class", startClassName );
 
             man.write( jos );
-
-            jos.close();
-            jos = null;
         }
         finally
         {

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java
index da08d01..914d684 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java
@@ -22,8 +22,10 @@ package org.apache.maven.plugin.surefire.report;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+
 import org.apache.maven.shared.utils.io.IOUtil;
 import org.apache.maven.surefire.report.ReportEntry;
+
 import static org.apache.maven.plugin.surefire.report.FileReporter.getReportFile;
 
 /**
@@ -64,17 +66,21 @@ public class ConsoleOutputFileReporter
     @SuppressWarnings( "checkstyle:emptyblock" )
     public void close()
     {
-        try
-        {
-            this.fileOutputStream.close();
-        }
-        catch ( final IOException e )
-        {
-            throw new RuntimeException( "Failure closing reporter.", e );
-        }
-        finally
+        if ( fileOutputStream != null )
         {
-            this.fileOutputStream = null;
+            try
+            {
+                fileOutputStream.flush();
+                fileOutputStream.close();
+            }
+            catch ( IOException e )
+            {
+                // do nothing
+            }
+            finally
+            {
+                fileOutputStream = null;
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java
index d7a41af..6239f77 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java
@@ -19,13 +19,14 @@ package org.apache.maven.plugin.surefire.report;
  * under the License.
  */
 
-import java.io.BufferedWriter;
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.ReporterException;
+
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.List;
-import org.apache.maven.surefire.report.ReportEntry;
-import org.apache.maven.surefire.report.ReporterException;
+
 import static org.apache.maven.plugin.surefire.report.FileReporterUtils.stripIllegalFilenameChars;
 import static org.apache.maven.surefire.util.internal.StringUtils.isNotBlank;
 
@@ -47,7 +48,7 @@ public class FileReporter
         this.reportNameSuffix = reportNameSuffix;
     }
 
-    private BufferedWriter testSetStarting( ReportEntry report )
+    private PrintWriter testSetStarting( ReportEntry report )
     {
         File reportFile = getReportFile( reportsDirectory, report.getName(), reportNameSuffix, ".txt" );
 
@@ -56,39 +57,27 @@ public class FileReporter
         // noinspection ResultOfMethodCallIgnored
         reportDir.mkdirs();
 
-        BufferedWriter writer = null;
         try
         {
-            writer = new BufferedWriter( new FileWriter( reportFile ) );
+            /**
+             * The implementation of constructor {@link PrintWriter(File)}
+             * uses {@link java.io.BufferedWriter}
+             * which is guaranteed by Java 1.5 Javadoc of the constructor:
+             * "The output will be written to the file and is buffered."
+             */
+            PrintWriter writer = new PrintWriter( reportFile );
 
-            writer.append( "-------------------------------------------------------------------------------" );
-            writer.newLine();
+            writer.println( "-------------------------------------------------------------------------------" );
 
-            writer.append( "Test set: " + report.getName() );
-            writer.newLine();
+            writer.println( "Test set: " + report.getName() );
 
-            writer.append( "-------------------------------------------------------------------------------" );
-            writer.newLine();
+            writer.println( "-------------------------------------------------------------------------------" );
 
             return writer;
         }
         catch ( IOException e )
         {
-            try
-            {
-                if ( writer != null )
-                {
-                    writer.close();
-                }
-            }
-            catch ( final IOException e1 )
-            {
-                // Suppressed.
-            }
-            finally
-            {
-                throw new ReporterException( "Unable to create file for report: " + e.getMessage(), e );
-            }
+            throw new ReporterException( "Unable to create file for report: " + e.getMessage(), e );
         }
     }
 
@@ -101,37 +90,23 @@ public class FileReporter
     }
 
     public void testSetCompleted( WrappedReportEntry report, TestSetStats testSetStats, List<String> testResults )
-        throws IOException
     {
-        BufferedWriter writer = null;
+        /**
+         * Using buffered stream internally.
+         */
+        PrintWriter writer = testSetStarting( report );
         try
         {
-            writer = testSetStarting( report );
-            writer.append( testSetStats.getTestSetSummary( report ) );
-            writer.newLine();
-
+            writer.println( testSetStats.getTestSetSummary( report ) );
             for ( String testResult : testResults )
             {
-                writer.append( testResult );
-                writer.newLine();
+                writer.println( testResult );
             }
-
-            writer.close();
-            writer = null;
+            writer.flush();
         }
         finally
         {
-            try
-            {
-                if ( writer != null )
-                {
-                    writer.close();
-                }
-            }
-            catch ( final IOException e )
-            {
-                // Suppressed.
-            }
+            writer.close();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
index a9b8f3b..c5a17d3 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
@@ -151,29 +151,22 @@ public class TestSetRunListener
 
     public void testSetCompleted( ReportEntry report )
     {
-        try
-        {
-            final WrappedReportEntry wrap = wrapTestSet( report );
-            final List<String> testResults =
+        final WrappedReportEntry wrap = wrapTestSet( report );
+        final List<String> testResults =
                 briefOrPlainFormat ? detailsForThis.getTestResults() : Collections.<String>emptyList();
-            fileReporter.testSetCompleted( wrap, detailsForThis, testResults );
-            simpleXMLReporter.testSetCompleted( wrap, detailsForThis );
-            statisticsReporter.testSetCompleted();
-            consoleReporter.testSetCompleted( wrap, detailsForThis, testResults );
-            consoleOutputReceiver.testSetCompleted( wrap );
-            consoleReporter.reset();
-
-            wrap.getStdout().free();
-            wrap.getStdErr().free();
-
-            addTestMethodStats();
-            detailsForThis.reset();
-            clearCapture();
-        }
-        catch ( final IOException e )
-        {
-            throw new RuntimeException( "Unexpected IOException.e", e );
-        }
+        fileReporter.testSetCompleted( wrap, detailsForThis, testResults );
+        simpleXMLReporter.testSetCompleted( wrap, detailsForThis );
+        statisticsReporter.testSetCompleted();
+        consoleReporter.testSetCompleted( wrap, detailsForThis, testResults );
+        consoleOutputReceiver.testSetCompleted( wrap );
+        consoleReporter.reset();
+
+        wrap.getStdout().free();
+        wrap.getStdErr().free();
+
+        addTestMethodStats();
+        detailsForThis.reset();
+        clearCapture();
     }
 
     // ----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java
index ee3421e..3f78939 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java
@@ -19,10 +19,11 @@ package org.apache.maven.plugin.surefire.runorder;
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
 import org.apache.maven.surefire.report.ReportEntry;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+
 import static org.apache.maven.plugin.surefire.runorder.RunEntryStatisticsMap.fromFile;
 
 /**
@@ -54,7 +55,7 @@ public class StatisticsReporter
         {
             newResults.serialize( dataFile );
         }
-        catch ( IOException e )
+        catch ( FileNotFoundException e )
         {
             throw new RuntimeException( e );
         }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DependenciesScannerTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DependenciesScannerTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DependenciesScannerTest.java
index a223a0d..c8dd436 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DependenciesScannerTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DependenciesScannerTest.java
@@ -75,10 +75,9 @@ public class DependenciesScannerTest
         File output = new File( "target/DependenciesScannerTest-tests.jar" );
         output.delete();
 
-        ZipOutputStream out = null;
+        ZipOutputStream out = new ZipOutputStream( new FileOutputStream( output ) );
         try
         {
-            out = new ZipOutputStream( new FileOutputStream( output ) );
             out.putNextEntry( new ZipEntry( "org/test/TestA.class" ) );
             out.closeEntry();
             out.putNextEntry( new ZipEntry( "org/test/TestB.class" ) );
@@ -87,10 +86,7 @@ public class DependenciesScannerTest
         }
         finally
         {
-            if ( out != null )
-            {
-                out.close();
-            }
+            out.close();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java b/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java
index f8a92d8..076b23c 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java
@@ -19,15 +19,15 @@ package org.apache.maven.surefire.report;
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
 import junit.framework.TestCase;
 import org.apache.maven.plugin.surefire.report.FileReporter;
 import org.apache.maven.plugin.surefire.report.ReportEntryType;
 import org.apache.maven.plugin.surefire.report.TestSetStats;
 import org.apache.maven.plugin.surefire.report.WrappedReportEntry;
 
+import java.io.File;
+import java.util.ArrayList;
+
 public class FileReporterTest
     extends TestCase
 {
@@ -38,7 +38,7 @@ public class FileReporterTest
 
     private static final String testName = "org.apache.maven.surefire.report.FileReporterTest";
 
-    public void testFileNameWithoutSuffix() throws IOException
+    public void testFileNameWithoutSuffix()
     {
         File reportDir = new File( "target" );
         reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
@@ -58,7 +58,7 @@ public class FileReporterTest
         return new TestSetStats( true, true );
     }
 
-    public void testFileNameWithSuffix() throws IOException
+    public void testFileNameWithSuffix()
     {
         File reportDir = new File( "target" );
         String suffixText = "sampleSuffixText";

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportMojoTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportMojoTest.java b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportMojoTest.java
index 8532b1b..724e72d 100644
--- a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportMojoTest.java
+++ b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportMojoTest.java
@@ -640,8 +640,6 @@ public class SurefireReportMojoTest
             writer = WriterFactory.newXmlWriter( outputHtml );
             // renderer doxia 1.6 already closed the writer
             renderer.generateDocument( writer, (SiteRendererSink) mojo.getSink(), context );
-            writer.close();
-            writer = null;
         }
         finally
         {

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-api/src/main/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMap.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/main/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMap.java b/surefire-api/src/main/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMap.java
index 2e9c133..eab2a81 100644
--- a/surefire-api/src/main/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMap.java
+++ b/surefire-api/src/main/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMap.java
@@ -20,12 +20,15 @@ package org.apache.maven.plugin.surefire.runorder;
  */
 
 
+import org.apache.maven.shared.utils.io.IOUtil;
+import org.apache.maven.surefire.report.ReportEntry;
+
 import java.io.BufferedReader;
-import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
 import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Comparator;
@@ -35,9 +38,8 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+
 import static java.util.Collections.sort;
-import org.apache.maven.shared.utils.io.IOUtil;
-import org.apache.maven.surefire.report.ReportEntry;
 import static org.apache.maven.plugin.surefire.runorder.RunEntryStatistics.fromReportEntry;
 import static org.apache.maven.plugin.surefire.runorder.RunEntryStatistics.fromString;
 
@@ -66,10 +68,7 @@ public final class RunEntryStatisticsMap
             try
             {
                 reader = new FileReader( file );
-                final RunEntryStatisticsMap result = fromReader( reader );
-                reader.close();
-                reader = null;
-                return result;
+                return fromReader( reader );
             }
             catch ( IOException e )
             {
@@ -89,50 +88,39 @@ public final class RunEntryStatisticsMap
     static RunEntryStatisticsMap fromReader( Reader fileReader )
         throws IOException
     {
-        BufferedReader reader = null;
         Map<String, RunEntryStatistics> result = new HashMap<String, RunEntryStatistics>();
-        try
+        BufferedReader reader = new BufferedReader( fileReader );
+        for ( String line = reader.readLine(); line != null && !line.startsWith( "#" ); line = reader.readLine() )
         {
-            reader = new BufferedReader( fileReader );
-            for ( String line = reader.readLine(); line != null; line = reader.readLine() )
-            {
-                if ( !line.startsWith( "#" ) )
-                {
-                    RunEntryStatistics stats = fromString( line );
-                    result.put( stats.getTestName(), stats );
-                }
-            }
-            reader.close();
-            reader = null;
-            return new RunEntryStatisticsMap( result );
-        }
-        finally
-        {
-            IOUtil.close( reader );
+            RunEntryStatistics stats = fromString( line );
+            result.put( stats.getTestName(), stats );
         }
+        return new RunEntryStatisticsMap( result );
     }
 
     public void serialize( File file )
-        throws IOException
+        throws FileNotFoundException
     {
-        BufferedWriter writer = null;
+        /**
+         * The implementation of constructor {@link PrintWriter(File)}
+         * uses {@link java.io.BufferedWriter}
+         * which is guaranteed by Java 1.5 Javadoc of the constructor:
+         * "The output will be written to the file and is buffered."
+         */
+        PrintWriter printWriter = new PrintWriter( file );
         try
         {
-            writer = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( file ) ) );
             List<RunEntryStatistics> items = new ArrayList<RunEntryStatistics>( runEntryStatistics.values() );
             sort( items, new RunCountComparator() );
             for ( RunEntryStatistics item : items )
             {
-                writer.append( item.toString() );
-                writer.newLine();
+                printWriter.println( item.toString() );
             }
-
-            writer.close();
-            writer = null;
+            printWriter.flush();
         }
         finally
         {
-            IOUtil.close( writer );
+            printWriter.close();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
index 7439ec3..aa0dadd 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
@@ -19,11 +19,6 @@ package org.apache.maven.surefire.booter;
  * under the License.
  */
 
-import java.io.PrintStream;
-import java.util.Enumeration;
-import java.util.Properties;
-import static java.lang.Integer.toHexString;
-import static java.nio.charset.Charset.defaultCharset;
 import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
 import org.apache.maven.plugin.surefire.log.api.ConsoleLoggerUtils;
 import org.apache.maven.surefire.report.ConsoleOutputReceiver;
@@ -33,6 +28,13 @@ import org.apache.maven.surefire.report.RunListener;
 import org.apache.maven.surefire.report.SafeThrowable;
 import org.apache.maven.surefire.report.SimpleReportEntry;
 import org.apache.maven.surefire.report.StackTraceWriter;
+
+import java.io.PrintStream;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import static java.lang.Integer.toHexString;
+import static java.nio.charset.Charset.defaultCharset;
 import static org.apache.maven.surefire.util.internal.StringUtils.encodeStringForForkCommunication;
 import static org.apache.maven.surefire.util.internal.StringUtils.escapeBytesToPrintable;
 import static org.apache.maven.surefire.util.internal.StringUtils.escapeToPrintable;
@@ -209,8 +211,7 @@ public class ForkingRunListener
                 // We MUST NOT throw any exception from this method; otherwise we are in loop and CPU goes up:
                 // ForkingRunListener -> Exception -> JUnit Notifier and RunListener -> ForkingRunListener -> Exception
                 DumpErrorSingleton.getSingleton()
-                    .dumpStreamText( "Unexpected IOException with stream: " + new String( buf, off, len ) );
-
+                        .dumpStreamText( "Unexpected IOException with stream: " + new String( buf, off, len ) );
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java
index d5f6375..0bd7b89 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java
@@ -23,8 +23,8 @@ import java.io.DataInputStream;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
+
 import static java.lang.String.format;
-import org.apache.maven.surefire.util.internal.StringUtils;
 import static org.apache.maven.surefire.util.internal.ObjectUtils.requireNonNull;
 import static org.apache.maven.surefire.util.internal.StringUtils.FORK_STREAM_CHARSET_NAME;
 import static org.apache.maven.surefire.util.internal.StringUtils.encodeStringForForkCommunication;

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
index 6df3009..b76df2f 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
@@ -19,6 +19,14 @@ package org.apache.maven.surefire.booter;
  * under the License.
  */
 
+import org.apache.maven.surefire.providerapi.ProviderParameters;
+import org.apache.maven.surefire.providerapi.SurefireProvider;
+import org.apache.maven.surefire.report.LegacyPojoStackTraceWriter;
+import org.apache.maven.surefire.report.ReporterFactory;
+import org.apache.maven.surefire.report.StackTraceWriter;
+import org.apache.maven.surefire.suite.RunResult;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -30,19 +38,13 @@ import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.atomic.AtomicBoolean;
+
 import static java.lang.System.err;
 import static java.lang.System.out;
 import static java.lang.System.setErr;
 import static java.lang.System.setOut;
 import static java.lang.Thread.currentThread;
 import static java.util.concurrent.TimeUnit.SECONDS;
-import org.apache.maven.surefire.providerapi.ProviderParameters;
-import org.apache.maven.surefire.providerapi.SurefireProvider;
-import org.apache.maven.surefire.report.LegacyPojoStackTraceWriter;
-import org.apache.maven.surefire.report.ReporterFactory;
-import org.apache.maven.surefire.report.StackTraceWriter;
-import org.apache.maven.surefire.suite.RunResult;
-import org.apache.maven.surefire.testset.TestSetFailedException;
 import static org.apache.maven.surefire.booter.CommandReader.getReader;
 import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_BYE;
 import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_ERROR;

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
index 8d301dc..a80656e 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
@@ -24,7 +24,6 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
@@ -49,8 +48,6 @@ public class SystemPropertyManager
         {
             Properties p = new Properties();
             p.load( inStream );
-            inStream.close();
-            inStream = null;
             Map<String, String> map = new ConcurrentHashMap<String, String>( p.size() );
             // @todo use .stringPropertyNames() JDK6 instead of .keySet()
             for ( Map.Entry<?, ?> entry : p.entrySet() )
@@ -61,18 +58,7 @@ public class SystemPropertyManager
         }
         finally
         {
-            // @todo use try-with-resources JDK7, search in all code
-            try
-            {
-                if ( inStream != null )
-                {
-                    inStream.close();
-                }
-            }
-            catch ( final IOException e1 )
-            {
-                // Suppressed, so that the exception thrown in the try block will be propagated.
-            }
+            close( inStream ); // @todo use try-with-resources JDK7, search in all code
         }
     }
 
@@ -107,34 +93,21 @@ public class SystemPropertyManager
     public static void writePropertiesFile( File file, String name, Properties properties )
         throws IOException
     {
-        OutputStream out = null;
+        FileOutputStream out = new FileOutputStream( file );
+
         try
         {
-            out = new FileOutputStream( file );
+            /**
+             * See {@link Properties#store(java.io.OutputStream, String)} Javadoc - stream is flushed.
+             */
             properties.store( out, name );
-            out.close();
-            out = null;
         }
         finally
         {
-            try
-            {
-                if ( out != null )
-                {
-                    out.close();
-                }
-            }
-            catch ( final IOException e1 )
-            {
-                // Suppressed.
-            }
+            out.close();
         }
     }
 
-    /**
-     * @deprecated As of Java 7, please use the try-with-resources statement.
-     */
-    @Deprecated
     public static void close( InputStream inputStream )
     {
         if ( inputStream == null )

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/TestFile.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/TestFile.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/TestFile.java
index eb33e78..6d3d8e2 100644
--- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/TestFile.java
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/TestFile.java
@@ -28,8 +28,10 @@ import java.io.IOException;
 import java.net.URI;
 import java.nio.charset.Charset;
 import java.util.List;
-import junit.framework.Assert;
 import org.apache.commons.io.FileUtils;
+
+import junit.framework.Assert;
+
 import static junit.framework.Assert.assertTrue;
 
 /**
@@ -101,8 +103,6 @@ public class TestFile
             {
                 sb.append( line );
             }
-            reader.close();
-            reader = null;
             return sb.toString();
         }
         catch ( IOException e )

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-integration-tests/src/test/resources/classpath-order/src/test/java/it/BasicTest.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/classpath-order/src/test/java/it/BasicTest.java b/surefire-integration-tests/src/test/resources/classpath-order/src/test/java/it/BasicTest.java
index e595cd6..f46e3be 100644
--- a/surefire-integration-tests/src/test/resources/classpath-order/src/test/java/it/BasicTest.java
+++ b/surefire-integration-tests/src/test/resources/classpath-order/src/test/java/it/BasicTest.java
@@ -44,17 +44,14 @@ public class BasicTest
     }
 
     private Properties getProperties( String resource )
-        throws IOException
+            throws IOException
     {
-        InputStream in = null;
+        InputStream in = getClass().getResourceAsStream( resource );
+        assertNotNull( in );
         try
         {
-            in = getClass().getResourceAsStream( resource );
-            assertNotNull( in );
             Properties props = new Properties();
             props.load( in );
-            in.close();
-            in = null;
             return props;
         }
         catch ( IOException e )
@@ -64,16 +61,9 @@ public class BasicTest
         }
         finally
         {
-            try
-            {
-                if ( in != null )
-                {
-                    in.close();
-                }
-            }
-            catch ( final IOException e )
+            if ( in != null )
             {
-                // Suppressed.
+                in.close();
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java b/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java
index c842a1d..0112f31 100644
--- a/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java
+++ b/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java
@@ -33,8 +33,7 @@ public class FileHelper
         {
             writer = new FileWriter( new File( new File( "target" ).getAbsoluteFile(), fileName ) );
             writer.write( content );
-            writer.close();
-            writer = null;
+            writer.flush();
         }
         catch ( IOException e )
         {
@@ -51,7 +50,7 @@ public class FileHelper
             }
             catch ( final IOException e )
             {
-                // Suppressed, so that the exception thrown in the try block will be propagated.
+                // Suppressed.
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-integration-tests/src/test/resources/surefire-803-multiFailsafeExec-failureInFirst/src/test/java/org/apache/maven/surefire/test/FailingTest.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-803-multiFailsafeExec-failureInFirst/src/test/java/org/apache/maven/surefire/test/FailingTest.java b/surefire-integration-tests/src/test/resources/surefire-803-multiFailsafeExec-failureInFirst/src/test/java/org/apache/maven/surefire/test/FailingTest.java
index 30224e1..dc651e7 100644
--- a/surefire-integration-tests/src/test/resources/surefire-803-multiFailsafeExec-failureInFirst/src/test/java/org/apache/maven/surefire/test/FailingTest.java
+++ b/surefire-integration-tests/src/test/resources/surefire-803-multiFailsafeExec-failureInFirst/src/test/java/org/apache/maven/surefire/test/FailingTest.java
@@ -60,27 +60,14 @@ public class FailingTest
         final File f = new File( "target/tests-run", getClass().getName() + ".txt" );
         f.getParentFile().mkdirs();
 
-        FileWriter w = null;
+        FileWriter w = new FileWriter( f, true );
         try
         {
-            w = new FileWriter( f, true );
             w.write( name.getMethodName() );
-            w.close();
-            w = null;
         }
         finally
         {
-            if ( w != null )
-            {
-                try
-                {
-                    w.close();
-                }
-                catch ( final IOException e )
-                {
-                    // Suppressed.
-                }
-            }
+            w.close();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-integration-tests/src/test/resources/surefire-803-multiFailsafeExec-failureInFirst/src/test/java/org/apache/maven/surefire/test/SucceedingTest.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-803-multiFailsafeExec-failureInFirst/src/test/java/org/apache/maven/surefire/test/SucceedingTest.java b/surefire-integration-tests/src/test/resources/surefire-803-multiFailsafeExec-failureInFirst/src/test/java/org/apache/maven/surefire/test/SucceedingTest.java
index 2ed21eb..f924074 100644
--- a/surefire-integration-tests/src/test/resources/surefire-803-multiFailsafeExec-failureInFirst/src/test/java/org/apache/maven/surefire/test/SucceedingTest.java
+++ b/surefire-integration-tests/src/test/resources/surefire-803-multiFailsafeExec-failureInFirst/src/test/java/org/apache/maven/surefire/test/SucceedingTest.java
@@ -60,28 +60,15 @@ public class SucceedingTest
         final File f = new File( "target/tests-run", getClass().getName() + ".txt" );
         f.getParentFile().mkdirs();
 
-        FileWriter w = null;
+        FileWriter w = new FileWriter( f, true );
 
         try
         {
-            w = new FileWriter( f, true );
             w.write( name.getMethodName() );
-            w.close();
-            w = null;
         }
         finally
         {
-            if ( w != null )
-            {
-                try
-                {
-                    w.close();
-                }
-                catch ( final IOException e )
-                {
-                    // Suppressed.
-                }
-            }
+            w.close();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-integration-tests/src/test/resources/test-helper-dump-pid-plugin/src/main/java/org/apache/maven/plugins/surefire/dumppid/DumpPidMojo.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/test-helper-dump-pid-plugin/src/main/java/org/apache/maven/plugins/surefire/dumppid/DumpPidMojo.java b/surefire-integration-tests/src/test/resources/test-helper-dump-pid-plugin/src/main/java/org/apache/maven/plugins/surefire/dumppid/DumpPidMojo.java
index b010d22..aa44b64 100644
--- a/surefire-integration-tests/src/test/resources/test-helper-dump-pid-plugin/src/main/java/org/apache/maven/plugins/surefire/dumppid/DumpPidMojo.java
+++ b/surefire-integration-tests/src/test/resources/test-helper-dump-pid-plugin/src/main/java/org/apache/maven/plugins/surefire/dumppid/DumpPidMojo.java
@@ -51,12 +51,11 @@ public class DumpPidMojo
             {
                 targetDir.mkdirs();
             }
-
             fw = new FileWriter( target );
-            final String pid = ManagementFactory.getRuntimeMXBean().getName();
+            String pid = ManagementFactory.getRuntimeMXBean().getName();
             fw.write( pid );
-            fw.close();
-            fw = null;
+            fw.flush();
+
             getLog().info( "Wrote " + pid + " to " + target );
         }
         catch ( IOException e )

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-integration-tests/src/test/resources/testng-listener-reporter/src/test/java/listenReport/FileHelper.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/testng-listener-reporter/src/test/java/listenReport/FileHelper.java b/surefire-integration-tests/src/test/resources/testng-listener-reporter/src/test/java/listenReport/FileHelper.java
index 4405996..031b1fa 100644
--- a/surefire-integration-tests/src/test/resources/testng-listener-reporter/src/test/java/listenReport/FileHelper.java
+++ b/surefire-integration-tests/src/test/resources/testng-listener-reporter/src/test/java/listenReport/FileHelper.java
@@ -33,8 +33,6 @@ public class FileHelper
         {
             writer = new FileWriter( new File( new File( "target" ).getAbsoluteFile(), fileName ) );
             writer.write( content );
-            writer.close();
-            writer = null;
         }
         catch ( IOException e )
         {
@@ -51,7 +49,7 @@ public class FileHelper
             }
             catch ( final IOException e )
             {
-                // Suppressed.
+                throw new RuntimeException( e );
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-integration-tests/src/test/resources/testng-objectFactory/src/test/java/testng/objectfactory/FileHelper.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/testng-objectFactory/src/test/java/testng/objectfactory/FileHelper.java b/surefire-integration-tests/src/test/resources/testng-objectFactory/src/test/java/testng/objectfactory/FileHelper.java
index 4525e29..7e2e820 100644
--- a/surefire-integration-tests/src/test/resources/testng-objectFactory/src/test/java/testng/objectfactory/FileHelper.java
+++ b/surefire-integration-tests/src/test/resources/testng-objectFactory/src/test/java/testng/objectfactory/FileHelper.java
@@ -16,8 +16,7 @@ public class FileHelper
                                                          "target" ).getCanonicalFile(), fileName ), true );
 
             writer.write( content );
-            writer.close();
-            writer = null;
+            writer.flush();
         }
         catch ( IOException exception )
         {

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/90654a0a/surefire-integration-tests/src/test/resources/testng-testRunnerFactory/src/test/java/testng/testrunnerfactory/FileHelper.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/testng-testRunnerFactory/src/test/java/testng/testrunnerfactory/FileHelper.java b/surefire-integration-tests/src/test/resources/testng-testRunnerFactory/src/test/java/testng/testrunnerfactory/FileHelper.java
index b0a8e92..5451dbf 100644
--- a/surefire-integration-tests/src/test/resources/testng-testRunnerFactory/src/test/java/testng/testrunnerfactory/FileHelper.java
+++ b/surefire-integration-tests/src/test/resources/testng-testRunnerFactory/src/test/java/testng/testrunnerfactory/FileHelper.java
@@ -3,21 +3,19 @@ package testng.testrunnerfactory;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.io.Writer;
 
 public class FileHelper
 {
     public static void writeFile( String fileName, String content )
     {
-        Writer writer = null;
+        FileWriter out = null;
         try
         {
-            writer = new FileWriter( new File( new File( System.getProperty( "user.dir" ),
-                                                         "target" ).getCanonicalFile(), fileName ), true );
-
-            writer.write( content );
-            writer.close();
-            writer = null;
+            File target = new File( System.getProperty("user.dir"), "target" ).getCanonicalFile();
+            File listenerOutput = new File( target, fileName );
+            out = new FileWriter( listenerOutput, true );
+            out.write( content );
+            out.flush();
         }
         catch ( IOException e )
         {
@@ -25,15 +23,15 @@ public class FileHelper
         }
         finally
         {
-            if ( writer != null )
+            if ( out != null )
             {
                 try
                 {
-                    writer.close();
+                    out.close();
                 }
                 catch ( IOException e )
                 {
-                    // Suppressed, so that the exception thrown in the try block will be propagated.
+                    throw new RuntimeException( e );
                 }
             }
         }


Mime
View raw message