[maven-enforcer] branch MENFORCER-306 updated (1549f75 -> e81e131)

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

[maven-enforcer] branch MENFORCER-306 updated (1549f75 -> e81e131)

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

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


 discard 1549f75  WIP - [MENFORCER-306] - [REGRESSION] RequirePluginVersions fails  o Added some debugging output  o Added first implementation which is not final yet.  o Added simple IT's for this case.  o Make it Maven 3.0.5 compatible.  o Changed IT's according to parameter definition with List.
 discard 69e3212  Added fixed.
 discard 5071042  Added more debug.
 discard 6c1358f  Added some debugging output.
     add 32c6034  [INFRA-16467] move components documentation out of CMS space
     add 100eb8c  [MNGSITE-341] use https for sigs, hashes and KEYS
     add fd64d87  [MPOM-205] use sha512 checksums instead of sha1
     add 7b02571  Changed configuration for allowedPluginRepositories
     add df77932  [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
     add 208c5c7  [MENFORCER-317] - Fix RequireFileChecksum ignores configured message  - Introduce configurable message for nonexistent file  - Including small refactoring: extract checksum calculation into private method.
     add caef332  [MENFORCER-320] - RequireProfileIdsExist check fails if no profiles have been specified  - RequireProfileIdsExist check must not fail if there are no profiles    in the pom.xml and no profiles have been specified in the command line  - fix site: breadcrumbs on the "requireProfileIdsExist" page.
     add 02ab1b2  [MENFORCER-312] - Upgrade maven-parent to 33
     add 3f49c2f  Removed $Id$ from SVN
     new 49c2ad7  Added some debugging output.
     new 1e99225  Added more debug.
     new 9e52063  Added fixed.
     new 597b19c  WIP - [MENFORCER-306] - [REGRESSION] RequirePluginVersions fails  o Added some debugging output  o Added first implementation which is not final yet.  o Added simple IT's for this case.  o Make it Maven 3.0.5 compatible.  o Changed IT's according to parameter definition with List.
     new e81e131  Code improvement.

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   (1549f75)
            \
             N -- N -- N   refs/heads/MENFORCER-306 (e81e131)

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 5 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/enforcer/rule/api/EnforcerRule.java      |   1 -
 .../maven/enforcer/rule/api/EnforcerRule2.java     |   1 -
 .../plugins/enforcer/AbstractBanDependencies.java  |   1 -
 .../enforcer/AbstractNonCacheableEnforcerRule.java |   1 -
 .../enforcer/AbstractPropertyEnforcerRule.java     |   1 -
 .../plugins/enforcer/AbstractVersionEnforcer.java  |   1 -
 .../maven/plugins/enforcer/BannedDependencies.java |   1 -
 .../enforcer/DefaultEnforcementRuleHelper.java     |   1 -
 .../plugins/enforcer/RequireFileChecksum.java      | 118 ++++++++++++++-------
 .../maven/plugins/enforcer/RequireJavaVersion.java |   1 -
 .../plugins/enforcer/RequireMavenVersion.java      |   1 -
 .../apache/maven/plugins/enforcer/RequireOS.java   |   1 -
 .../plugins/enforcer/RequirePluginVersions.java    |  20 ++--
 .../plugins/enforcer/RequireProfileIdsExist.java   |  12 +--
 .../maven/plugins/enforcer/RequireReleaseDeps.java |   1 -
 .../src/site/apt/requireProfileIdsExist.apt.vm     |   2 +-
 .../plugins/enforcer/TestRequireFileChecksum.java  |  60 ++++++++++-
 maven-enforcer-plugin/pom.xml                      |   4 +
 .../maven/plugins/enforcer/DisplayInfoMojo.java    |   1 -
 .../apache/maven/plugins/enforcer/EnforceMojo.java |   1 -
 .../src/site/apt/thirdparty-rules.apt              |  14 +--
 maven-enforcer-plugin/src/site/site.xml            |   1 +
 pom.xml                                            |   7 +-
 src/site/xdoc/download.xml.vm                      |   6 +-
 24 files changed, 173 insertions(+), 85 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/05: Added some debugging output.

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

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

commit 49c2ad796e94b02150b95075f98481bde64717bc
Author: Karl Heinz Marbaise <[hidden email]>
AuthorDate: Tue Jun 19 17:58:07 2018 +0200

    Added some debugging output.
---
 .../plugins/enforcer/RequirePluginVersions.java    | 62 +++++++++++++---------
 1 file changed, 38 insertions(+), 24 deletions(-)

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
index f3df358..09923c9 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
@@ -79,7 +79,7 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 public class RequirePluginVersions
     extends AbstractNonCacheableEnforcerRule
 {
-    
+
     private EnforcerRuleHelper helper;
 
     /**
@@ -234,6 +234,12 @@ public class RequirePluginVersions
             allPlugins =
                 removeUncheckedPlugins( combineUncheckedPlugins( unCheckedPlugins, unCheckedPluginList ), allPlugins );
 
+            for ( Plugin plugin : allPlugins )
+            {
+                log.debug( "allPlugins(): " + plugin.getGroupId() + ":" + plugin.getArtifactId() + ":"
+                    + plugin.getVersion() );
+            }
+
             // there's nothing to do here
             if ( allPlugins.isEmpty() )
             {
@@ -248,12 +254,19 @@ public class RequirePluginVersions
             // get all the plugins that are mentioned in the pom (and parents)
             List<PluginWrapper> pluginWrappers = getAllPluginEntries( project );
 
+            for ( PluginWrapper pluginWrapper : pluginWrappers )
+            {
+                log.debug( "pluginWrappers: " + pluginWrapper.getGroupId() + ":" + pluginWrapper.getArtifactId() + ":"
+                    + pluginWrapper.getVersion() + " source:" + pluginWrapper.getSource() );
+            }
             // now look for the versions that aren't valid and add to a list.
             List<Plugin> failures = new ArrayList<Plugin>();
             for ( Plugin plugin : allPlugins )
             {
                 if ( !hasValidVersionSpecified( helper, plugin, pluginWrappers ) )
                 {
+                    log.debug( "hasValidVersionSpecified(): " + plugin.getGroupId() + ":" + plugin.getArtifactId() + ":"
+                        + plugin.getVersion() );
                     failures.add( plugin );
                 }
             }
@@ -391,7 +404,8 @@ public class RequirePluginVersions
      * @return List of unchecked plugins.
      */
     // CHECKSTYLE_OFF: LineLength
-    public Collection<String> combineUncheckedPlugins( Collection<String> uncheckedPlugins, String uncheckedPluginsList )
+    public Collection<String> combineUncheckedPlugins( Collection<String> uncheckedPlugins,
+                                                       String uncheckedPluginsList )
     // CHECKSTYLE_ON: LineLength
     {
         // if the comma list is empty, then there's nothing to do here.
@@ -545,9 +559,8 @@ public class RequirePluginVersions
     {
 
         List<ArtifactRepository> pluginRepositories = project.getPluginArtifactRepositories();
-        Artifact artifact =
-            factory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(),
-                                          VersionRange.createFromVersion( "LATEST" ) );
+        Artifact artifact = factory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(),
+                                                          VersionRange.createFromVersion( "LATEST" ) );
 
         try
         {
@@ -556,11 +569,11 @@ public class RequirePluginVersions
         }
         catch ( ArtifactResolutionException e )
         {
-            //What does this mean?
+            // What does this mean?
         }
         catch ( ArtifactNotFoundException e )
         {
-            //What does this mean?
+            // What does this mean?
         }
 
         return plugin;
@@ -594,6 +607,8 @@ public class RequirePluginVersions
                 try
                 {
                     Lifecycle lifecycle = getLifecycleForPhase( lifecyclePhase );
+                    log.debug( "getBoundPlugins(): " + project.getId() + " " + lifecyclePhase + " "
+                        + lifecycle.getId() );
                     allPlugins.addAll( getAllPlugins( project, lifecycle ) );
                 }
                 catch ( BuildFailureException e )
@@ -782,6 +797,7 @@ public class RequirePluginVersions
                 List<String> phases = lifecycle.getPhases();
                 for ( String phase : phases )
                 {
+                    log.debug( "getPhaseToLifecycleMap(): phase: " + phase );
                     if ( phaseToLifecycleMap.containsKey( phase ) )
                     {
                         Lifecycle prevLifecycle = (Lifecycle) phaseToLifecycleMap.get( phase );
@@ -834,9 +850,8 @@ public class RequirePluginVersions
         String packaging = project.getPackaging();
         Map<String, String> mappings = null;
 
-        LifecycleMapping m =
-            (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session.getSettings(),
-                                              session.getLocalRepository() );
+        LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging,
+                                                               session.getSettings(), session.getLocalRepository() );
         if ( m != null )
         {
             mappings = m.getPhases( lifecycle.getId() );
@@ -855,8 +870,8 @@ public class RequirePluginVersions
             {
                 if ( defaultMappings == null )
                 {
-                    throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'"
-                        + packaging + "\'.", e );
+                    throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging
+                        + "\'.", e );
                 }
             }
         }
@@ -892,9 +907,8 @@ public class RequirePluginVersions
         String packaging = project.getPackaging();
         List<String> optionalMojos = null;
 
-        LifecycleMapping m =
-            (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session.getSettings(),
-                                              session.getLocalRepository() );
+        LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging,
+                                                               session.getSettings(), session.getLocalRepository() );
 
         if ( m != null )
         {
@@ -911,7 +925,7 @@ public class RequirePluginVersions
             catch ( ComponentLookupException e )
             {
                 log.debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: "
-                               + lifecycle.getId() + ". Error: " + e.getMessage(), e );
+                    + lifecycle.getId() + ". Error: " + e.getMessage(), e );
             }
         }
 
