maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From khmarba...@apache.org
Subject [maven-enforcer] 03/03: Removed all tests from TestEnforcerRuleUtils and left a single static method and renamed it to EnforcerRuleUtilsHelper cause it's used in some Tests.
Date Sat, 06 Jan 2018 19:31:53 GMT
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 c6a9adc01586b5d8bcc582cb5899f87960280285
Author: Karl Heinz Marbaise <khmarbaise@apache.org>
AuthorDate: Sat Jan 6 20:30:09 2018 +0100

    Removed all tests from TestEnforcerRuleUtils and left a single static
    method and renamed it to EnforcerRuleUtilsHelper cause it's used in some
    Tests.
---
 .../plugins/enforcer/utils/EnforcerRuleUtils.java  | 155 ---------------------
 .../plugins/enforcer/TestRequireReleaseDeps.java   |  16 +--
 .../enforcer/TestRequireReleaseVersion.java        |  10 +-
 .../enforcer/TestRequireSnapshotVersion.java       |  14 +-
 ...RuleUtils.java => EnforcerRuleUtilsHelper.java} |  46 +-----
 5 files changed, 23 insertions(+), 218 deletions(-)

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 bdedb39..c122e10 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
@@ -19,29 +19,18 @@ package org.apache.maven.plugins.enforcer.utils;
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.io.Reader;
 import java.util.List;
 
-import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-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.Plugin;
 import org.apache.maven.model.ReportPlugin;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import org.codehaus.plexus.util.ReaderFactory;
