maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (MENFORCER-241) DependencyConverge - allow ignoring minor and patch level mismatches
Date Thu, 26 Oct 2017 07:41:00 GMT

    [ https://issues.apache.org/jira/browse/MENFORCER-241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16220105#comment-16220105
] 

ASF GitHub Bot commented on MENFORCER-241:
------------------------------------------

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:stf@molindo.at">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:
users@infra.apache.org


> DependencyConverge - allow ignoring minor and patch level mismatches
> --------------------------------------------------------------------
>
>                 Key: MENFORCER-241
>                 URL: https://issues.apache.org/jira/browse/MENFORCER-241
>             Project: Maven Enforcer Plugin
>          Issue Type: Improvement
>    Affects Versions: 1.4.1
>            Reporter: Stefan Fussenegger
>         Attachments: MENFORCER-241.patch
>
>
> sometimes it is acceptable to allow some degree of version mismatches. For instance,
if an artifact follows [semantic versioning rules|http://semver.org/] it is acceptable to
allow patch level mismatches (bug fixes) or even minor level mismatches (added backward compatible
functionality).
> This new feature could somehow replace the current {{uniqueVersions}} flag which pretty
much does the same thing to a lesser degree



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message