@@ -1045,13 +1059,13 @@ public class RequirePluginVersions
         // get all the pom models
 
         List<Model> models = new ArrayList<Model>();
-        
+
         List<MavenProject> sortedProjects = session.getProjectDependencyGraph().getSortedProjects();
         for ( MavenProject mavenProject : sortedProjects )
         {
             models.add( mavenProject.getOriginalModel() );
         }
-                        
+
         // now find all the plugin entries, either in
         // build.plugins or build.pluginManagement.plugins, profiles.plugins and reporting
         for ( Model model : models )
@@ -1059,8 +1073,8 @@ public class RequirePluginVersions
             try
             {
                 List<Plugin> modelPlugins = model.getBuild().getPlugins();
-                plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId()
-                    + ".build.plugins" ) );
+                plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ),
+                                                      model.getId() + ".build.plugins" ) );
             }
             catch ( NullPointerException e )
             {
@@ -1071,8 +1085,8 @@ public class RequirePluginVersions
             {
                 List<ReportPlugin> modelReportPlugins = model.getReporting().getPlugins();
                 // add the reporting plugins
-                plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ), model.getId()
-                    + ".reporting" ) );
+                plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ),
+                                                      model.getId() + ".reporting" ) );
             }
             catch ( NullPointerException e )
             {
@@ -1082,8 +1096,8 @@ public class RequirePluginVersions
             try
             {
                 List<Plugin> modelPlugins = model.getBuild().getPluginManagement().getPlugins();
-                plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId()
-                    + ".build.pluginManagement.plugins" ) );
+                plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ),
+                                                      model.getId() + ".build.pluginManagement.plugins" ) );
             }
             catch ( NullPointerException e )
             {

Reply | Threaded
Open this post in threaded view
|

[maven-enforcer] 02/05: Added more debug.

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-306
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git

commit 1e99225a9accb978a2f66145feb7fe58d2356715
Author: Karl Heinz Marbaise <[hidden email]>
AuthorDate: Tue Aug 7 22:01:06 2018 +0200

    Added more debug.
---
 .../org/apache/maven/plugins/enforcer/RequirePluginVersions.java  | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
index 09923c9..f48fcbd 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
@@ -263,10 +263,12 @@ public class RequirePluginVersions
             List<Plugin> failures = new ArrayList<Plugin>();
             for ( Plugin plugin : allPlugins )
             {
+                log.debug( "hasValidVersionSpecified(1): " + plugin.getGroupId() + ":" + plugin.getArtifactId() + ":"
+                    + plugin.getVersion() );
                 if ( !hasValidVersionSpecified( helper, plugin, pluginWrappers ) )
                 {
-                    log.debug( "hasValidVersionSpecified(): " + plugin.getGroupId() + ":" + plugin.getArtifactId() + ":"
-                        + plugin.getVersion() );
+                    log.debug( "hasValidVersionSpecified(1): " + plugin.getGroupId() + ":" + plugin.getArtifactId()
+                        + ":" + plugin.getVersion() );
                     failures.add( plugin );
                 }
             }
@@ -659,7 +661,7 @@ public class RequirePluginVersions
 
                 if ( StringUtils.isNotEmpty( version ) && !StringUtils.isWhitespace( version ) )
                 {
-
+                    log.debug( "checking for notEmpty and notIsWhiespace(): " + version );
                     if ( banRelease && version.equals( "RELEASE" ) )
                     {
                         return false;

Reply | Threaded
Open this post in threaded view
|

[maven-enforcer] 03/05: Added fixed.

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-306
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git

commit 9e520632b32c9c502ca1f36e0fb6386a78fdb58a
Author: Karl Heinz Marbaise <[hidden email]>
AuthorDate: Tue Aug 14 11:35:53 2018 +0200

    Added fixed.
---
 .../apache/maven/plugins/enforcer/TestRequirePluginVersions.java | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java
index 422967d..5b9c157 100644
--- a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java
+++ b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java
@@ -1,5 +1,8 @@
 package org.apache.maven.plugins.enforcer;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -28,6 +31,7 @@ import java.util.Set;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.plugins.enforcer.utils.PluginWrapper;
 
@@ -80,7 +84,10 @@ public class TestRequirePluginVersions
         rule.setBanRelease( false );
         rule.setBanSnapshots( false );
 
+
         EnforcerRuleHelper helper = EnforcerTestUtils.getHelper();
+        Log log = mock( Log.class );
+        when( helper.getLog() ).thenReturn( log );
 
         assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) );
 
@@ -144,6 +151,8 @@ public class TestRequirePluginVersions
         rule.setBanSnapshots( false );
 
         EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( true );
+        Log log = mock( Log.class );
+        when( helper.getLog() ).thenReturn( log );
 
         source.setArtifactId( "a-artifact" );
         assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) );

