You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2020/01/10 16:12:25 UTC

[maven-verifier-plugin] branch MVERIFIER-36 created (now 1330656)

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

slachiewicz pushed a change to branch MVERIFIER-36
in repository https://gitbox.apache.org/repos/asf/maven-verifier-plugin.git.


      at 1330656  [MVERIFIER-36] Code cleanup, move to Java 7

This branch includes the following new commits:

     new 1330656  [MVERIFIER-36] Code cleanup, move to Java 7

The 1 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.



[maven-verifier-plugin] 01/01: [MVERIFIER-36] Code cleanup, move to Java 7

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

slachiewicz pushed a commit to branch MVERIFIER-36
in repository https://gitbox.apache.org/repos/asf/maven-verifier-plugin.git

commit 1330656e1945dfe7ef1a1f3e8034b64138887f10
Author: Artem Krosheninnikov <fe...@gmail.com>
AuthorDate: Thu Jan 9 18:18:24 2020 +0300

    [MVERIFIER-36] Code cleanup, move to Java 7
    
    Closes #1
---
 .../verifier/ConsoleVerificationResultPrinter.java | 26 +++---------------
 .../maven/plugins/verifier/VerificationResult.java |  6 ++--
 .../maven/plugins/verifier/VerifierMojo.java       | 32 ++++++----------------
 .../maven/plugins/verifier/VerifierMojoTest.java   | 30 ++++++++++++--------
 4 files changed, 33 insertions(+), 61 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/verifier/ConsoleVerificationResultPrinter.java b/src/main/java/org/apache/maven/plugins/verifier/ConsoleVerificationResultPrinter.java
index 64f33a4..90d20b5 100644
--- a/src/main/java/org/apache/maven/plugins/verifier/ConsoleVerificationResultPrinter.java
+++ b/src/main/java/org/apache/maven/plugins/verifier/ConsoleVerificationResultPrinter.java
@@ -20,6 +20,7 @@ package org.apache.maven.plugins.verifier;
  */
 
 import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.verifier.model.File;
 
 /**
  * 
@@ -42,37 +43,18 @@ public class ConsoleVerificationResultPrinter
      */
     public void print( VerificationResult results )
     {
-        printExistenceFailures( results );
-        printNonExistenceFailures( results );
-        printContentFailures( results );
-    }
-
-    private void printExistenceFailures( VerificationResult results )
-    {
-        for ( Object o : results.getExistenceFailures() )
+        for ( File file : results.getExistenceFailures() )
         {
-            org.apache.maven.plugins.verifier.model.File file = (org.apache.maven.plugins.verifier.model.File) o;
-
             printMessage( "File not found [" + file.getLocation() + "]" );
         }
-    }
 
-    private void printNonExistenceFailures( VerificationResult results )
-    {
-        for ( Object o : results.getNonExistenceFailures() )
+        for ( File file : results.getNonExistenceFailures() )
         {
-            org.apache.maven.plugins.verifier.model.File file = (org.apache.maven.plugins.verifier.model.File) o;
-
             printMessage( "File should not exist [" + file.getLocation() + "]" );
         }
-    }
 
-    private void printContentFailures( VerificationResult results )
-    {
-        for ( Object o : results.getContentFailures() )
+        for ( File file : results.getContentFailures() )
         {
-            org.apache.maven.plugins.verifier.model.File file = (org.apache.maven.plugins.verifier.model.File) o;
-
             printMessage( "File [" + file.getLocation() + "] does not match regexp [" + file.getContains() + "]" );
         }
     }
