[maven-enforcer] branch MENFORCER-317 updated (b6c9b73 -> 3f397b1)

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

[maven-enforcer] branch MENFORCER-317 updated (b6c9b73 -> 3f397b1)

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.


 discard b6c9b73  [MENFORCER-317] - Fix RequireFileChecksum ignores configured message
    omit 7b02571  Changed configuration for allowedPluginRepositories
     new 297fe2a  Changed configuration for allowedPluginRepositories
     new 5d74395  [MENFORCER-315] - Add thirdparty rules page to the enforcer site  o Add thirdparty-rules page to site for enumerating thirdparty Maven Enforcer rules;  o Add link to Sonatype OSS Index rules documentation
     new 3f397b1  [MENFORCER-317] - Fix RequireFileChecksum ignores configured message  - Introduce configurable message for nonexistent file  - Including small refactoring: extract checksum calculation into private method.

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (b6c9b73)
            \
             N -- N -- N   refs/heads/MENFORCER-317 (3f397b1)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 3 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:
 .../plugins/enforcer/RequireFileChecksum.java      | 123 +++++++++++++--------
 .../plugins/enforcer/TestRequireFileChecksum.java  |  41 ++++++-
 .../src/site/apt/thirdparty-rules.apt              |  14 +--
 maven-enforcer-plugin/src/site/site.xml            |   1 +
 4 files changed, 123 insertions(+), 56 deletions(-)
 copy enforcer-api/src/site/apt/index.apt => maven-enforcer-plugin/src/site/apt/thirdparty-rules.apt (67%)

Reply | Threaded
Open this post in threaded view
|

[maven-enforcer] 01/03: Changed configuration for allowedPluginRepositories

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 297fe2ab6ada8986acb8cc1f1483d9023a205149
Author: Karl Heinz Marbaise <[hidden email]>
AuthorDate: Fri Oct 5 19:14:59 2018 +0200

    Changed configuration for allowedPluginRepositories
---
 .../it/projects/require-no-repositories-allow-plugin-repo/pom.xml    | 4 +++-
 .../src/it/projects/require-no-repositories-allow-repo/pom.xml       | 4 +++-
 .../require-no-repositories_failure_allowed-plugin-repo/pom.xml      | 5 ++++-
 .../it/projects/require-no-repositories_failure_repositories/pom.xml | 4 +++-
 4 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/pom.xml b/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/pom.xml
index ba8a6a7..cc568e2 100644
--- a/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/pom.xml
+++ b/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/pom.xml
@@ -58,7 +58,9 @@
             <configuration>
               <rules>
                 <requireNoRepositories>
-                  <allowedPluginRepositories>plugin-repo</allowedPluginRepositories>
+                  <allowedPluginRepositories>
+                    <allowedPluginRepository>plugin-repo</allowedPluginRepository>
+                  </allowedPluginRepositories>
                 </requireNoRepositories>
               </rules>
             </configuration>
diff --git a/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/pom.xml b/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/pom.xml
index c0af0cc..9c9aa27 100644
--- a/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/pom.xml
+++ b/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/pom.xml
@@ -58,7 +58,9 @@
             <configuration>
               <rules>
                 <requireNoRepositories>
-                  <allowedRepositories>com.asual.maven.public</allowedRepositories>
+                  <allowedRepositories>
+                    <allowedRepository>com.asual.maven.public</allowedRepository>
+                  </allowedRepositories>
                 </requireNoRepositories>
               </rules>
             </configuration>
diff --git a/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/pom.xml b/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/pom.xml
index 4951265..557a44c 100644
--- a/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/pom.xml
+++ b/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/pom.xml
@@ -58,7 +58,10 @@
             <configuration>
               <rules>
                 <requireNoRepositories>
-                  <allowedPluginRepositories>plugin-repo,com.asual.maven.public</allowedPluginRepositories>
+                  <allowedPluginRepositories>
+                    <allowedPluginRepository>plugin-repo</allowedPluginRepository>
+                    <allowedPluginRepository>com.asual.maven.public</allowedPluginRepository>
+                  </allowedPluginRepositories>
                 </requireNoRepositories>
               </rules>
             </configuration>