Reply | Threaded
Open this post in threaded view
|

[maven-enforcer] 04/05: WIP - [MENFORCER-306] - [REGRESSION] RequirePluginVersions fails o Added some debugging output o Added first implementation which is not final yet. o Added simple IT's for this case. o Make it Maven 3.0.5 compatible. o Changed IT's according to parameter definition with List.

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-306
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git

commit 597b19cf4ed52501777d0ec3b39abb90367eaff9
Author: Karl Heinz Marbaise <[hidden email]>
AuthorDate: Thu Aug 16 22:31:13 2018 +0200

    WIP - [MENFORCER-306] - [REGRESSION] RequirePluginVersions fails
     o Added some debugging output
     o Added first implementation which is not final yet.
     o Added simple IT's for this case.
     o Make it Maven 3.0.5 compatible.
     o Changed IT's according to parameter definition with List.
---
 .../plugins/enforcer/RequirePluginVersions.java    | 187 ++++++++++++---------
 .../enforcer/TestRequirePluginVersions.java        |   8 -
 .../src/it/projects/MENFORCER-306/parent/pom.xml   | 103 ++++++++++++
 .../src/it/projects/MENFORCER-306/pom.xml          |  31 ++++
 4 files changed, 246 insertions(+), 83 deletions(-)

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
index f48fcbd..383f60e 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
@@ -267,7 +267,7 @@ public class RequirePluginVersions
                     + plugin.getVersion() );
                 if ( !hasValidVersionSpecified( helper, plugin, pluginWrappers ) )
                 {
-                    log.debug( "hasValidVersionSpecified(1): " + plugin.getGroupId() + ":" + plugin.getArtifactId()
+                    log.debug( "hasValidVersionSpecified(2): " + plugin.getGroupId() + ":" + plugin.getArtifactId()
                         + ":" + plugin.getVersion() );
                     failures.add( plugin );
                 }
@@ -661,7 +661,7 @@ public class RequirePluginVersions
 
                 if ( StringUtils.isNotEmpty( version ) && !StringUtils.isWhitespace( version ) )
                 {
-                    log.debug( "checking for notEmpty and notIsWhiespace(): " + version );
+                    helper.getLog().debug( "checking for notEmpty and notIsWhiespace(): " + version );
                     if ( banRelease && version.equals( "RELEASE" ) )
                     {
                         return false;
@@ -692,7 +692,7 @@ public class RequirePluginVersions
         }
         if ( !found )
         {
-            log.debug( "plugin " + source.getGroupId() + ":" + source.getArtifactId() + " not found" );
+            helper.getLog().debug( "plugin " + source.getGroupId() + ":" + source.getArtifactId() + " not found" );
         }
         return status;
     }
@@ -1043,6 +1043,7 @@ public class RequirePluginVersions
         return pluginDescriptor;
     }
 