-import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 /**
  * The Class EnforcerRuleUtils.
@@ -124,150 +113,6 @@ public class EnforcerRuleUtils
         }
     }
 
-    /**
-     * Gets the pom model for this file.
-     *
-     * @param pom the pom
-     * @return the model
-     * @throws IOException Signals that an I/O exception has occurred.
-     * @throws XmlPullParserException the xml pull parser exception
-     */
-    private Model readModel( File pom )
-        throws IOException, XmlPullParserException
-    {
-        Reader reader = ReaderFactory.newXmlReader( pom );
-        MavenXpp3Reader xpp3 = new MavenXpp3Reader();
-        Model model = null;
-        try
-        {
-            model = xpp3.read( reader );
-        }
-        finally
-        {
-            reader.close();
-            reader = null;
-        }
-        return model;
-    }
-
-    /**
-     * This method gets the model for the defined artifact. Looks first in the filesystem,
then tries to get it from the
-     * repo.
-     *
-     * @param groupId the group id
-     * @param artifactId the artifact id
-     * @param version the version
-     * @param pom the pom
-     * @return the pom model
-     * @throws ArtifactResolutionException the artifact resolution exception
-     * @throws ArtifactNotFoundException the artifact not found exception
-     * @throws XmlPullParserException the xml pull parser exception
-     * @throws IOException Signals that an I/O exception has occurred.
-     */
-    private Model getPomModel( String groupId, String artifactId, String version, File pom
)
-        throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException
-    {
-        Model model = null;
-
-        // do we want to look in the reactor like the
-        // project builder? Would require @aggregator goal
-        // which causes problems in maven core right now
-        // because we also need dependency resolution in
-        // other
-        // rules. (MNG-2277)
-
-        // look in the location specified by pom first.
-        boolean found = false;
-        try
-        {
-            model = readModel( pom );
-
-            // i found a model, lets make sure it's the one
-            // I want
-            found = checkIfModelMatches( groupId, artifactId, version, model );
-        }
-        catch ( IOException e )
-        {
-            // nothing here, but lets look in the repo
-            // before giving up.
-        }
-        catch ( XmlPullParserException e )
-        {
-            // nothing here, but lets look in the repo
-            // before giving up.
-        }
-
-        // i didn't find it in the local file system, go
-        // look in the repo
-        if ( !found )
-        {
-            Artifact pomArtifact = factory.createArtifact( groupId, artifactId, version,
null, "pom" );
-            resolver.resolve( pomArtifact, remoteRepositories, local );
-            model = readModel( pomArtifact.getFile() );
-        }
-
-        return model;
-    }
-
-    /**
-     * Make sure the model is the one I'm expecting.
-     *
-     * @param groupId the group id
-     * @param artifactId the artifact id
-     * @param version the version
-     * @param model Model being checked.
-     * @return true, if check if model matches
-     */
-    protected boolean checkIfModelMatches( String groupId, String artifactId, String version,
Model model )
-    {
-        // try these first.
-        String modelGroup = model.getGroupId();
-        String modelArtifactId = model.getArtifactId();
-        String modelVersion = model.getVersion();
-
-        try
-        {
-            if ( StringUtils.isEmpty( modelGroup ) )
-            {
-                modelGroup = model.getParent().getGroupId();
-            }
-            else
-            {
-                // MENFORCER-30, handle cases where the value is a property like ${project.parent.groupId}
-                modelGroup = (String) helper.evaluate( modelGroup );
-            }
-
-            if ( StringUtils.isEmpty( modelVersion ) )
-            {
-                modelVersion = model.getParent().getVersion();
-            }
-            else
-            {
-                // MENFORCER-30, handle cases where the value is a property like ${project.parent.version}
-                modelVersion = (String) helper.evaluate( modelVersion );
-            }
-
-            // Is this only required for Maven2?
-            modelArtifactId = (String) helper.evaluate( modelArtifactId );
-        }
-        catch ( NullPointerException e )
-        {
-            // this is probably bad. I don't have a valid
-            // group or version and I can't find a
-            // parent????
-            // lets see if it's what we're looking for
-            // anyway.
-        }
-        catch ( ExpressionEvaluationException e )
-        {
-            // as above
-        }
-        // CHECKSTYLE_OFF: LineLength
-        return ( StringUtils.equals( groupId, modelGroup ) && StringUtils.equals(
version, modelVersion ) && StringUtils.equals( artifactId,
-                                                                                        
                                        modelArtifactId ) );
-        // CHECKSTYLE_ON: LineLength
-    }
-
     private void resolve( Plugin plugin )
     {
         try
diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseDeps.java
b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseDeps.java
index efe023e..858e60f 100644
--- a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseDeps.java
+++ b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseDeps.java
@@ -27,7 +27,7 @@ import junit.framework.TestCase;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.plugin.testing.ArtifactStubFactory;
-import org.apache.maven.plugins.enforcer.utils.TestEnforcerRuleUtils;
+import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtilsHelper;
 import org.apache.maven.project.MavenProject;
 
 /**
@@ -56,25 +56,25 @@ public class TestRequireReleaseDeps
         RequireReleaseDeps rule = newRequireReleaseDeps();
         rule.setSearchTransitive( false );
 
-        TestEnforcerRuleUtils.execute( rule, helper, false );
+        EnforcerRuleUtilsHelper.execute( rule, helper, false );
 
         rule.setSearchTransitive( true );
 
-        TestEnforcerRuleUtils.execute( rule, helper, true );
+        EnforcerRuleUtilsHelper.execute( rule, helper, true );
 
         // test onlyWhenRelease in each case
 
         project.setArtifact( factory.getSnapshotArtifact() );
 
-        TestEnforcerRuleUtils.execute( rule, helper, true );
+        EnforcerRuleUtilsHelper.execute( rule, helper, true );
 
         rule.setOnlyWhenRelease( true );
 
-        TestEnforcerRuleUtils.execute( rule, helper, false );
+        EnforcerRuleUtilsHelper.execute( rule, helper, false );
 
         project.setArtifact( factory.getReleaseArtifact() );
 
-        TestEnforcerRuleUtils.execute( rule, helper, true );
+        EnforcerRuleUtilsHelper.execute( rule, helper, true );
 
         MockProject parent = new MockProject();
         parent.setArtifact( factory.getSnapshotArtifact() );
@@ -84,10 +84,10 @@ public class TestRequireReleaseDeps
         helper = EnforcerTestUtils.getHelper(project);
 
         rule.setFailWhenParentIsSnapshot( true );
-        TestEnforcerRuleUtils.execute( rule, helper, true );
+        EnforcerRuleUtilsHelper.execute( rule, helper, true );
 
         rule.setFailWhenParentIsSnapshot( false );
-        TestEnforcerRuleUtils.execute( rule, helper, false );
+        EnforcerRuleUtilsHelper.execute( rule, helper, false );
 
 
     }
diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseVersion.java
b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseVersion.java
index 0a65bba..286008e 100644
--- a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseVersion.java
+++ b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseVersion.java
@@ -26,7 +26,7 @@ import junit.framework.TestCase;
 import org.apache.maven.enforcer.rule.api.EnforcerRule;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.plugin.testing.ArtifactStubFactory;
-import org.apache.maven.plugins.enforcer.utils.TestEnforcerRuleUtils;
+import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtilsHelper;
 
 /**
  * The Class TestRequireReleaseVersion.
@@ -53,11 +53,11 @@ public class TestRequireReleaseVersion
 
         EnforcerRule rule = new RequireReleaseVersion();
 
-        TestEnforcerRuleUtils.execute( rule, helper, false );
+        EnforcerRuleUtilsHelper.execute( rule, helper, false );
 
         project.setArtifact( factory.getSnapshotArtifact() );
 
-        TestEnforcerRuleUtils.execute( rule, helper, true );
+        EnforcerRuleUtilsHelper.execute( rule, helper, true );
 
         project.setArtifact( factory.getReleaseArtifact() );
 
@@ -67,10 +67,10 @@ public class TestRequireReleaseVersion
         helper = EnforcerTestUtils.getHelper(project);
 
         ( (RequireReleaseVersion) rule ).setFailWhenParentIsSnapshot( true );
-        TestEnforcerRuleUtils.execute( rule, helper, true );
+        EnforcerRuleUtilsHelper.execute( rule, helper, true );
 
         ( (RequireReleaseVersion) rule ).setFailWhenParentIsSnapshot( false );
-        TestEnforcerRuleUtils.execute( rule, helper, false );
+        EnforcerRuleUtilsHelper.execute( rule, helper, false );
 
     }
 
diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireSnapshotVersion.java
b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireSnapshotVersion.java
index 4c1c60e..2fd08a9 100644
--- a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireSnapshotVersion.java
+++ b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireSnapshotVersion.java
@@ -21,7 +21,7 @@ package org.apache.maven.plugins.enforcer;
 
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.plugin.testing.ArtifactStubFactory;
-import org.apache.maven.plugins.enforcer.utils.TestEnforcerRuleUtils;
+import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtilsHelper;
 import org.apache.maven.project.MavenProject;
 import org.junit.Before;
 import org.junit.Test;
@@ -56,10 +56,10 @@ public class TestRequireSnapshotVersion
         throws IOException
     {
         project.setArtifact( factory.getReleaseArtifact() );
-        TestEnforcerRuleUtils.execute( rule, helper, true );
+        EnforcerRuleUtilsHelper.execute( rule, helper, true );
 
         project.setArtifact( factory.getSnapshotArtifact() );
-        TestEnforcerRuleUtils.execute( rule, helper, false );
+        EnforcerRuleUtilsHelper.execute( rule, helper, false );
     }
 
     @Test
@@ -72,12 +72,12 @@ public class TestRequireSnapshotVersion
         MockProject parent = new MockProject();
         parent.setArtifact( factory.getReleaseArtifact() );
         project.setParent( parent );
-        TestEnforcerRuleUtils.execute( rule, helper, true );
+        EnforcerRuleUtilsHelper.execute( rule, helper, true );
 
         parent = new MockProject();
         parent.setArtifact( factory.getSnapshotArtifact() );
         project.setParent( parent );
-        TestEnforcerRuleUtils.execute( rule, helper, false );
+        EnforcerRuleUtilsHelper.execute( rule, helper, false );
     }
 
     @Test
@@ -90,12 +90,12 @@ public class TestRequireSnapshotVersion
         MockProject parent = new MockProject();
         parent.setArtifact( factory.getReleaseArtifact() );
         project.setParent( parent );
-        TestEnforcerRuleUtils.execute( rule, helper, false );
+        EnforcerRuleUtilsHelper.execute( rule, helper, false );
 
         parent = new MockProject();
         parent.setArtifact( factory.getSnapshotArtifact() );
         project.setParent( parent );
-        TestEnforcerRuleUtils.execute( rule, helper, false );
+        EnforcerRuleUtilsHelper.execute( rule, helper, false );
     }
 
 }
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/EnforcerRuleUtilsHelper.java
similarity index 55%
rename from enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestEnforcerRuleUtils.java
rename to enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtilsHelper.java
index dc85ada..37d98bc 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/EnforcerRuleUtilsHelper.java
@@ -1,5 +1,7 @@
 package org.apache.maven.plugins.enforcer.utils;
 
+import static org.junit.Assert.fail;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -22,58 +24,16 @@ package org.apache.maven.plugins.enforcer.utils;
 import org.apache.maven.enforcer.rule.api.EnforcerRule;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
-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;
 
 /**
  * The Class TestEnforcerRuleUtils.
  *
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
  */
-public class TestEnforcerRuleUtils
-    extends AbstractMojoTestCase
+public class EnforcerRuleUtilsHelper
 {
 
     /**
-     * Test check if model matches.
-     */
-    public void testCheckIfModelMatches()
-    {
-
-        EnforcerRuleUtils utils = new EnforcerRuleUtils( EnforcerTestUtils.getHelper() );
-
-        Model model = new Model();
-        model.setArtifactId( "" );
-        model.setGroupId( "" );
-        model.setVersion( "" );
-
-        // should generate internal NPE on the parent, but
-        // will still
-        // compare the raw values
-        assertTrue( utils.checkIfModelMatches( "", "", "", model ) );
-        assertFalse( utils.checkIfModelMatches( "", "", "1.0", model ) );
-
-        // now setup a parent
-        Parent parent = new Parent();
-        parent.setArtifactId( "foo" );
-        parent.setGroupId( "foo-group" );
-        parent.setVersion( "1.0" );
-        model.setParent( parent );
-
-        // should NOT pickup the parent artifact
-        assertFalse( utils.checkIfModelMatches( "foo-group", "foo", "1.0", model ) );
-
-        // check that the version and group are inherited
-        // from the parent.
-        assertTrue( utils.checkIfModelMatches( "foo-group", "", "1.0", model ) );
-
-        // check handling of nulls
-        assertFalse( utils.checkIfModelMatches( "foo-group", null, "1.0", model ) );
-    }
-
-    /**
      * Simpler wrapper to execute and deal with the expected result.
      *
      * @param rule the rule

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

Mime
View raw message