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

[maven-enforcer] branch MENFORCER-306 updated (d1fbbb8 -> a874e02)

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 d1fbbb8  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.
     new a874e02  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.

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   (d1fbbb8)
            \
             N -- N -- N   refs/heads/MENFORCER-306 (a874e02)

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


Summary of changes:
 maven-enforcer-plugin/pom.xml | 3 +++
 1 file changed, 3 insertions(+)


[maven-enforcer] 01/01: 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.

Posted by kh...@apache.org.
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 a874e0255ffe5742f1f7f3c4b0a75e3711614bfa
Author: Karl Heinz Marbaise <kh...@apache.org>
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.
---
 .../plugins/enforcer/RequirePluginVersions.java    | 177 ++++++++++++---------
 .../enforcer/TestRequirePluginVersions.java        |   8 -
 maven-enforcer-plugin/pom.xml                      |   3 +
 .../src/it/projects/MENFORCER-306/parent/pom.xml   | 103 ++++++++++++
 .../src/it/projects/MENFORCER-306/pom.xml          |  31 ++++
 5 files changed, 242 insertions(+), 80 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 bae55ec..6b97fff 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
@@ -268,7 +268,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 );
                 }
@@ -662,7 +662,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;
@@ -693,7 +693,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;
     }
@@ -1044,6 +1044,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
@@ -1058,98 +1059,130 @@ 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.
-            }
-
-            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.
-            }
-
-            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.
-            }
+            getPlugins( plugins, model );
+            getReportingPlugins( plugins, model );
+            getPluginManagementPlugins( plugins, model );
 
             // 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.
-                }
-
-                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.
-                }
+                getProfilePlugins( plugins, model, profile );
+                getProfileReportingPlugins( plugins, model, profile );
+                getProfilePluginManagementPlugins( plugins, model, profile );
             }
         }
 
         return plugins;
     }
 
+    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.
+        }
+    }
+
+    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.
+        }
+    }
+
     /**
      * Checks if is ban latest.
      *
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/pom.xml b/maven-enforcer-plugin/pom.xml
index 42581d0..efa5e21 100644
--- a/maven-enforcer-plugin/pom.xml
+++ b/maven-enforcer-plugin/pom.xml
@@ -119,6 +119,9 @@
               <goal>helpmojo</goal>
               <goal>descriptor</goal>
             </goals>
+            <configuration>
+              <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+            </configuration>
           </execution>
         </executions>
       </plugin>
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>