diff --git a/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/pom.xml b/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/pom.xml
index ba8a6a7..cc568e2 100644
--- a/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/pom.xml
+++ b/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/pom.xml
@@ -58,7 +58,9 @@
             <configuration>
               <rules>
                 <requireNoRepositories>
-                  <allowedPluginRepositories>plugin-repo</allowedPluginRepositories>
+                  <allowedPluginRepositories>
+                    <allowedPluginRepository>plugin-repo</allowedPluginRepository>
+                  </allowedPluginRepositories>
                 </requireNoRepositories>
               </rules>
             </configuration>

Reply | Threaded
Open this post in threaded view
|

[maven-enforcer] 02/03: [MENFORCER-315] - Add thirdparty rules page to the enforcer site o Add thirdparty-rules page to site for enumerating thirdparty Maven Enforcer rules; o Add link to Sonatype OSS Index rules documentation

khmarbaise
In reply to this post by 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 5d7439513a7b6007fa02570bcbd4506aa14919c0
Author: Jason Dillon <[hidden email]>
AuthorDate: Mon Aug 27 16:31:47 2018 -0700

    [MENFORCER-315] - Add thirdparty rules page to the enforcer site
     o Add thirdparty-rules page to site for enumerating thirdparty Maven Enforcer rules;
     o Add link to Sonatype OSS Index rules documentation
---
 .../src/site/apt/thirdparty-rules.apt              | 28 ++++++++++++++++++++++
 maven-enforcer-plugin/src/site/site.xml            |  1 +
 2 files changed, 29 insertions(+)