diff --git a/src/main/java/org/apache/maven/plugins/verifier/VerificationResult.java b/src/main/java/org/apache/maven/plugins/verifier/VerificationResult.java
index c4c7a60..111468b 100644
--- a/src/main/java/org/apache/maven/plugins/verifier/VerificationResult.java
+++ b/src/main/java/org/apache/maven/plugins/verifier/VerificationResult.java
@@ -29,11 +29,11 @@ import org.apache.maven.plugins.verifier.model.File;
  */
 public class VerificationResult
 {
-    private List<File> existenceFailures = new ArrayList<File>();
+    private List<File> existenceFailures = new ArrayList<>();
 
-    private List<File> nonExistenceFailures = new ArrayList<File>();
+    private List<File> nonExistenceFailures = new ArrayList<>();
 
-    private List<File> contentFailures = new ArrayList<File>();
+    private List<File> contentFailures = new ArrayList<>();
 
     /**
      * @param file {@link File}
diff --git a/src/main/java/org/apache/maven/plugins/verifier/VerifierMojo.java b/src/main/java/org/apache/maven/plugins/verifier/VerifierMojo.java
index 5132efe..c093ec6 100644
--- a/src/main/java/org/apache/maven/plugins/verifier/VerifierMojo.java
+++ b/src/main/java/org/apache/maven/plugins/verifier/VerifierMojo.java
@@ -53,7 +53,7 @@ import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.verifier.model.Verifications;
 import org.apache.maven.plugins.verifier.model.io.xpp3.VerificationsXpp3Reader;
 import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 /**
  * Verifies the existence or non-existence of files/directories and optionally checks file content against a regular
@@ -74,10 +74,9 @@ public class VerifierMojo
     /**
      * The file containing the verifications to perform.
      */
-    // CHECKSTYLE_OFF: LineLength
-    @Parameter( property = "verifier.verificationFile", defaultValue = "${basedir}/src/test/verifier/verifications.xml", required = true )
+    @Parameter( property = "verifier.verificationFile", defaultValue = "${basedir}/src/test/verifier/verifications.xml",
+            required = true )
     private File verificationFile;
-    // CHECKSTYLE_ON: LineLength
 
     /**
      * Whether the build will fail on verification errors.
@@ -94,7 +93,7 @@ public class VerifierMojo
         throws MojoExecutionException
     {
         VerificationResult results = verify();
-        this.resultPrinter.print( results );
+        resultPrinter.print( results );
 
         // Fail the build if there are errors
         if ( this.failOnError && results.hasFailures() )
@@ -123,17 +122,11 @@ public class VerifierMojo
     {
         VerificationResult results = new VerificationResult();
 
-        Reader reader = null;
-        try
+        try ( Reader reader = new FileReader( verificationFile ) )
         {
-            reader = new FileReader( this.verificationFile );
-
             VerificationsXpp3Reader xppReader = new VerificationsXpp3Reader();
             Verifications verifications = xppReader.read( reader );
 
-            reader.close();
-            reader = null;
-
             for ( org.apache.maven.plugins.verifier.model.File file : verifications.getFiles() )
             {
                 // Transform the file to check into an absolute path prefixing the basedir if
@@ -149,18 +142,10 @@ public class VerifierMojo
                 }
             }
         }
-        catch ( org.codehaus.plexus.util.xml.pull.XmlPullParserException e )
+        catch ( XmlPullParserException | IOException e )
         {
             throw new MojoExecutionException( "Error while verifying files", e );
         }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( "Error while verifying files", e );
-        }
-        finally
-        {
-            IOUtil.close( reader );
-        }
 
         return results;
     }
@@ -179,8 +164,8 @@ public class VerifierMojo
         return result;
     }
 
-    // CHECKSTYLE_OFF: LineLength
-    private boolean verifyFileContent( org.apache.maven.plugins.verifier.model.File fileCheck, VerificationResult results )
+    private boolean verifyFileContent( org.apache.maven.plugins.verifier.model.File fileCheck,
+            VerificationResult results )
         throws IOException
     {
         boolean result = false;
@@ -204,7 +189,6 @@ public class VerifierMojo
 
         return result;
     }
-    // CHECKSTYLE_ON: LineLength
 
     private boolean verifyFileExistence( org.apache.maven.plugins.verifier.model.File fileCheck,
                                          VerificationResult results )
diff --git a/src/test/java/org/apache/maven/plugins/verifier/VerifierMojoTest.java b/src/test/java/org/apache/maven/plugins/verifier/VerifierMojoTest.java
index d6afbdc..0129ee3 100644
--- a/src/test/java/org/apache/maven/plugins/verifier/VerifierMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/verifier/VerifierMojoTest.java
@@ -1,14 +1,5 @@
 package org.apache.maven.plugins.verifier;
 
-import java.io.File;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.verifier.VerificationResult;
-import org.apache.maven.plugins.verifier.VerificationResultPrinter;
-import org.apache.maven.plugins.verifier.VerifierMojo;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -28,18 +19,26 @@ import org.apache.maven.plugins.verifier.VerifierMojo;
  * under the License.
  */
 
-import junit.framework.TestCase;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+
+import static org.junit.Assert.*;
 
 public class VerifierMojoTest
-    extends TestCase
 {
     private File getResourceFile( String name ) throws UnsupportedEncodingException
     {
         String file = getClass().getResource( name ).getFile();
-        String decode = URLDecoder.decode( file, "UTF-8" ); // necessary for JDK 1.5+, where spaces are escaped to %20
+        String decode = URLDecoder.decode( file, StandardCharsets.UTF_8.toString()  ); // necessary for JDK 1.5+, where spaces are escaped to %20
         return new File( decode );
     }
 
+    @Test
     public void testPrefixWithBaseDir()
     {
         VerifierMojo mojo = new VerifierMojo();
@@ -51,6 +50,7 @@ public class VerifierMojoTest
         assertEquals( expectedResult.getPath(), result.getPath() );
     }
 
+    @Test
     public void testDoNotPrefixWhenAbsolutePath()
     {
         VerifierMojo mojo = new VerifierMojo();
@@ -62,6 +62,7 @@ public class VerifierMojoTest
         assertEquals( absoluteFile.getPath(), result.getPath() );
     }
 
+    @Test
     public void testCheckFileThatDoesNotExist()
         throws Exception
     {
@@ -91,6 +92,7 @@ public class VerifierMojoTest
         }
     }
 
+    @Test
     public void testCheckFileThatExists()
         throws Exception
     {
@@ -112,6 +114,7 @@ public class VerifierMojoTest
         mojo.execute();
     }
 
+    @Test
     public void testCheckForInexistentFile()
         throws Exception
     {
@@ -132,6 +135,7 @@ public class VerifierMojoTest
         mojo.execute();
     }
 
+    @Test
     public void testCheckForInexistentFileThatExists()
         throws Exception
     {
@@ -161,6 +165,7 @@ public class VerifierMojoTest
         }
     }
 
+    @Test
     public void testCheckFileForContent()
         throws Exception
     {
@@ -181,6 +186,7 @@ public class VerifierMojoTest
         mojo.execute();
     }
 
+    @Test
     public void testCheckFileForInvalidContent()
         throws Exception
     {