[maven-enforcer] branch MENFORCER-317 created (now 1aad120)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[maven-enforcer] branch MENFORCER-317 created (now 1aad120)

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

khmarbaise pushed a change to branch MENFORCER-317
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git.


      at 1aad120  [MENFORCER-317] - Fix RequireFileChecksum ignores configured message

This branch includes the following new commits:

     new 1aad120  [MENFORCER-317] - Fix RequireFileChecksum ignores configured message

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.


Reply | Threaded
Open this post in threaded view
|

[maven-enforcer] 01/01: [MENFORCER-317] - Fix RequireFileChecksum ignores configured message

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

khmarbaise pushed a commit to branch MENFORCER-317
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git

commit 1aad120efeb2ea91ba396866e35861386476805f
Author: Falko Modler <[hidden email]>
AuthorDate: Tue Sep 4 23:44:32 2018 +0200

    [MENFORCER-317] - Fix RequireFileChecksum ignores configured message
---
 .../maven/plugins/enforcer/RequireFileChecksum.java   |  9 +++++++--
 .../plugins/enforcer/TestRequireFileChecksum.java     | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java
index 1ab2aba..4ec1c54 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java
@@ -100,8 +100,13 @@ public class RequireFileChecksum
             }
             if ( !checksum.equalsIgnoreCase( this.checksum ) )
             {
-                throw new EnforcerRuleException( this.type + " hash of " + this.file + " was " + checksum
-                    + " but expected " + this.checksum );
+                String exceptionMessage = getMessage();
+                if ( exceptionMessage == null )
+                {
+                    exceptionMessage = this.type + " hash of " + this.file + " was " + checksum
+                        + " but expected " + this.checksum;
+                }
+                throw new EnforcerRuleException( exceptionMessage );
             }
         }
         catch ( IOException e )
diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFileChecksum.java b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFileChecksum.java
index 4333cb3..3f8ed9b 100644
--- a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFileChecksum.java
+++ b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFileChecksum.java
@@ -176,6 +176,25 @@ public class TestRequireFileChecksum
     }
 
     @Test
+    public void testFileChecksumMd5ChecksumMismatchFailureWithMessage()
+        throws IOException, EnforcerRuleException
+    {
+        File f = temporaryFolder.newFile();
+        FileUtils.fileWrite( f, "message" );
+        String configuredMessage = "testMessage";
+
+        expectedException.expect( EnforcerRuleException.class );
+        expectedException.expectMessage( configuredMessage );
+
+        rule.setFile( f );
+        rule.setChecksum( "ffeeddccbbaa99887766554433221100" );
+        rule.setType( "md5" );
+        rule.setMessage( configuredMessage );
+
+        rule.execute( EnforcerTestUtils.getHelper() );
+    }
+
+    @Test
     public void testFileChecksumSha1()
         throws IOException, EnforcerRuleException
     {