diff --git a/maven-enforcer-plugin/src/site/apt/thirdparty-rules.apt b/maven-enforcer-plugin/src/site/apt/thirdparty-rules.apt
new file mode 100644
index 0000000..515925b
--- /dev/null
+++ b/maven-enforcer-plugin/src/site/apt/thirdparty-rules.apt
@@ -0,0 +1,28 @@
+~~ Licensed to the Apache Software Foundation (ASF) under one
+~~ or more contributor license agreements.  See the NOTICE file
+~~ distributed with this work for additional information
+~~ regarding copyright ownership.  The ASF licenses this file
+~~ to you under the Apache License, Version 2.0 (the
+~~ "License"); you may not use this file except in compliance
+~~ with the License.  You may obtain a copy of the License at
+~~
+~~ http://www.apache.org/licenses/LICENSE-2.0
+~~
+~~ Unless required by applicable law or agreed to in writing,
+~~ software distributed under the License is distributed on an
+~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+~~ KIND, either express or implied.  See the License for the
+~~ specific language governing permissions and limitations
+~~ under the License.    
+
+  ------
+  Thirdparty Rules
+  ------
+  Jason Dillon
+  ------
+  2018-08-27
+  ------
+
+Thirdparty Rules
+
+  * {{{https://sonatype.github.io/ossindex-maven/enforcer-rules/}Sonatype OSS Index - Ban Vulnerable Dependencies}}
diff --git a/maven-enforcer-plugin/src/site/site.xml b/maven-enforcer-plugin/src/site/site.xml
index 9caae07..06e160e 100644
--- a/maven-enforcer-plugin/src/site/site.xml
+++ b/maven-enforcer-plugin/src/site/site.xml
@@ -29,6 +29,7 @@ under the License.
       <item name="Usage" href="usage.html"/>
       <item name="FAQ" href="faq.html"/>
       <item name="Built-In Rules" href="../../enforcer/enforcer-rules/index.html"/>
+      <item name="Thirdparty Rules" href="thirdparty-rules.html"/>
       <!-- According to https://issues.apache.org/jira/browse/MNGSITE-152 -->
       <item name="License" href="http://www.apache.org/licenses/"/>
       <item name="Download" href="../download.html"/>

Reply | Threaded
Open this post in threaded view
|

[maven-enforcer] 03/03: [MENFORCER-317] - Fix RequireFileChecksum ignores configured message - Introduce configurable message for nonexistent file - Including small refactoring: extract checksum calculation into private method.

khmarbaise
In reply to this post by 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 3f397b19377e5e3655d38cd3b2a4e27aeedafa8c
Author: Falko Modler <[hidden email]>
AuthorDate: Tue Sep 4 23:44:32 2018 +0200

    [MENFORCER-317] - Fix RequireFileChecksum ignores configured message
     - Introduce configurable message for nonexistent file
     - Including small refactoring: extract checksum calculation into private method.
---
 .../plugins/enforcer/RequireFileChecksum.java      | 118 ++++++++++++++-------
 .../plugins/enforcer/TestRequireFileChecksum.java  |  60 ++++++++++-
 2 files changed, 136 insertions(+), 42 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..1a4c160 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
@@ -45,6 +45,8 @@ public class RequireFileChecksum
 
     private String type;
 
+    private String nonexistentFileMessage;
+
     @Override
     public void execute( EnforcerRuleHelper helper )
         throws EnforcerRuleException
@@ -64,53 +66,38 @@ public class RequireFileChecksum
             throw new EnforcerRuleException( "Checksum unspecified" );
         }
 
-        InputStream inputStream = null;
-        try
+        if ( !this.file.exists() )
         {
-            if ( this.file.isDirectory() || !this.file.canRead() )
+            String message = nonexistentFileMessage;
+            if ( message == null )
             {
-                throw new EnforcerRuleException( "Cannot read file: " + this.file.getAbsolutePath() );
+                message = "File does not exist: " + this.file.getAbsolutePath();
             }
+            throw new EnforcerRuleException( message );
+        }
 
-            inputStream = new FileInputStream( this.file );
-            String checksum;
-            if ( "md5".equals( this.type ) )
-            {
-                checksum = DigestUtils.md5Hex( inputStream );
-            }
-            else if ( "sha1".equals( this.type ) )
-            {
-                checksum = DigestUtils.shaHex( inputStream );
-            }
-            else if ( "sha256".equals( this.type ) )
-            {
-                checksum = DigestUtils.sha256Hex( inputStream );
-            }
-            else if ( "sha384".equals( this.type ) )
-            {
-                checksum = DigestUtils.sha384Hex( inputStream );
-            }
-            else if ( "sha512".equals( this.type ) )
-            {
-                checksum = DigestUtils.sha512Hex( inputStream );
-            }
-            else
-            {
-                throw new EnforcerRuleException( "Unsupported hash type: " + this.type );
-            }
-            if ( !checksum.equalsIgnoreCase( this.checksum ) )
-            {
-                throw new EnforcerRuleException( this.type + " hash of " + this.file + " was " + checksum
-                    + " but expected " + this.checksum );
-            }
+        if ( this.file.isDirectory() )
+        {
+            throw new EnforcerRuleException( "Cannot calculate the checksum of directory: "
+                + this.file.getAbsolutePath() );
         }
-        catch ( IOException e )
+
+        if ( !this.file.canRead() )
         {
-            throw new EnforcerRuleException( "Unable to calculate checksum", e );
+            throw new EnforcerRuleException( "Cannot read file: " + this.file.getAbsolutePath() );
         }
-        finally
+
+        String checksum = calculateChecksum();
+
+        if ( !checksum.equalsIgnoreCase( this.checksum ) )
         {
-            IOUtil.close( inputStream );
+            String exceptionMessage = getMessage();
+            if ( exceptionMessage == null )
+            {
+                exceptionMessage = this.type + " hash of " + this.file + " was " + checksum
+                    + " but expected " + this.checksum;
+            }
+            throw new EnforcerRuleException( exceptionMessage );
         }
     }
 
@@ -144,4 +131,57 @@ public class RequireFileChecksum
         this.type = type;
     }
 
