You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2018/11/09 19:15:17 UTC

[maven-verifier] branch master updated (13db883 -> d258bc3)

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/maven-verifier.git.


    from 13db883  Upgrade parent to 33
     new deb4fc1  Switch from test-named to @Test annotated methods
     new d258bc3  Apply try-with-resources and multi-catch

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../maven/shared/verifier/Embedded3xLauncher.java  | 42 +---------
 .../org/apache/maven/shared/verifier/Verifier.java | 94 ++++++++--------------
 .../apache/maven/shared/verifier/VerifierTest.java | 10 ++-
 3 files changed, 43 insertions(+), 103 deletions(-)


[maven-verifier] 02/02: Apply try-with-resources and multi-catch

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-verifier.git

commit d258bc3e975e93ccb2bcf14d6a06ceb7f68ca7c8
Author: rfscholte <rf...@apache.org>
AuthorDate: Fri Nov 9 20:15:08 2018 +0100

    Apply try-with-resources and multi-catch
---
 .../maven/shared/verifier/Embedded3xLauncher.java  | 42 +---------
 .../org/apache/maven/shared/verifier/Verifier.java | 94 ++++++++--------------
 2 files changed, 36 insertions(+), 100 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/verifier/Embedded3xLauncher.java b/src/main/java/org/apache/maven/shared/verifier/Embedded3xLauncher.java
index 699be36..8979a23 100644
--- a/src/main/java/org/apache/maven/shared/verifier/Embedded3xLauncher.java
+++ b/src/main/java/org/apache/maven/shared/verifier/Embedded3xLauncher.java
@@ -107,27 +107,7 @@ class Embedded3xLauncher
 
             return new Embedded3xLauncher( mavenCli, doMain );
         }
-        catch ( ClassNotFoundException e )
-        {
-            throw new LauncherException( "Invalid Maven home directory " + mavenHome, e );
-        }
-        catch ( InstantiationException e )
-        {
-            throw new LauncherException( "Invalid Maven home directory " + mavenHome, e );
-        }
-        catch ( IllegalAccessException e )
-        {
-            throw new LauncherException( "Invalid Maven home directory " + mavenHome, e );
-        }
-        catch ( NoSuchMethodException e )
-        {
-            throw new LauncherException( "Invalid Maven home directory " + mavenHome, e );
-        }
-        catch ( InvocationTargetException e )
-        {
-            throw new LauncherException( "Invalid Maven home directory " + mavenHome, e );
-        }
-        catch ( IOException e )
+        catch ( ReflectiveOperationException | IOException e )
         {
             throw new LauncherException( "Invalid Maven home directory " + mavenHome, e );
         }
@@ -157,19 +137,7 @@ class Embedded3xLauncher
 
             return new Embedded3xLauncher( mavenCli, doMain );
         }
-        catch ( ClassNotFoundException e )
-        {
-            throw new LauncherException( e.getMessage(), e );
-        }
-        catch ( NoSuchMethodException e )
-        {
-            throw new LauncherException( e.getMessage(), e );
-        }
-        catch ( InstantiationException e )
-        {
-            throw new LauncherException( e.getMessage(), e );
-        }
-        catch ( IllegalAccessException e )
+        catch ( ReflectiveOperationException e )
         {
             throw new LauncherException( e.getMessage(), e );
         }
@@ -255,11 +223,7 @@ class Embedded3xLauncher
                 System.setProperties( originalProperties );
             }
         }
-        catch ( IllegalAccessException e )
-        {
-            throw new LauncherException( "Failed to run Maven: " + e.getMessage(), e );
-        }
-        catch ( InvocationTargetException e )
+        catch ( IllegalAccessException | InvocationTargetException e )
         {
             throw new LauncherException( "Failed to run Maven: " + e.getMessage(), e );
         }
