maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From schu...@apache.org
Subject [2/4] maven-surefire git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/maven-surefire
Date Sat, 07 Jan 2017 23:38:43 GMT
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 <schulte@apache.org>
Authored: Sun Jan 8 00:30:24 2017 +0100
Committer: Christian Schulte <schulte@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.
+                 }
              }
          }
      }


Mime
View raw message