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/01/06 19:31:52 UTC

[maven-enforcer] 02/03: [MENFORCER-281] RequirePluginVersions broken with "CI Friendly versions" o Followup o Added selector condition to limit execution to Maven 3.5.0+ o Replaced EnforcerRuleUtils.getModelsRecursively method with session.getProjectDependencyGraph().getSortedProjects() o Removed the testGetAllPlugins() and all related tests cause it only tests the getModelsRecursively method.

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

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

commit 5448dc4a6ceb995da6451d3b8293d25234102d1f
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Sat Jan 6 20:09:35 2018 +0100

    [MENFORCER-281] RequirePluginVersions broken with "CI Friendly versions"
     o Followup
       o Added selector condition to limit execution to Maven 3.5.0+
       o Replaced EnforcerRuleUtils.getModelsRecursively
         method with session.getProjectDependencyGraph().getSortedProjects()
       o Removed the testGetAllPlugins() and all related tests
         cause it only tests the getModelsRecursively method.
---
 .../plugins/enforcer/RequirePluginVersions.java    |  18 +--
 .../plugins/enforcer/utils/EnforcerRuleUtils.java  |  56 -------
 .../enforcer/TestRequirePluginVersions.java        |  38 -----
 .../enforcer/utils/TestEnforcerRuleUtils.java      | 161 ---------------------
 .../invoker.properties                             |   1 +
 5 files changed, 7 insertions(+), 267 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 81ebb5e..9e840da 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
@@ -19,7 +19,6 @@ package org.apache.maven.plugins.enforcer;
  * under the License.
  */
 
-import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
@@ -1046,19 +1045,14 @@ public class RequirePluginVersions
         List<PluginWrapper> plugins = new ArrayList<PluginWrapper>();
         // get all the pom models
 
-        String pomName = null;
-        try
-        {
-            pomName = project.getFile().getName();
-        }
-        catch ( Exception e )
+        List<Model> models = new ArrayList<Model>();
+        
+        List<MavenProject> sortedProjects = session.getProjectDependencyGraph().getSortedProjects();
+        for ( MavenProject mavenProject : sortedProjects )
         {
-            pomName = "pom.xml";
+            models.add( mavenProject.getOriginalModel() );
         }
-        List<Model> models =
-            utils.getModelsRecursively( project.getGroupId(), project.getArtifactId(), project.getVersion(),
-                                        new File( project.getBasedir(), pomName ) );
-
+                        
         // now find all the plugin entries, either in
         // build.plugins or build.pluginManagement.plugins, profiles.plugins and reporting
         for ( Model model : models )
diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtils.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtils.java
index c5f4bdd..bdedb39 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtils.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtils.java
@@ -22,7 +22,6 @@ package org.apache.maven.plugins.enforcer.utils;
 import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