+    /**
+     * The friendly message to use when the file does not exist.
+     *
+     * @param nonexistentFileMessage message
+     */
+    public void setNonexistentFileMessage( String nonexistentFileMessage )
+    {
+        this.nonexistentFileMessage = nonexistentFileMessage;
+    }
+
+    private String calculateChecksum()
+        throws EnforcerRuleException
+    {
+        InputStream inputStream = null;
+        try
+        {
+            inputStream = new FileInputStream( this.file );
+            String checksum;
+            if ( "md5".equals( this.type ) )
+            {
+                checksum = DigestUtils.md5Hex( inputStream );
+            }
+            else if ( "sha1".equals( this.type ) )
+            {
+                checksum = DigestUtils.shaHex( inputStream );
+            }
+            else if ( "sha256".equals( this.type ) )
+            {
+                checksum = DigestUtils.sha256Hex( inputStream );
+            }
+            else if ( "sha384".equals( this.type ) )
+            {
+                checksum = DigestUtils.sha384Hex( inputStream );
+            }
+            else if ( "sha512".equals( this.type ) )
+            {
+                checksum = DigestUtils.sha512Hex( inputStream );
+            }
+            else
+            {
+                throw new EnforcerRuleException( "Unsupported hash type: " + this.type );
+            }
+            return checksum;
+        }
+        catch ( IOException e )
+        {
+            throw new EnforcerRuleException( "Unable to calculate checksum", e );
+        }
+        finally
+        {
+            IOUtil.close( inputStream );
+        }
+    }
 }
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..c7075ce 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
@@ -74,10 +74,45 @@ public class TestRequireFileChecksum
     }
 
     @Test
-    public void testFileChecksumMd5NoFileFailure()
+    public void testFileChecksumMd5GivenFileDoesNotExistFailure()
         throws IOException, EnforcerRuleException
     {
-        File f = new File( "foo" )
+        File f = new File( "nonExistent" );
+
+        expectedException.expect( EnforcerRuleException.class );
+        expectedException.expectMessage( "File does not exist: " + f.getAbsolutePath() );
+
+        rule.setFile( f );
+        rule.setChecksum( "78e731027d8fd50ed642340b7c9a63b3" );
+        rule.setType( "md5" );
+
+        rule.execute( EnforcerTestUtils.getHelper() );
+    }
+
+    @Test
+    public void testFileChecksumMd5GivenFileDoesNotExistFailureWithMessage()
+        throws IOException, EnforcerRuleException
+    {
+        File f = new File( "nonExistent" );
+        String configuredMessage = "testMessageFileDoesNotExist";
+
+        expectedException.expect( EnforcerRuleException.class );
+        expectedException.expectMessage( configuredMessage );
+
+        rule.setFile( f );
+        rule.setChecksum( "78e731027d8fd50ed642340b7c9a63b3" );
+        rule.setType( "md5" );
+        rule.setNonexistentFileMessage( configuredMessage );
+
+        rule.execute( EnforcerTestUtils.getHelper() );
+    }
+
+    @Test
+    public void testFileChecksumMd5GivenFileIsNotReadableFailure()
+        throws IOException, EnforcerRuleException
+    {
+        File f = temporaryFolder.newFile();
+        f = new File( f.getAbsolutePath() )
         {
             private static final long serialVersionUID = 6987790643999338089L;
 
@@ -105,7 +140,7 @@ public class TestRequireFileChecksum
         File f = temporaryFolder.newFolder();
 
         expectedException.expect( EnforcerRuleException.class );
-        expectedException.expectMessage( "Cannot read file: " + f.getAbsolutePath() );
+        expectedException.expectMessage( "Cannot calculate the checksum of directory: " + f.getAbsolutePath() );
 
         rule.setFile( f );
         rule.setChecksum( "78e731027d8fd50ed642340b7c9a63b3" );
@@ -176,6 +211,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
     {