diff --git a/src/main/java/org/apache/maven/shared/verifier/Verifier.java b/src/main/java/org/apache/maven/shared/verifier/Verifier.java
index 3981d71..e9c96f4 100644
--- a/src/main/java/org/apache/maven/shared/verifier/Verifier.java
+++ b/src/main/java/org/apache/maven/shared/verifier/Verifier.java
@@ -50,8 +50,6 @@ import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
-import junit.framework.Assert;
-
 import org.apache.maven.shared.utils.StringUtils;
 import org.apache.maven.shared.utils.cli.CommandLineException;
 import org.apache.maven.shared.utils.cli.CommandLineUtils;
@@ -59,7 +57,7 @@ import org.apache.maven.shared.utils.cli.Commandline;
 import org.apache.maven.shared.utils.cli.StreamConsumer;
 import org.apache.maven.shared.utils.cli.WriterStreamConsumer;
 import org.apache.maven.shared.utils.io.FileUtils;
-import org.apache.maven.shared.utils.io.IOUtil;
+import org.junit.Assert;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
@@ -341,15 +339,10 @@ public class Verifier
             File propertiesFile = new File( getBasedir(), filename );
             if ( propertiesFile.exists() )
             {
-                FileInputStream fis = new FileInputStream( propertiesFile );
-                try
+                try ( FileInputStream fis = new FileInputStream( propertiesFile ) ) 
                 {
                     properties.load( fis );
                 }
-                finally
-                {
-                    fis.close();
-                }
             }
         }
         catch ( FileNotFoundException e )
@@ -379,20 +372,8 @@ public class Verifier
     {
         List<String> lines = new ArrayList<String>();
 
-        File file = new File( getBasedir(), filename );
-
-        BufferedReader reader = null;
-        try
+        try ( BufferedReader reader = getReader( filename, encoding ) )
         {
-            if ( StringUtils.isNotEmpty( encoding ) )
-            {
-                reader = new BufferedReader( new InputStreamReader( new FileInputStream( file ), encoding ) );
-            }
-            else
-            {
-                reader = new BufferedReader( new FileReader( file ) );
-            }
-
             String line;
             while ( ( line = reader.readLine() ) != null )
             {
@@ -402,14 +383,24 @@ public class Verifier
                 }
             }
         }
-        finally
-        {
-            IOUtil.close( reader );
-        }
 
         return lines;
     }
 