-import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.maven.artifact.Artifact;
@@ -33,7 +32,6 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.model.Model;
-import org.apache.maven.model.Parent;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.ReportPlugin;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
@@ -212,60 +210,6 @@ public class EnforcerRuleUtils
     }
 
     /**
-     * This method loops through all the parents, getting each pom model and then its parent.
-     *
-     * @param groupId the group id
-     * @param artifactId the artifact id
-     * @param version the version
-     * @param pom the pom
-     * @return the models recursively
-     * @throws ArtifactResolutionException the artifact resolution exception
-     * @throws ArtifactNotFoundException the artifact not found exception
-     * @throws IOException Signals that an I/O exception has occurred.
-     * @throws XmlPullParserException the xml pull parser exception
-     */
-    public List<Model> getModelsRecursively( String groupId, String artifactId, String version, File pom )
-        throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException
-    {
-        List<Model> models = null;
-        Model model = getPomModel( groupId, artifactId, version, pom );
-
-        Parent parent = model.getParent();
-
-        // recurse into the parent
-        if ( parent != null )
-        {
-            // get the relative path
-            String relativePath = parent.getRelativePath();
-            if ( StringUtils.isEmpty( relativePath ) )
-            {
-                relativePath = "../pom.xml";
-            }
-            // calculate the recursive path
-            File parentPom = new File( pom.getParent(), relativePath );
-
-            // if relative path is a directory, append pom.xml
-            if ( parentPom.isDirectory() )
-            {
-                parentPom = new File( parentPom, "pom.xml" );
-            }
-
-            //@formatter:off
-            models = getModelsRecursively( parent.getGroupId(), parent.getArtifactId(), 
-                                           parent.getVersion(), parentPom );
-            //@formatter:on
-        }
-        else
-        {
-            // only create it here since I'm not at the top
-            models = new ArrayList<Model>();
-        }
-        models.add( model );
-
-        return models;
-    }
-
-    /**
      * Make sure the model is the one I'm expecting.
      *
      * @param groupId the group id
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 bbd4e8b..422967d 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
@@ -19,24 +19,17 @@ package org.apache.maven.plugins.enforcer;
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 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.testing.AbstractMojoTestCase;
-import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtils;
 import org.apache.maven.plugins.enforcer.utils.PluginWrapper;
-import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 /**
  * The Class TestRequirePluginVersions.
@@ -190,37 +183,6 @@ public class TestRequirePluginVersions
     }
 
     /**
-     * Test get all plugins.
-     *
-     * @throws ArtifactResolutionException the artifact resolution exception
-     * @throws ArtifactNotFoundException the artifact not found exception
-     * @throws IOException Signals that an I/O exception has occurred.
-     * @throws XmlPullParserException the xml pull parser exception
-     */
-    public void testGetAllPlugins()
-        throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException
-    {
-        RequirePluginVersions rule = new RequirePluginVersions();
-        String path = "target/test-classes/requirePluginVersions/getPomRecursively/b/c";
-
-        StringUtils.replace( path, "/", File.separator );
-
-        File projectDir = new File( getBasedir(), path );
-
-        MockProject project = new MockProject();
-        project.setArtifactId( "c" );
-        project.setGroupId( "group" );
-        project.setVersion( "1.0" );
-        project.setBaseDir( projectDir );
-
-        rule.setUtils( new EnforcerRuleUtils( EnforcerTestUtils.getHelper( project ) ) );
-        List<PluginWrapper> plugins = rule.getAllPluginEntries( project );
-
-        // there should be 3
-        assertEquals( 3, plugins.size() );
-    }
-
-    /**
      * Test get additional plugins null.
      *
      * @throws MojoExecutionException the mojo execution exception
diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestEnforcerRuleUtils.java b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestEnforcerRuleUtils.java
index 3583a6a..dc85ada 100644
--- a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestEnforcerRuleUtils.java
+++ b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestEnforcerRuleUtils.java
@@ -19,12 +19,6 @@ package org.apache.maven.plugins.enforcer.utils;
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.enforcer.rule.api.EnforcerRule;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
@@ -32,9 +26,6 @@ import org.apache.maven.model.Model;
 import org.apache.maven.model.Parent;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.plugins.enforcer.EnforcerTestUtils;
-import org.apache.maven.plugins.enforcer.MockProject;
-import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 /**
  * The Class TestEnforcerRuleUtils.
@@ -83,158 +74,6 @@ public class TestEnforcerRuleUtils
     }
 
     /**
-     * Test get models recursively bottom.
-     *
-     * @throws ArtifactResolutionException the artifact resolution exception
-     * @throws ArtifactNotFoundException the artifact not found exception
-     * @throws IOException Signals that an I/O exception has occurred.
-     * @throws XmlPullParserException the xml pull parser exception
-     */
-    public void testGetModelsRecursivelyBottom()
-        throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException
-    {
-        String path = "target/test-classes/requirePluginVersions/getPomRecursively/b/c";
-
-        StringUtils.replace( path, "/", File.separator );
-
-        File pom = new File( getBasedir() + File.separator + path, "pom.xml" );
-
-        EnforcerRuleUtils utils = new EnforcerRuleUtils( EnforcerTestUtils.getHelper() );
-        List models = utils.getModelsRecursively( "group", "c", "1.0", pom );
-
-        // there should be 3
-        assertEquals( 3, models.size() );
-
-        // now make sure they are all there
-        Model m = new Model();
-        m.setGroupId( "group" );
-        m.setVersion( "1.0" );
-        m.setArtifactId( "c" );
-
-        models.contains( m );
-
-        m.setArtifactId( "b" );
-        models.contains( m );
-
-        m.setArtifactId( "a" );
-        models.contains( m );
-    }
-
-    /**
-     * Test get models recursively top.
-     *
-     * @throws ArtifactResolutionException the artifact resolution exception
-     * @throws ArtifactNotFoundException the artifact not found exception
-     * @throws IOException Signals that an I/O exception has occurred.
-     * @throws XmlPullParserException the xml pull parser exception
-     */
-    public void testGetModelsRecursivelyTop()
-        throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException
-    {
-        String path = "target/test-classes/requirePluginVersions/getPomRecursively";
-
-        StringUtils.replace( path, "/", File.separator );
-
-        File pom = new File( getBasedir() + File.separator + path, "pom.xml" );
-
-        EnforcerRuleUtils utils = new EnforcerRuleUtils( EnforcerTestUtils.getHelper() );
-
-        List models = utils.getModelsRecursively( "group", "a", "1.0", pom );
-
-        // there should be 1
-        assertEquals( 1, models.size() );
-
-        // now make sure they are all there
-        Model m = new Model();
-        m.setGroupId( "group" );
-        m.setVersion( "1.0" );
-        m.setArtifactId( "a" );
-
-        models.contains( m );
-    }
-
-    public void testGetModelsRecursivelyParentExpression()
-        throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException
-    {
-        String path = "target/test-classes/requirePluginVersions/parentExpression/child";
-
-        StringUtils.replace( path, "/", File.separator );
-
-        File pom = new File( getBasedir() + File.separator + path, "pom.xml" );
-
-        // bit backwards - the project here should really be the one read in the first stage of getModelsRecursively
-        MockProject parent = new MockProject();
-        parent.setGroupId( "org.apache.maven.plugins.enforcer.test" );
-        parent.setArtifactId( "parent" );
-        parent.setVersion( "1.0-SNAPSHOT" );
-
-        MockProject project = new MockProject();
-        project.setParent( parent );
-
-        EnforcerRuleUtils utils = new EnforcerRuleUtils( EnforcerTestUtils.getHelper( project ) );
-
-        List models =
-            utils.getModelsRecursively( "org.apache.maven.plugins.enforcer.test", "child", "1.0-SNAPSHOT", pom );
-
-        // there should be 2
-        assertEquals( 2, models.size() );
-    }
-
-    public void testGetModelsRecursivelyParentRelativePath()
-        throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException
-    {
-        String path = "target/test-classes/requirePluginVersions/parentRelativePath";
-
-        StringUtils.replace( path, "/", File.separator );
-
-        File pom = new File( getBasedir() + File.separator + path, "pom.xml" );
-
-        // bit backwards - the project here should really be the one read in the first stage of getModelsRecursively
-        MockProject parent = new MockProject();
-        parent.setGroupId( "org.apache.maven.plugins.enforcer.test" );
-        parent.setArtifactId( "parent" );
-        parent.setVersion( "1.0-SNAPSHOT" );
-
-        MockProject project = new MockProject();
-        project.setParent( parent );
-
-        EnforcerRuleUtils utils = new EnforcerRuleUtils( EnforcerTestUtils.getHelper( project ) );
-
-        List models =
-            utils.getModelsRecursively( "org.apache.maven.plugins.enforcer.test", "aggregate", "1.0-SNAPSHOT", pom );
-
-        // there should be 2
-        assertEquals( 2, models.size() );
-    }
-
-    public void testGetModelsRecursivelyParentRelativePathDirectory()
-        throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException
-    {
-        String path = "target/test-classes/requirePluginVersions/parentRelativePathDirectory";
-
-        StringUtils.replace( path, "/", File.separator );
-
-        File pom = new File( getBasedir() + File.separator + path, "pom.xml" );
-
-        // bit backwards - the project here should really be the one read in the first stage of getModelsRecursively
-        MockProject parent = new MockProject();
-        parent.setGroupId( "org.apache.maven.plugins.enforcer.test" );
-        parent.setArtifactId( "parent" );
-        parent.setVersion( "1.0-SNAPSHOT" );
-
-        MockProject project = new MockProject();
-        project.setParent( parent );
-
-        EnforcerRuleUtils utils = new EnforcerRuleUtils( EnforcerTestUtils.getHelper( project ) );
-
-        List models =
-            utils.getModelsRecursively( "org.apache.maven.plugins.enforcer.test", "aggregate", "1.0-SNAPSHOT", pom );
-
-        // there should be 2
-        assertEquals( 2, models.size() );
-    }
-
-    /**
      * Simpler wrapper to execute and deal with the expected result.
      *
      * @param rule the rule
diff --git a/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/invoker.properties b/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/invoker.properties
index a07d2f1..1b78093 100644
--- a/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/invoker.properties
+++ b/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/invoker.properties
@@ -14,4 +14,5 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+invoker.maven.version = 3.5.0+
 invoker.goals = install -Drevision=0.10.0-SNAPSHOT
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.