[GitHub] asfgit closed pull request #16: MENFORCER-241 allow ignoring minor and patch level mismatches

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] asfgit closed pull request #16: MENFORCER-241 allow ignoring minor and patch level mismatches

GitBox
asfgit closed pull request #16: MENFORCER-241 allow ignoring minor and patch level mismatches
URL: https://github.com/apache/maven-enforcer/pull/16
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java
index 7c21bd6..a4ac405 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java
@@ -49,15 +49,31 @@
     implements EnforcerRule
 {
 
+    /**
+     * @author <a href="mailto:[hidden email]">Stefan Fussenegger</a>
+     */
+    public enum Degree
+    {
+        MAJOR, MINOR, PATCH, UNIQUE;
+    }
+
     private static Log log;
 
     private static I18N i18n;
 
-    private boolean uniqueVersions;
+    private Degree degree = Degree.PATCH;
 
     public void setUniqueVersions( boolean uniqueVersions )
     {
-        this.uniqueVersions = uniqueVersions;
+        if ( uniqueVersions )
+        {
+            setDegree( Degree.UNIQUE );
+        }
+    }
+
+    public void setDegree( Degree degree )
+    {
+        this.degree = degree == null ? Degree.PATCH : degree;
     }
 
     // CHECKSTYLE_OFF: LineLength
@@ -119,7 +135,7 @@ public void execute( EnforcerRuleHelper helper )
             }
             DependencyNode node = getNode( helper );
             DependencyVersionMap visitor = new DependencyVersionMap( log );
-            visitor.setUniqueVersions( uniqueVersions );
+            visitor.setDegree( degree );
             node.accept( visitor );
             List<CharSequence> errorMsgs = new ArrayList<CharSequence>();
             errorMsgs.addAll( getConvergenceErrorMsgs( visitor.getConflictedVersionNumbers() ) );
diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java
index 2ec4ac2..d3999b7 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java
@@ -25,7 +25,9 @@
 import java.util.Map;
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.enforcer.DependencyConvergence.Degree;
 import org.apache.maven.shared.dependency.tree.DependencyNode;
 import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor;
 
@@ -37,20 +39,29 @@
     implements DependencyNodeVisitor
 {
     private Log log;
-    
-    private boolean uniqueVersions;
+
+    private Degree degree = Degree.PATCH;
 
     private Map<String, List<DependencyNode>> idsToNode;
 
+
     public DependencyVersionMap( Log log )
     {
         this.log = log;
         idsToNode = new HashMap<String, List<DependencyNode>>();
     }
-    
+
     public void setUniqueVersions( boolean uniqueVersions )
     {
-        this.uniqueVersions = uniqueVersions;
+        if ( uniqueVersions )
+        {
+            setDegree( Degree.UNIQUE );
+        }
+    }
+
+    public void setDegree( Degree degree )
+    {
+        this.degree = degree == null ? Degree.PATCH : degree;
     }
 
     public boolean visit( DependencyNode node )
@@ -85,10 +96,33 @@ public void addDependency( DependencyNode node )
         }
         nodes.add( node );
     }
-    
+
     private String getVersion( Artifact artifact )
     {
-        return uniqueVersions ? artifact.getVersion() : artifact.getBaseVersion();
+        if ( degree == Degree.UNIQUE )
+        {
+            return artifact.getVersion();
+        }
+        else if ( degree == Degree.PATCH )
+        {
+            return artifact.getBaseVersion();
+        }
+        else
+        {
+            DefaultArtifactVersion v = new DefaultArtifactVersion( artifact.getBaseVersion() );
+            if ( degree == Degree.MINOR )
+            {
+                return v.getMajorVersion() + "." + v.getMinorVersion();
+            }
+            else if ( degree == Degree.MAJOR )
+            {
+                return Integer.toString( v.getMajorVersion() );
+            }
+            else
+            {
+                throw new IllegalStateException( "undexpected degree: " + degree );
+            }
+        }
     }
 
     private boolean containsConflicts( DependencyNode node )


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]