You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sc...@apache.org on 2017/01/07 23:38:42 UTC
[1/4] maven-surefire git commit: [SUREFIRE-1324] Surefire incorrectly
suppresses exceptions when closing resources.
Repository: maven-surefire
Updated Branches:
refs/heads/master 4d3673c42 -> 780f91393
[SUREFIRE-1324] Surefire incorrectly suppresses exceptions when closing resources.
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/e5a6b9c8
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/e5a6b9c8
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/e5a6b9c8
Branch: refs/heads/master
Commit: e5a6b9c8d4f514100a01dea2acf1fb059e294968
Parents: 66bc4c0
Author: Christian Schulte <sc...@apache.org>
Authored: Mon Jan 2 00:54:07 2017 +0100
Committer: Christian Schulte <sc...@apache.org>
Committed: Mon Jan 2 02:21:25 2017 +0100
----------------------------------------------------------------------
.../plugin/surefire/SurefireProperties.java | 41 ++++++------
.../booterclient/ForkConfiguration.java | 27 ++++----
.../report/ConsoleOutputFileReporter.java | 15 ++++-
.../plugin/surefire/report/FileReporter.java | 65 +++++++++++++++-----
.../surefire/report/TestSetRunListener.java | 37 ++++++-----
.../surefire/runorder/StatisticsReporter.java | 4 +-
.../surefire/util/DependenciesScannerTest.java | 8 ++-
.../maven/surefire/report/FileReporterTest.java | 5 +-
.../surefire/report/SurefireReportMojoTest.java | 2 +
surefire-api/pom.xml | 4 ++
.../runorder/RunEntryStatisticsMap.java | 30 ++++++---
.../surefire/booter/ForkingRunListener.java | 8 +++
.../surefire/booter/MasterProcessCommand.java | 5 +-
.../surefire/booter/SystemPropertyManager.java | 21 ++++++-
.../maven/surefire/its/fixture/TestFile.java | 18 +++++-
.../src/test/java/it/BasicTest.java | 31 +++++++---
.../src/test/java/runListener/FileHelper.java | 26 ++++++--
.../apache/maven/surefire/test/FailingTest.java | 4 +-
.../maven/surefire/test/SucceedingTest.java | 3 +
.../plugins/surefire/dumppid/DumpPidMojo.java | 30 ++++++---
.../src/test/java/listenReport/FileHelper.java | 30 ++++++---
.../java/testng/objectfactory/FileHelper.java | 28 +++++++--
.../testng/testrunnerfactory/FileHelper.java | 28 +++++++--
23 files changed, 341 insertions(+), 129 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 3663f39..2e3aa58 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
@@ -32,13 +32,11 @@ 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 java.util.Arrays.asList;
-
/**
* A properties implementation that preserves insertion order.
*/
@@ -46,6 +44,7 @@ public class SurefireProperties
extends Properties
implements KeyValueSource
{
+
private static final Collection<String> KEYS_THAT_CANNOT_BE_USED_AS_SYSTEM_PROPERTIES =
asList( "java.library.path", "file.encoding", "jdk.map.althashing.threshold", "line.separator" );
@@ -153,7 +152,6 @@ public class SurefireProperties
// user specified properties for SUREFIRE-121, causing SUREFIRE-491.
// Not gonna do THAT any more... instead, we only propagate those system properties
// that have been explicitly specified by the user via -Dkey=value on the CLI
-
result.copyPropertiesFrom( userProperties );
return result;
}
@@ -224,18 +222,32 @@ public class SurefireProperties
}
}
- private static SurefireProperties loadProperties( InputStream inStream )
+ private static SurefireProperties loadProperties( final InputStream inStream )
throws IOException
{
+ InputStream in = inStream;
+
try
{
- Properties p = new Properties();
- p.load( inStream );
+ final Properties p = new Properties();
+ p.load( in );
+ in.close();
+ in = null;
return new SurefireProperties( p );
}
finally
{
- close( inStream );
+ try
+ {
+ if ( in != null )
+ {
+ in.close();
+ }
+ }
+ catch ( final IOException e )
+ {
+ // Suppressed.
+ }
}
}
@@ -245,18 +257,6 @@ public class SurefireProperties
return file == null ? new SurefireProperties() : loadProperties( new FileInputStream( file ) );
}
- private static void close( InputStream inputStream )
- {
- try
- {
- inputStream.close();
- }
- catch ( IOException ex )
- {
- // ignore
- }
- }
-
public void setNullableProperty( String key, String value )
{
if ( value != null )
@@ -264,4 +264,5 @@ public class SurefireProperties
super.setProperty( key, value );
}
}
+
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 988af8f..f42c8aa 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,15 +19,6 @@ 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.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;
@@ -38,6 +29,15 @@ 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.
@@ -270,10 +270,10 @@ public class ForkConfiguration
{
file.deleteOnExit();
}
- FileOutputStream fos = new FileOutputStream( file );
- JarOutputStream jos = new JarOutputStream( fos );
+ JarOutputStream jos = null;
try
{
+ jos = new JarOutputStream( new FileOutputStream( file ) );
jos.setLevel( JarOutputStream.STORED );
JarEntry je = new JarEntry( "META-INF/MANIFEST.MF" );
jos.putNextEntry( je );
@@ -297,10 +297,13 @@ public class ForkConfiguration
man.getMainAttributes().putValue( "Main-Class", startClassName );
man.write( jos );
+
+ jos.close();
+ jos = null;
}
finally
{
- jos.close();
+ IOUtil.close( jos );
}
return file;
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 f9e59fe..552c12a 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
@@ -69,13 +69,15 @@ public class ConsoleOutputFileReporter
{
try
{
- fileOutputStream.flush();
fileOutputStream.close();
}
catch ( IOException e )
{
}
- fileOutputStream = null;
+ finally
+ {
+ fileOutputStream = null;
+ }
}
}
@@ -97,6 +99,15 @@ public class ConsoleOutputFileReporter
}
catch ( IOException e )
{
+ try
+ {
+ fileOutputStream.close();
+ // Intentionally no setting to null.
+ }
+ catch ( final IOException e1 )
+ {
+ // Suppressed.
+ }
throw new RuntimeException( e );
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 a4d8c8e..d7a41af 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,15 +19,13 @@ package org.apache.maven.plugin.surefire.report;
* under the License.
*/
-import org.apache.maven.surefire.report.ReportEntry;
-import org.apache.maven.surefire.report.ReporterException;
-
+import java.io.BufferedWriter;
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;
@@ -49,7 +47,7 @@ public class FileReporter
this.reportNameSuffix = reportNameSuffix;
}
- private PrintWriter testSetStarting( ReportEntry report )
+ private BufferedWriter testSetStarting( ReportEntry report )
{
File reportFile = getReportFile( reportsDirectory, report.getName(), reportNameSuffix, ".txt" );
@@ -58,21 +56,39 @@ public class FileReporter
// noinspection ResultOfMethodCallIgnored
reportDir.mkdirs();
+ BufferedWriter writer = null;
try
{
- PrintWriter writer = new PrintWriter( new FileWriter( reportFile ) );
+ writer = new BufferedWriter( new FileWriter( reportFile ) );
- writer.println( "-------------------------------------------------------------------------------" );
+ writer.append( "-------------------------------------------------------------------------------" );
+ writer.newLine();
- writer.println( "Test set: " + report.getName() );
+ writer.append( "Test set: " + report.getName() );
+ writer.newLine();
- writer.println( "-------------------------------------------------------------------------------" );
+ writer.append( "-------------------------------------------------------------------------------" );
+ writer.newLine();
return writer;
}
catch ( IOException e )
{
- throw new ReporterException( "Unable to create file for report: " + e.getMessage(), 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 );
+ }
}
}
@@ -85,20 +101,37 @@ public class FileReporter
}
public void testSetCompleted( WrappedReportEntry report, TestSetStats testSetStats, List<String> testResults )
+ throws IOException
{
- PrintWriter writer = testSetStarting( report );
+ BufferedWriter writer = null;
try
{
- writer.println( testSetStats.getTestSetSummary( report ) );
+ writer = testSetStarting( report );
+ writer.append( testSetStats.getTestSetSummary( report ) );
+ writer.newLine();
+
for ( String testResult : testResults )
{
- writer.println( testResult );
+ writer.append( testResult );
+ writer.newLine();
}
- writer.flush();
+
+ writer.close();
+ writer = null;
}
finally
{
- writer.close();
+ try
+ {
+ if ( writer != null )
+ {
+ writer.close();
+ }
+ }
+ catch ( final IOException e )
+ {
+ // Suppressed.
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 f0f996d..0643896 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,22 +151,29 @@ public class TestSetRunListener
public void testSetCompleted( ReportEntry report )
{
- final WrappedReportEntry wrap = wrapTestSet( report );
- final List<String> testResults =
+ try
+ {
+ 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();
+ 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 );
+ }
}
// ----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 a53db02..bf4523e 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
@@ -20,7 +20,7 @@ package org.apache.maven.plugin.surefire.runorder;
*/
import java.io.File;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import org.apache.maven.surefire.report.ReportEntry;
import static org.apache.maven.plugin.surefire.runorder.RunEntryStatisticsMap.fromFile;
@@ -54,7 +54,7 @@ public class StatisticsReporter
{
newResults.serialize( dataFile );
}
- catch ( FileNotFoundException e )
+ catch ( IOException e )
{
throw new RuntimeException( e );
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 c8dd436..a223a0d 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,9 +75,10 @@ public class DependenciesScannerTest
File output = new File( "target/DependenciesScannerTest-tests.jar" );
output.delete();
- ZipOutputStream out = new ZipOutputStream( new FileOutputStream( output ) );
+ ZipOutputStream out = null;
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" ) );
@@ -86,7 +87,10 @@ public class DependenciesScannerTest
}
finally
{
- out.close();
+ if ( out != null )
+ {
+ out.close();
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 7c49547..87d4b0c 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
@@ -20,6 +20,7 @@ package org.apache.maven.surefire.report;
*/
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import org.apache.maven.plugin.surefire.report.FileReporter;
import org.apache.maven.plugin.surefire.report.ReportEntryType;
@@ -38,7 +39,7 @@ public class FileReporterTest
private static final String testName = "org.apache.maven.surefire.report.FileReporterTest";
- public void testFileNameWithoutSuffix()
+ public void testFileNameWithoutSuffix() throws IOException
{
File reportDir = new File( "target" );
reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
@@ -58,7 +59,7 @@ public class FileReporterTest
return new TestSetStats( true, true );
}
- public void testFileNameWithSuffix()
+ public void testFileNameWithSuffix() throws IOException
{
File reportDir = new File( "target" );
String suffixText = "sampleSuffixText";
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 f138d8a..9fca007 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,6 +640,8 @@ public class SurefireReportMojoTest
writer = WriterFactory.newXmlWriter( outputHtml );
renderer.generateDocument( writer, (SiteRendererSink) mojo.getSink(), context );
+ writer.close();
+ writer = null;
}
finally
{
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/surefire-api/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-api/pom.xml b/surefire-api/pom.xml
index a35f983..2583972 100644
--- a/surefire-api/pom.xml
+++ b/surefire-api/pom.xml
@@ -33,6 +33,10 @@
<dependencies>
<dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-logger-api</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 d47e803..a66e797 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
@@ -23,12 +23,13 @@ package org.apache.maven.plugin.surefire.runorder;
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.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
-import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Comparator;
@@ -40,6 +41,7 @@ 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 static org.apache.maven.plugin.surefire.runorder.RunEntryStatistics.fromReportEntry;
import static org.apache.maven.plugin.surefire.runorder.RunEntryStatistics.fromString;
@@ -64,9 +66,14 @@ public final class RunEntryStatisticsMap
{
if ( file.exists() )
{
+ Reader reader = null;
try
{
- return fromReader( new FileReader( file ) );
+ reader = new FileReader( file );
+ final RunEntryStatisticsMap result = fromReader( reader );
+ reader.close();
+ reader = null;
+ return result;
}
catch ( FileNotFoundException e )
{
@@ -76,6 +83,10 @@ public final class RunEntryStatisticsMap
{
throw new RuntimeException( e );
}
+ finally
+ {
+ IOUtil.close( reader );
+ }
}
else
{
@@ -102,23 +113,26 @@ public final class RunEntryStatisticsMap
}
public void serialize( File file )
- throws FileNotFoundException
+ throws IOException
{
- FileOutputStream fos = new FileOutputStream( file );
- PrintWriter printWriter = new PrintWriter( fos );
+ BufferedWriter writer = null;
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 )
{
- printWriter.println( item.toString() );
+ writer.append( item.toString() );
+ writer.newLine();
}
- printWriter.flush();
+
+ writer.close();
+ writer = null;
}
finally
{
- printWriter.close();
+ IOUtil.close( writer );
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 282c4d4..4558aba 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
@@ -206,6 +206,10 @@ public class ForkingRunListener
synchronized ( target ) // See notes about synchronization/thread safety in class javadoc
{
target.write( encodeBytes, 0, encodeBytes.length );
+ if ( target.checkError() )
+ {
+ throw new RuntimeException( "Unexpected IOException." );
+ }
}
}
@@ -268,6 +272,10 @@ public class ForkingRunListener
synchronized ( target ) // See notes about synchronization/thread safety in class javadoc
{
target.write( encodeBytes, 0, encodeBytes.length );
+ if ( target.checkError() )
+ {
+ throw new RuntimeException( "Unexpected IOException." );
+ }
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 a53a046..d2d1673 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
@@ -124,14 +124,15 @@ public enum MasterProcessCommand
int dataLength = is.readInt();
if ( dataLength > 0 )
{
- byte[] buffer = new byte[dataLength];
+ byte[] buffer = new byte[ dataLength ];
int read = 0;
int total = 0;
do
{
total += read;
read = is.read( buffer, total, dataLength - total );
- } while ( read > 0 );
+ }
+ while ( total < dataLength && read >= 0 );
if ( command.getDataType() == Void.class )
{
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 713d4fe..4046b7b 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,6 +24,7 @@ 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;
@@ -48,6 +49,8 @@ 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() )
@@ -93,15 +96,27 @@ public class SystemPropertyManager
public static void writePropertiesFile( File file, String name, Properties properties )
throws IOException
{
- FileOutputStream out = new FileOutputStream( file );
-
+ OutputStream out = null;
try
{
+ out = new FileOutputStream( file );
properties.store( out, name );
+ out.close();
+ out = null;
}
finally
{
- out.close();
+ try
+ {
+ if ( out != null )
+ {
+ out.close();
+ }
+ }
+ catch ( final IOException e1 )
+ {
+ // Suppressed.
+ }
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 61736df..a2f021f 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
@@ -94,23 +94,37 @@ public class TestFile
public String slurpFile()
{
+ BufferedReader reader = null;
try
{
StringBuilder sb = new StringBuilder();
- BufferedReader reader;
reader = new BufferedReader( new FileReader( file ) );
for ( String line = reader.readLine(); line != null; line = reader.readLine() )
{
sb.append( line );
}
reader.close();
+ reader = null;
return sb.toString();
}
catch ( IOException e )
{
throw new SurefireVerifierException( e );
}
-
+ finally
+ {
+ try
+ {
+ if ( reader != null )
+ {
+ reader.close();
+ }
+ }
+ catch ( final IOException e )
+ {
+ // Suppressed.
+ }
+ }
}
public String readFileToString()
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 739e134..258fd0f 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
@@ -43,19 +43,36 @@ public class BasicTest
private Properties getProperties(String resource)
{
- InputStream in = getClass().getResourceAsStream( resource );
- assertNotNull( in );
+ InputStream in = null;
try
{
- Properties props = new Properties();
- props.load( in );
- return props;
+ in = getClass().getResourceAsStream( resource );
+ assertNotNull( in );
+ Properties props = new Properties();
+ props.load( in );
+ in.close();
+ in = null;
+ return props;
}
- catch (IOException e)
+ catch ( IOException e )
{
- fail(e.toString());
+ fail( e.toString() );
return null;
}
+ finally
+ {
+ try
+ {
+ if ( in != null )
+ {
+ in.close();
+ }
+ }
+ catch ( final IOException e )
+ {
+ // Suppressed.
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 85d0a5b..1acfa60 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
@@ -22,23 +22,37 @@ package runListener;
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;
try
{
- File target = new File( "target" ).getAbsoluteFile();
- File listenerOutput = new File( target, fileName );
- FileWriter out = new FileWriter( listenerOutput );
- out.write( content );
- out.flush();
- out.close();
+ writer = new FileWriter( new File( new File( "target" ).getAbsoluteFile(), fileName ) );
+ writer.write( content );
+ writer.close();
+ writer = null;
}
catch ( IOException e )
{
throw new RuntimeException( e );
}
+ finally
+ {
+ try
+ {
+ if ( writer != null )
+ {
+ writer.close();
+ }
+ }
+ catch ( final IOException e )
+ {
+ // Suppressed.
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 a4d0cd3..30224e1 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
@@ -61,11 +61,12 @@ public class FailingTest
f.getParentFile().mkdirs();
FileWriter w = null;
-
try
{
w = new FileWriter( f, true );
w.write( name.getMethodName() );
+ w.close();
+ w = null;
}
finally
{
@@ -77,6 +78,7 @@ public class FailingTest
}
catch ( final IOException e )
{
+ // Suppressed.
}
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 c9167c1..2ed21eb 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
@@ -66,6 +66,8 @@ public class SucceedingTest
{
w = new FileWriter( f, true );
w.write( name.getMethodName() );
+ w.close();
+ w = null;
}
finally
{
@@ -77,6 +79,7 @@ public class SucceedingTest
}
catch ( final IOException e )
{
+ // Suppressed.
}
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 035976b..5e70556 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
@@ -41,30 +41,42 @@ public class DumpPidMojo
public void execute()
throws MojoExecutionException
{
- File target;
+ FileWriter fw = null;
try
{
getLog().info( "Dumping PID to " + targetDir );
-
+
if ( !targetDir.exists() )
{
targetDir.mkdirs();
}
-
- target = new File( targetDir, "maven.pid" ).getCanonicalFile();
- FileWriter fw = new FileWriter( target );
- String pid = ManagementFactory.getRuntimeMXBean().getName();
+ final String pid = ManagementFactory.getRuntimeMXBean().getName();
+ final File target = new File( targetDir, "maven.pid" ).getCanonicalFile();
+ fw = new FileWriter( target );
fw.write( pid );
- fw.flush();
fw.close();
-
+ fw = null;
+
getLog().info( "Wrote " + pid + " to " + target );
-
}
catch ( IOException e )
{
throw new MojoExecutionException( "Unable to create pid file", e );
}
+ finally
+ {
+ try
+ {
+ if ( fw != null )
+ {
+ fw.close();
+ }
+ }
+ catch ( final IOException e )
+ {
+ // Suppressed.
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 6a6688a..4405996 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
@@ -22,23 +22,37 @@ package listenReport;
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)
+ public static void writeFile( String fileName, String content )
{
+ Writer writer = null;
try
{
- File target = new File( "target" ).getAbsoluteFile();
- File listenerOutput = new File( target, fileName );
- FileWriter out = new FileWriter(listenerOutput);
- out.write( content );
- out.flush();
- out.close();
+ writer = new FileWriter( new File( new File( "target" ).getAbsoluteFile(), fileName ) );
+ writer.write( content );
+ writer.close();
+ writer = null;
}
catch ( IOException e )
{
- throw new RuntimeException(e);
+ throw new RuntimeException( e );
+ }
+ finally
+ {
+ try
+ {
+ if ( writer != null )
+ {
+ writer.close();
+ }
+ }
+ catch ( final IOException e )
+ {
+ // Suppressed.
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 4db30b6..4525e29 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
@@ -3,23 +3,39 @@ package testng.objectfactory;
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;
try
{
- File target = new File( System.getProperty("user.dir"), "target" ).getCanonicalFile();
- File listenerOutput = new File( target, fileName );
- FileWriter out = new FileWriter( listenerOutput, true );
- out.write( content );
- out.flush();
- out.close();
+ writer = new FileWriter( new File( new File( System.getProperty( "user.dir" ),
+ "target" ).getCanonicalFile(), fileName ), true );
+
+ writer.write( content );
+ writer.close();
+ writer = null;
}
catch ( IOException exception )
{
throw new RuntimeException( exception );
}
+ finally
+ {
+ try
+ {
+ if ( writer != null )
+ {
+ writer.close();
+ }
+ }
+ catch ( final IOException e )
+ {
+ // Suppressed.
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e5a6b9c8/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 4b998ed..b72bfc6 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,23 +3,39 @@ 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;
try
{
- File target = new File( System.getProperty("user.dir"), "target" ).getCanonicalFile();
- File listenerOutput = new File( target, fileName );
- FileWriter out = new FileWriter( listenerOutput, true );
- out.write( content );
- out.flush();
- out.close();
+ writer = new FileWriter( new File( new File( System.getProperty( "user.dir" ),
+ "target" ).getCanonicalFile(), fileName ), true );
+
+ writer.write( content );
+ writer.close();
+ writer = null;
}
catch ( IOException exception )
{
throw new RuntimeException( exception );
}
+ finally
+ {
+ try
+ {
+ if ( writer != null )
+ {
+ writer.close();
+ }
+ }
+ catch ( final IOException e )
+ {
+ // Suppressed.
+ }
+ }
}
}
[4/4] maven-surefire git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/maven-surefire
Posted by sc...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/maven-surefire
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/780f9139
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/780f9139
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/780f9139
Branch: refs/heads/master
Commit: 780f91393046fd11129cd9ee5bd10ca1d59286f0
Parents: 8004064 4d3673c
Author: Christian Schulte <sc...@apache.org>
Authored: Sun Jan 8 00:34:58 2017 +0100
Committer: Christian Schulte <sc...@apache.org>
Committed: Sun Jan 8 00:34:58 2017 +0100
----------------------------------------------------------------------
maven-surefire-common/pom.xml | 1 +
.../plugin/surefire/AbstractSurefireMojo.java | 1 +
.../surefire/StartupReportConfiguration.java | 7 ++-
.../surefire/booterclient/ForkStarter.java | 4 +-
.../output/DeserializedStacktraceWriter.java | 2 +-
.../booterclient/output/ForkClient.java | 13 +++++-
.../output/LostCommandsDumpSingleton.java | 7 +++
.../output/ThreadedStreamConsumer.java | 49 ++++++++------------
.../surefire/report/DefaultReporterFactory.java | 13 +++---
.../report/NullStatelessXmlReporter.java | 2 +-
.../surefire/report/StatelessXmlReporter.java | 10 ++--
.../surefire/report/TestSetRunListener.java | 2 +-
.../surefire/runorder/StatisticsReporter.java | 4 +-
.../report/DefaultReporterFactoryTest.java | 18 +++----
.../report/StatelessXmlReporterTest.java | 6 +--
.../maven/plugins/surefire/report/Utils.java | 1 +
.../maven/surefire/booter/CommandReader.java | 15 +++---
.../surefire/booter/MasterProcessCommand.java | 6 +--
.../surefire/report/CategorizedReportEntry.java | 17 +++----
.../maven/surefire/report/SafeThrowable.java | 5 ++
.../surefire/util/internal/StringUtils.java | 28 +----------
21 files changed, 102 insertions(+), 109 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/780f9139/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/780f9139/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/780f9139/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java
----------------------------------------------------------------------
[3/4] maven-surefire git commit: [SUREFIRE-1324] Surefire incorrectly
suppresses exceptions when closing resources.
Posted by sc...@apache.org.
[SUREFIRE-1324] Surefire incorrectly suppresses exceptions when closing resources.
o Updated various comments.
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/8004064b
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/8004064b
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/8004064b
Branch: refs/heads/master
Commit: 8004064be0f1e40539cd7879aa7752a78af97891
Parents: 6745654
Author: Christian Schulte <sc...@apache.org>
Authored: Sun Jan 8 00:33:35 2017 +0100
Committer: Christian Schulte <sc...@apache.org>
Committed: Sun Jan 8 00:33:35 2017 +0100
----------------------------------------------------------------------
.../java/org/apache/maven/plugin/surefire/SurefireProperties.java | 2 +-
.../org/apache/maven/surefire/booter/SystemPropertyManager.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/8004064b/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 b645032..0125aa4 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
@@ -247,7 +247,7 @@ public class SurefireProperties
}
catch ( final IOException e )
{
- // Suppressed.
+ // Suppressed, so that the exception thrown in the try block will be propagated.
}
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/8004064b/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 68d79a4..8d301dc 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
@@ -71,7 +71,7 @@ public class SystemPropertyManager
}
catch ( final IOException e1 )
{
- // Suppressed.
+ // Suppressed, so that the exception thrown in the try block will be propagated.
}
}
}
[2/4] maven-surefire git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/maven-surefire
Posted by sc...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/maven-surefire
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/67456544
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/67456544
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/67456544
Branch: refs/heads/master
Commit: 6745654499f086cd9b21b67026bbaf6e195edfb7
Parents: e5a6b9c 201a313
Author: Christian Schulte <sc...@apache.org>
Authored: Sun Jan 8 00:30:24 2017 +0100
Committer: Christian Schulte <sc...@apache.org>
Committed: Sun Jan 8 00:30:24 2017 +0100
----------------------------------------------------------------------
.../plugin/surefire/SurefireProperties.java | 1 +
.../output/LostCommandsDumpSingleton.java | 62 +++++++++++-
.../output/ThreadedStreamConsumer.java | 35 ++++---
.../report/ConsoleOutputFileReporter.java | 35 +++----
.../maven/surefire/report/FileReporterTest.java | 3 +-
.../surefire/report/SurefireReportMojoTest.java | 2 +-
.../runorder/RunEntryStatisticsMap.java | 34 +++----
.../maven/surefire/booter/CommandReader.java | 21 ++---
.../surefire/booter/DumpErrorSingleton.java | 99 ++++++++++++++++++++
.../surefire/booter/ForkingRunListener.java | 16 ++--
.../surefire/booter/MasterProcessCommand.java | 29 +-----
.../maven/surefire/booter/ForkedBooter.java | 41 +++-----
.../surefire/booter/SystemPropertyManager.java | 17 +++-
.../maven/surefire/its/fixture/TestFile.java | 4 +-
.../src/test/java/it/BasicTest.java | 13 ++-
.../src/test/java/runListener/FileHelper.java | 2 +-
.../plugins/surefire/dumppid/DumpPidMojo.java | 5 +-
.../testng/testrunnerfactory/FileHelper.java | 16 ++--
18 files changed, 282 insertions(+), 153 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/67456544/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
----------------------------------------------------------------------
diff --cc maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
index 2e3aa58,53aa134..b645032
--- 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
@@@ -237,17 -236,7 +237,18 @@@ public class SurefirePropertie
}
finally
{
- close( inStream ); // @todo use try-with-resources JDK7, search in all code
++ // @todo use try-with-resources JDK7, search in all code
+ try
+ {
+ if ( in != null )
+ {
+ in.close();
+ }
+ }
+ catch ( final IOException e )
+ {
+ // Suppressed.
+ }
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/67456544/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java
----------------------------------------------------------------------
diff --cc maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java
index 552c12a,914d684..da08d01
--- 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,9 -22,10 +22,8 @@@ package org.apache.maven.plugin.surefir
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;
/**
@@@ -65,19 -66,21 +64,17 @@@ public class ConsoleOutputFileReporte
@SuppressWarnings( "checkstyle:emptyblock" )
public void close()
{
-- if ( fileOutputStream != null )
++ try
{
-- try
-- {
- fileOutputStream.flush();
-- fileOutputStream.close();
-- }
-- catch ( IOException e )
-- {
- // do nothing
-- }
-- finally
-- {
-- fileOutputStream = null;
-- }
++ this.fileOutputStream.close();
++ }
++ catch ( final IOException e )
++ {
++ throw new RuntimeException( "Failure closing reporter.", e );
++ }
++ finally
++ {
++ this.fileOutputStream = null;
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/67456544/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java
----------------------------------------------------------------------
diff --cc maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java
index 87d4b0c,076b23c..f8a92d8
--- 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,16 -19,15 +19,15 @@@ package org.apache.maven.surefire.repor
* 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 junit.framework.TestCase;
-import java.io.File;
-import java.util.ArrayList;
--
public class FileReporterTest
extends TestCase
{
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/67456544/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportMojoTest.java
----------------------------------------------------------------------
diff --cc maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportMojoTest.java
index 9fca007,724e72d..8532b1b
--- 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
@@@ -638,10 -638,8 +638,10 @@@ public class SurefireReportMojoTes
{
outputHtml.getParentFile().mkdirs();
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/67456544/surefire-api/src/main/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMap.java
----------------------------------------------------------------------
diff --cc surefire-api/src/main/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMap.java
index a66e797,eab2a81..2e9c133
--- 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,16 -20,15 +20,12 @@@ package org.apache.maven.plugin.surefir
*/
-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.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
-import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Comparator;
@@@ -39,9 -38,8 +35,9 @@@ 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;
@@@ -70,15 -68,8 +66,11 @@@ public final class RunEntryStatisticsMa
try
{
reader = new FileReader( file );
- return fromReader( reader );
+ final RunEntryStatisticsMap result = fromReader( reader );
+ reader.close();
+ reader = null;
+ return result;
}
- catch ( FileNotFoundException e )
- {
- throw new RuntimeException( e );
- }
catch ( IOException e )
{
throw new RuntimeException( e );
@@@ -97,19 -88,14 +89,27 @@@
static RunEntryStatisticsMap fromReader( Reader fileReader )
throws IOException
{
++ BufferedReader reader = null;
Map<String, RunEntryStatistics> result = new HashMap<String, RunEntryStatistics>();
- BufferedReader bufferedReader = new BufferedReader( fileReader );
- String line = bufferedReader.readLine();
- while ( line != null )
- BufferedReader reader = new BufferedReader( fileReader );
- for ( String line = reader.readLine(); line != null && !line.startsWith( "#" ); line = reader.readLine() )
++ try
{
- if ( !line.startsWith( "#" ) )
- RunEntryStatistics stats = fromString( line );
- result.put( stats.getTestName(), stats );
++ reader = new BufferedReader( fileReader );
++ for ( String line = reader.readLine(); line != null; line = reader.readLine() )
+ {
- final RunEntryStatistics stats = fromString( line );
- result.put( stats.getTestName(), stats );
++ if ( !line.startsWith( "#" ) )
++ {
++ RunEntryStatistics stats = fromString( line );
++ result.put( stats.getTestName(), stats );
++ }
+ }
- line = bufferedReader.readLine();
++ reader.close();
++ reader = null;
++ return new RunEntryStatisticsMap( result );
++ }
++ finally
++ {
++ IOUtil.close( reader );
}
-- return new RunEntryStatisticsMap( result );
}
public void serialize( File file )
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/67456544/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
----------------------------------------------------------------------
diff --cc surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
index 4558aba,aa0dadd..7439ec3
--- 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,10 -19,6 +19,11 @@@ package org.apache.maven.surefire.boote
* 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;
@@@ -32,9 -28,13 +33,6 @@@ import org.apache.maven.surefire.report
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;
@@@ -208,7 -208,10 +206,11 @@@ public class ForkingRunListene
target.write( encodeBytes, 0, encodeBytes.length );
if ( target.checkError() )
{
- throw new RuntimeException( "Unexpected IOException." );
+ // 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/67456544/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java
----------------------------------------------------------------------
diff --cc surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessCommand.java
index d2d1673,a75aa83..bc95a39
--- 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
@@@ -19,18 -19,17 +19,15 @@@ package org.apache.maven.surefire.boote
* under the License.
*/
--import org.apache.maven.surefire.util.internal.StringUtils;
--
import java.io.DataInputStream;
- import java.io.EOFException;
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;
- import static org.apache.maven.surefire.util.internal.ObjectUtils.requireNonNull;
- import static java.lang.String.format;
/**
* Commands which are sent from plugin to the forked jvm.
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/67456544/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
----------------------------------------------------------------------
diff --cc surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java
index 29047f2,b76df2f..6df3009
--- 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,14 -19,14 +19,6 @@@ package org.apache.maven.surefire.boote
* 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;
@@@ -38,13 -38,13 +30,19 @@@ import java.util.concurrent.ScheduledFu
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/67456544/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
----------------------------------------------------------------------
diff --cc surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemPropertyManager.java
index 4046b7b,a80656e..68d79a4
--- 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
@@@ -61,7 -58,7 +61,18 @@@ public class SystemPropertyManage
}
finally
{
-- close( inStream ); // @todo use try-with-resources JDK7, search in all code
++ // @todo use try-with-resources JDK7, search in all code
++ try
++ {
++ if ( inStream != null )
++ {
++ inStream.close();
++ }
++ }
++ catch ( final IOException e1 )
++ {
++ // Suppressed.
++ }
}
}
@@@ -120,6 -108,6 +131,10 @@@
}
}
++ /**
++ * @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/67456544/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/TestFile.java
----------------------------------------------------------------------
diff --cc surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/TestFile.java
index a2f021f,6d3d8e2..eb33e78
--- 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,10 -28,10 +28,8 @@@ import java.io.IOException
import java.net.URI;
import java.nio.charset.Charset;
import java.util.List;
--import org.apache.commons.io.FileUtils;
--
import junit.framework.Assert;
--
++import org.apache.commons.io.FileUtils;
import static junit.framework.Assert.assertTrue;
/**
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/67456544/surefire-integration-tests/src/test/resources/classpath-order/src/test/java/it/BasicTest.java
----------------------------------------------------------------------
diff --cc surefire-integration-tests/src/test/resources/classpath-order/src/test/java/it/BasicTest.java
index 258fd0f,f46e3be..e595cd6
--- 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
@@@ -41,17 -43,15 +43,18 @@@ public class BasicTes
assertEquals( "classes", props.getProperty( "Surefire" ) );
}
- private Properties getProperties(String resource)
+ private Properties getProperties( String resource )
- throws IOException
++ throws IOException
{
- InputStream in = getClass().getResourceAsStream( resource );
- assertNotNull( in );
+ InputStream in = null;
try
{
+ in = getClass().getResourceAsStream( resource );
+ assertNotNull( in );
Properties props = new Properties();
props.load( in );
+ in.close();
+ in = null;
return props;
}
catch ( IOException e )
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/67456544/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java
----------------------------------------------------------------------
diff --cc surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java
index 1acfa60,0112f31..c842a1d
--- 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
@@@ -51,7 -50,7 +51,7 @@@ public class FileHelpe
}
catch ( final IOException e )
{
-- // Suppressed.
++ // Suppressed, so that the exception thrown in the try block will be propagated.
}
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/67456544/surefire-integration-tests/src/test/resources/test-helper-dump-pid-plugin/src/main/java/org/apache/maven/plugins/surefire/dumppid/DumpPidMojo.java
----------------------------------------------------------------------
diff --cc surefire-integration-tests/src/test/resources/test-helper-dump-pid-plugin/src/main/java/org/apache/maven/plugins/surefire/dumppid/DumpPidMojo.java
index 5e70556,aa44b64..b010d22
--- 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
@@@ -50,14 -51,11 +51,12 @@@ public class DumpPidMoj
{
targetDir.mkdirs();
}
+
- final String pid = ManagementFactory.getRuntimeMXBean().getName();
- final File target = new File( targetDir, "maven.pid" ).getCanonicalFile();
fw = new FileWriter( target );
- String pid = ManagementFactory.getRuntimeMXBean().getName();
++ final String pid = ManagementFactory.getRuntimeMXBean().getName();
fw.write( pid );
- fw.flush();
-
+ fw.close();
+ fw = null;
-
getLog().info( "Wrote " + pid + " to " + target );
}
catch ( IOException e )
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/67456544/surefire-integration-tests/src/test/resources/testng-testRunnerFactory/src/test/java/testng/testrunnerfactory/FileHelper.java
----------------------------------------------------------------------
diff --cc surefire-integration-tests/src/test/resources/testng-testRunnerFactory/src/test/java/testng/testrunnerfactory/FileHelper.java
index b72bfc6,5451dbf..b0a8e92
--- 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
@@@ -9,32 -8,31 +9,32 @@@ public class FileHelpe
{
public static void writeFile( String fileName, String content )
{
- FileWriter out = null;
+ Writer writer = null;
try
{
- 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();
+ writer = new FileWriter( new File( new File( System.getProperty( "user.dir" ),
+ "target" ).getCanonicalFile(), fileName ), true );
+
+ writer.write( content );
+ writer.close();
+ writer = null;
}
- catch ( IOException exception )
+ catch ( IOException e )
{
- throw new RuntimeException( exception );
+ throw new RuntimeException( e );
}
finally
{
- try
- if ( out != null )
++ if ( writer != null )
{
- if ( writer != null )
+ try
{
- out.close();
+ writer.close();
}
- }
- catch ( final IOException e )
- {
- // Suppressed.
+ catch ( IOException e )
+ {
- throw new RuntimeException( e );
++ // Suppressed, so that the exception thrown in the try block will be propagated.
+ }
}
}
}