+    
     /**
      * Gets all plugin entries in build.plugins, build.pluginManagement.plugins, profile.build.plugins, reporting and
      * profile.reporting in this project and all parents
@@ -1057,96 +1058,132 @@ public class RequirePluginVersions
     protected List<PluginWrapper> getAllPluginEntries( MavenProject project )
         throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException
     {
-        List<PluginWrapper> plugins = new ArrayList<PluginWrapper>();
-        // get all the pom models
-
         List<Model> models = new ArrayList<Model>();
 
         List<MavenProject> sortedProjects = session.getProjectDependencyGraph().getSortedProjects();
+
+        if ( sortedProjects.size() > 0 && sortedProjects.get( 0 ).getParent() != null )
+        {
+            MavenProject mp = sortedProjects.get( 0 ).getParent();
+            models.add( mp.getOriginalModel() );
+        }
+
         for ( MavenProject mavenProject : sortedProjects )
         {
             models.add( mavenProject.getOriginalModel() );
         }
 
+        List<PluginWrapper> plugins = new ArrayList<PluginWrapper>();
+        
         // now find all the plugin entries, either in
         // build.plugins or build.pluginManagement.plugins, profiles.plugins and reporting
         for ( Model model : models )
         {
-            try
-            {
-                List<Plugin> modelPlugins = model.getBuild().getPlugins();
-                plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ),
-                                                      model.getId() + ".build.plugins" ) );
-            }
-            catch ( NullPointerException e )
-            {
-                // guess there are no plugins here.
-            }
+            getPlugins( plugins, model );
+            getReportingPlugins( plugins, model );
+            getPluginManagementPlugins( plugins, model );
 
-            try
-            {
-                List<ReportPlugin> modelReportPlugins = model.getReporting().getPlugins();
-                // add the reporting plugins
-                plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ),
-                                                      model.getId() + ".reporting" ) );
-            }
-            catch ( NullPointerException e )
-            {
-                // guess there are no plugins here.
-            }
+            addPluginsInProfiles( plugins, model );
+        }
 
-            try
-            {
-                List<Plugin> modelPlugins = model.getBuild().getPluginManagement().getPlugins();
-                plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ),
-                                                      model.getId() + ".build.pluginManagement.plugins" ) );
-            }
-            catch ( NullPointerException e )
-            {
-                // guess there are no plugins here.
-            }
+        return plugins;
+    }
 
-            // Add plugins in profiles
-            List<Profile> profiles = model.getProfiles();
-            for ( Profile profile : profiles )
-            {
-                try
-                {
-                    List<Plugin> modelPlugins = profile.getBuild().getPlugins();
-                    plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId()
-                        + ".profiles.profile[" + profile.getId() + "].build.plugins" ) );
-                }
-                catch ( NullPointerException e )
-                {
-                    // guess there are no plugins here.
-                }
+    private void addPluginsInProfiles( List<PluginWrapper> plugins, Model model )
+    {
+        List<Profile> profiles = model.getProfiles();
+        for ( Profile profile : profiles )
+        {
+            getProfilePlugins( plugins, model, profile );
+            getProfileReportingPlugins( plugins, model, profile );
+            getProfilePluginManagementPlugins( plugins, model, profile );
+        }
+    }
 
-                try
-                {
-                    List<ReportPlugin> modelReportPlugins = profile.getReporting().getPlugins();
-                    // add the reporting plugins
-                    plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ),
-                                                          model.getId() + "profile[" + profile.getId()
-                                                              + "].reporting.plugins" ) );
-                }
-                catch ( NullPointerException e )
-                {
-                    // guess there are no plugins here.
-                }
-                try
-                {
-                    List<Plugin> modelPlugins = profile.getBuild().getPluginManagement().getPlugins();
-                    plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId()
-                        + "profile[" + profile.getId() + "].build.pluginManagement.plugins" ) );
-                }
-                catch ( NullPointerException e )
-                {
-                    // guess there are no plugins here.
-                }
-            }
+    private void getProfilePluginManagementPlugins( List<PluginWrapper> plugins, Model model, Profile profile )
+    {
+        try
+        {
+            List<Plugin> modelPlugins = profile.getBuild().getPluginManagement().getPlugins();
+            plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId() + "profile["
+                + profile.getId() + "].build.pluginManagement.plugins" ) );
         }
+        catch ( NullPointerException e )
+        {
+            // guess there are no plugins here.
+        }
+    }
 
-        return plugins;
+    private void getProfileReportingPlugins( List<PluginWrapper> plugins, Model model, Profile profile )
+    {
+        try
+        {
+            List<ReportPlugin> modelReportPlugins = profile.getReporting().getPlugins();
+            // add the reporting plugins
+            plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ), model.getId()
+                + "profile[" + profile.getId() + "].reporting.plugins" ) );
+        }
+        catch ( NullPointerException e )
+        {
+            // guess there are no plugins here.
+        }
+    }
+
+    private void getProfilePlugins( List<PluginWrapper> plugins, Model model, Profile profile )
+    {
+        try
+        {
+            List<Plugin> modelPlugins = profile.getBuild().getPlugins();
+            plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId()
+                + ".profiles.profile[" + profile.getId() + "].build.plugins" ) );
+        }
+        catch ( NullPointerException e )
+        {
+            // guess there are no plugins here.
+        }
+    }
+
+    private void getPlugins( List<PluginWrapper> plugins, Model model )
+    {
+        try
+        {
+            List<Plugin> modelPlugins = model.getBuild().getPlugins();
+            plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ),
+                                                  model.getId() + ".build.plugins" ) );
+        }
+        catch ( NullPointerException e )
+        {
+            // guess there are no plugins here.
+        }
+    }
+
+    private void getPluginManagementPlugins( List<PluginWrapper> plugins, Model model )
+    {
+        try
+        {
+            List<Plugin> modelPlugins = model.getBuild().getPluginManagement().getPlugins();
+            plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ),
+                                                  model.getId() + ".build.pluginManagement.plugins" ) );
+        }
+        catch ( NullPointerException e )
+        {
+            // guess there are no plugins here.
+        }
+    }
+
+    private void getReportingPlugins( List<PluginWrapper> plugins, Model model )
+    {
+        try
+        {
+            List<ReportPlugin> modelReportPlugins = model.getReporting().getPlugins();
+            // add the reporting plugins
+            plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ),
+                                                  model.getId() + ".reporting" ) );
+        }
+        catch ( NullPointerException e )
+        {
+            // guess there are no plugins here.
+        }
     }
 
     /**
diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java
index 5b9c157..64290af 100644
--- a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java
+++ b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java
@@ -1,8 +1,5 @@
 package org.apache.maven.plugins.enforcer;
 
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -31,7 +28,6 @@ import java.util.Set;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.plugins.enforcer.utils.PluginWrapper;
 
@@ -86,8 +82,6 @@ public class TestRequirePluginVersions
 
 
         EnforcerRuleHelper helper = EnforcerTestUtils.getHelper();
-        Log log = mock( Log.class );
-        when( helper.getLog() ).thenReturn( log );
 
         assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) );
 
@@ -151,8 +145,6 @@ public class TestRequirePluginVersions
         rule.setBanSnapshots( false );
 
         EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( true );
-        Log log = mock( Log.class );
-        when( helper.getLog() ).thenReturn( log );
 
         source.setArtifactId( "a-artifact" );
         assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) );
diff --git a/maven-enforcer-plugin/src/it/projects/MENFORCER-306/parent/pom.xml b/maven-enforcer-plugin/src/it/projects/MENFORCER-306/parent/pom.xml
new file mode 100644
index 0000000..d66827e
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/MENFORCER-306/parent/pom.xml
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>mbenson.test</groupId>
+  <artifactId>test-require-plugin-versions</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  <properties>
+    <enforcer.version>3.0.0-SNAPSHOT</enforcer.version>
+  </properties>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>enforce-plugin-versions</id>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <configuration>
+              <rules>
+                <requirePluginVersions>
+                  <banSnapshots>false</banSnapshots>
+                </requirePluginVersions>
+              </rules>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-clean-plugin</artifactId>
+          <version>3.1.0</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-install-plugin</artifactId>
+          <version>2.5.2</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-site-plugin</artifactId>
+          <version>3.7.1</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-deploy-plugin</artifactId>
+          <version>2.8.2</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.7.0</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-plugin-plugin</artifactId>
+          <version>3.5.2</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>2.21.0</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>3.1.0</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-resources-plugin</artifactId>
+          <version>3.1.0</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>
diff --git a/maven-enforcer-plugin/src/it/projects/MENFORCER-306/pom.xml b/maven-enforcer-plugin/src/it/projects/MENFORCER-306/pom.xml
new file mode 100644
index 0000000..9ad1574
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/MENFORCER-306/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>mbenson.test</groupId>
+    <artifactId>test-require-plugin-versions</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <relativePath>parent/pom.xml</relativePath>
+  </parent>
+  <artifactId>pom</artifactId>
+  <packaging>pom</packaging>
+</project>

Reply | Threaded
Open this post in threaded view
|

[maven-enforcer] 05/05: Code improvement.

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-306
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git

commit e81e13178ae3ea153a0d0c5936ca951b71a73bc3
Author: Karl Heinz Marbaise <[hidden email]>
AuthorDate: Sun Oct 7 17:33:56 2018 +0200

    Code improvement.
---
 .../maven/plugins/enforcer/RequirePluginVersions.java | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
index 383f60e..a005365 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
@@ -644,8 +644,7 @@ public class RequirePluginVersions
         for ( PluginWrapper plugin : pluginWrappers )
         {
             // find the matching plugin entry
-            if ( source.getArtifactId().equals( plugin.getArtifactId() )
-                && source.getGroupId().equals( plugin.getGroupId() ) )
+            if ( isMatchingPlugin( source, plugin ) )
             {
                 found = true;
                 // found the entry. now see if the version is specified
@@ -659,7 +658,7 @@ public class RequirePluginVersions
                     return false;
                 }
 
-                if ( StringUtils.isNotEmpty( version ) && !StringUtils.isWhitespace( version ) )
+                if ( isVersion( version ) )
                 {
                     helper.getLog().debug( "checking for notEmpty and notIsWhiespace(): " + version );
                     if ( banRelease && version.equals( "RELEASE" ) )
@@ -697,6 +696,17 @@ public class RequirePluginVersions
         return status;
     }
 
+    private boolean isVersion( String version )
+    {
+        return StringUtils.isNotEmpty( version ) && !StringUtils.isWhitespace( version );
+    }
+
+    private boolean isMatchingPlugin( Plugin source, PluginWrapper plugin )
+    {
+        return source.getArtifactId().equals( plugin.getArtifactId() )
+            && source.getGroupId().equals( plugin.getGroupId() );
+    }
+
     /**
      * Checks if is snapshot.
      *
@@ -1043,7 +1053,6 @@ public class RequirePluginVersions
         return pluginDescriptor;
     }
 
-    
     /**
      * Gets all plugin entries in build.plugins, build.pluginManagement.plugins, profile.build.plugins, reporting and
      * profile.reporting in this project and all parents
@@ -1074,7 +1083,7 @@ public class RequirePluginVersions
         }
 
         List<PluginWrapper> plugins = new ArrayList<PluginWrapper>();
-        
+
         // now find all the plugin entries, either in
         // build.plugins or build.pluginManagement.plugins, profiles.plugins and reporting
         for ( Model model : models )