+    private BufferedReader getReader( String filename, String encoding ) throws IOException
+    {
+        File file = new File( getBasedir(), filename );
+
+        if ( StringUtils.isNotEmpty( encoding ) )
+        {
+            return new BufferedReader( new InputStreamReader( new FileInputStream( file ), encoding ) );
+        }
+        else
+        {
+            return new BufferedReader( new FileReader( file ) );
+        }
+    }
+
     public List<String> loadFile( String basedir, String filename, boolean hasCommand )
         throws VerificationException
     {
@@ -421,14 +412,10 @@ public class Verifier
     {
         List<String> lines = new ArrayList<String>();
 
-        BufferedReader reader = null;
-
         if ( file.exists() )
         {
-            try
+            try ( BufferedReader reader = new BufferedReader( new FileReader( file ) ) )
             {
-                reader = new BufferedReader( new FileReader( file ) );
-
                 String line = reader.readLine();
 
                 while ( line != null )
@@ -441,8 +428,6 @@ public class Verifier
                     }
                     line = reader.readLine();
                 }
-
-                reader.close();
             }
             catch ( FileNotFoundException e )
             {
@@ -452,10 +437,6 @@ public class Verifier
             {
                 throw new VerificationException( e );
             }
-            finally
-            {
-                IOUtil.close( reader );
-            }
         }
 
         return lines;
@@ -798,23 +779,22 @@ public class Verifier
 
             cli.setWorkingDirectory( basedir );
 
-            Writer logWriter = new FileWriter( new File( basedir, LOG_FILENAME ) );
-
-            StreamConsumer out = new WriterStreamConsumer( logWriter );
-
-            StreamConsumer err = new WriterStreamConsumer( logWriter );
+            try ( Writer logWriter = new FileWriter( new File( basedir, LOG_FILENAME ) ) ) 
+            {
+                StreamConsumer out = new WriterStreamConsumer( logWriter );
 
-            System.out.println( "Command: " + CommandLineUtils.toString( cli.getCommandline() ) );
+                StreamConsumer err = new WriterStreamConsumer( logWriter );
 
-            int ret = CommandLineUtils.executeCommandLine( cli, out, err );
+                System.out.println( "Command: " + CommandLineUtils.toString( cli.getCommandline() ) );
 
-            logWriter.close();
+                int ret = CommandLineUtils.executeCommandLine( cli, out, err );
 
-            if ( ret > 0 )
-            {
-                System.err.println( "Exit code: " + ret );
+                if ( ret > 0 )
+                {
+                    System.err.println( "Exit code: " + ret );
 
-                throw new VerificationException();
+                    throw new VerificationException();
+                }
             }
         }
         catch ( CommandLineException e )
@@ -1529,30 +1509,22 @@ public class Verifier
     private void displayLogFile()
     {
         System.out.println( "Log file contents:" );
-        BufferedReader reader = null;
-        try
+
+        try ( BufferedReader reader = 
+                        new BufferedReader( new FileReader( new File( getBasedir(), getLogFileName() ) ) ) )
         {
-            reader = new BufferedReader( new FileReader( new File( getBasedir(), getLogFileName() ) ) );
             String line = reader.readLine();
+            
             while ( line != null )
             {
                 System.out.println( line );
                 line = reader.readLine();
             }
-            reader.close();
-        }
-        catch ( FileNotFoundException e )
-        {
-            System.err.println( "Error: " + e );
         }
         catch ( IOException e )
         {
             System.err.println( "Error: " + e );
         }
-        finally
-        {
-            IOUtil.close( reader );
-        }
     }
 
     // ----------------------------------------------------------------------


[maven-verifier] 01/02: Switch from test-named to @Test annotated methods

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-verifier.git

commit deb4fc1c49f8c6cf85d4906649ef687be04eedfc
Author: rfscholte <rf...@apache.org>
AuthorDate: Fri Nov 9 19:55:55 2018 +0100

    Switch from test-named to @Test annotated methods
---
 .../java/org/apache/maven/shared/verifier/VerifierTest.java    | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/test/java/org/apache/maven/shared/verifier/VerifierTest.java b/src/test/java/org/apache/maven/shared/verifier/VerifierTest.java
index a0ef9dd..94d1920 100644
--- a/src/test/java/org/apache/maven/shared/verifier/VerifierTest.java
+++ b/src/test/java/org/apache/maven/shared/verifier/VerifierTest.java
@@ -19,22 +19,23 @@ package org.apache.maven.shared.verifier;
  * under the License.
  */
 
+import static org.junit.Assert.assertEquals;
+
 import java.util.Arrays;
 
 import org.apache.maven.shared.verifier.ForkedLauncher;
 import org.apache.maven.shared.verifier.VerificationException;
 import org.apache.maven.shared.verifier.Verifier;
-
-import junit.framework.TestCase;
+import org.junit.Test;
 
 public class VerifierTest
-    extends TestCase
 {
     private void check( String expected, String... lines )
     {
         assertEquals( expected, ForkedLauncher.extractMavenVersion( Arrays.asList( lines ) ) );
     }
 
+    @Test
     public void testSunBug9009028ForJdk()
     {
         final String version = System.getProperty( "java.version" );
@@ -42,6 +43,7 @@ public class VerifierTest
         assertEquals( version, System.getProperty( "java.version" ) );
     }
 
+    @Test
     public void testExtractMavenVersion()
     {
         check( "2.0.6", "Maven version: 2.0.6" );
@@ -62,6 +64,7 @@ public class VerifierTest
                "OS name: \"linux\" version: \"3.11.0-13-generic\" arch: \"amd64\" Family: \"unix\"" );
     }
 
+    @Test
     public void testFileInJarPresent()
         throws VerificationException
     {
@@ -71,6 +74,7 @@ public class VerifierTest
         verifier.assertFileNotPresent( "mshared104.jar!/fud.xml" );
     }
 
+    @Test
     public void testStripAnsi()
     {
         assertEquals( "--- plugin:version:goal (id) @ artifactId ---",