maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1493553 - in /maven/enforcer/trunk: enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/ maven-enforcer-plugin/src/it/mrm/repository/ maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/ maven-...
Date Sun, 16 Jun 2013 17:56:14 GMT
Author: rfscholte
Date: Sun Jun 16 17:56:13 2013
New Revision: 1493553

URL: http://svn.apache.org/r1493553
Log:
[MENFORCER-146] requireUpperBoundDeps inneffective when DependencyManagement is used 

Added:
    maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_b-1.0.pom
    maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-1.1.pom
    maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-2.1.pom
    maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-3.1.pom
    maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/
    maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/invoker.properties
    maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/pom.xml
    maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/verify.groovy
    maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_success/
    maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_success/pom.xml
Modified:
    maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java

Modified: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java?rev=1493553&r1=1493552&r2=1493553&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java
(original)
+++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java
Sun Jun 16 17:56:13 2013
@@ -54,7 +54,6 @@ import org.codehaus.plexus.i18n.I18N;
 public class RequireUpperBoundDeps
     extends AbstractNonCacheableEnforcerRule
 {
-
     private static Log log;
 
     private static I18N i18n;
@@ -63,9 +62,8 @@ public class RequireUpperBoundDeps
      * @since 1.3
      */
     private boolean uniqueVersions;
-    
+
     /**
-     * 
      * @param uniqueVersions
      * @since 1.3
      */
@@ -73,7 +71,7 @@ public class RequireUpperBoundDeps
     {
         this.uniqueVersions = uniqueVersions;
     }
-    
+
     /**
      * Uses the {@link EnforcerRuleHelper} to populate the values of the
      * {@link DependencyTreeBuilder#buildDependencyTree(MavenProject, ArtifactRepository,
ArtifactFactory, ArtifactMetadataSource, ArtifactFilter, ArtifactCollector)}
@@ -165,7 +163,7 @@ public class RequireUpperBoundDeps
     {
         StringBuilder errorMessage = new StringBuilder();
         errorMessage.append( "\nRequire upper bound dependencies error for "
-            + getFullArtifactName( conflict.get( 0 ).getArtifact() ) + " paths to dependency
are:\n" );
+            + getFullArtifactName( conflict.get( 0 ), false ) + " paths to dependency are:\n"
);
         if ( conflict.size() > 0 )
         {
             errorMessage.append( buildTreeString( conflict.get( 0 ) ) );
@@ -184,7 +182,15 @@ public class RequireUpperBoundDeps
         DependencyNode currentNode = node;
         while ( currentNode != null )
         {
-            loc.add( getFullArtifactName( currentNode.getArtifact() ) );
+            StringBuilder line = new StringBuilder( getFullArtifactName( currentNode, false
) );
+            
+            if( currentNode.getPremanagedVersion() != null )
+            {
+                line.append( " (managed) <-- " );
+                line.append( getFullArtifactName( currentNode, true ) );
+            }
+            
+            loc.add( line.toString() );
             currentNode = currentNode.getParent();
         }
         Collections.reverse( loc );
@@ -201,17 +207,24 @@ public class RequireUpperBoundDeps
         return builder;
     }
 
-    private String getFullArtifactName( Artifact artifact )
+    private String getFullArtifactName( DependencyNode node, boolean usePremanaged )
     {
-        return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
+        Artifact artifact = node.getArtifact();
+
+        String version = node.getPremanagedVersion();
+        if ( !usePremanaged || version == null )
+        {
+            version = uniqueVersions ? artifact.getVersion() : artifact.getBaseVersion();
+        }
+        return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + version;
     }
 
     private static class RequireUpperBoundDepsVisitor
         implements DependencyNodeVisitor
     {
-        
+
         private boolean uniqueVersions;
-        
+
         public void setUniqueVersions( boolean uniqueVersions )
         {
             this.uniqueVersions = uniqueVersions;
@@ -261,30 +274,27 @@ public class RequireUpperBoundDeps
         @SuppressWarnings( "unchecked" )
         private boolean containsConflicts( List<DependencyNodeHopCountPair> pairs )
         {
-            if ( pairs.size() > 1 )
-            {
-                DependencyNodeHopCountPair resolvedPair = pairs.get( 0 );
+            DependencyNodeHopCountPair resolvedPair = pairs.get( 0 );
 
-                // search for artifact with lowest hopCount
-                for ( DependencyNodeHopCountPair hopPair : pairs )
+            // search for artifact with lowest hopCount
+            for ( DependencyNodeHopCountPair hopPair : pairs.subList( 1, pairs.size() ) )
+            {
+                if ( hopPair.getHopCount() < resolvedPair.getHopCount() )
                 {
-                    if ( hopPair.getHopCount() < resolvedPair.getHopCount() )
-                    {
-                        resolvedPair = hopPair;
-                    }
+                    resolvedPair = hopPair;
                 }
+            }
 
-                ArtifactVersion resolvedVersion = resolvedPair.extractArtifactVersion( uniqueVersions
);
+            ArtifactVersion resolvedVersion = resolvedPair.extractArtifactVersion( uniqueVersions,
false );
 
-                for ( DependencyNodeHopCountPair pair : pairs )
+            for ( DependencyNodeHopCountPair pair : pairs )
+            {
+                ArtifactVersion version = pair.extractArtifactVersion( uniqueVersions, true
);
+                if ( resolvedVersion.compareTo( version ) < 0 )
                 {
-                    ArtifactVersion version = pair.extractArtifactVersion( uniqueVersions
);
-                    if ( resolvedVersion.compareTo( version ) < 0 )
-                    {
-                        return true;
-                    }
+                    return true;
                 }
-            } 
+            }
             return false;
         }
 
@@ -326,8 +336,13 @@ public class RequireUpperBoundDeps
             return node;
         }
 
-        private ArtifactVersion extractArtifactVersion( boolean uniqueVersions )
+        private ArtifactVersion extractArtifactVersion( boolean uniqueVersions, boolean usePremanagedVersion
)
         {
+            if ( usePremanagedVersion && node.getPremanagedVersion() != null )
+            {
+                return new DefaultArtifactVersion( node.getPremanagedVersion() );
+            }
+
             Artifact artifact = node.getArtifact();
             String version = uniqueVersions ? artifact.getVersion() : artifact.getBaseVersion();
             if ( version != null )

Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_b-1.0.pom
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_b-1.0.pom?rev=1493553&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_b-1.0.pom
(added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_b-1.0.pom
Sun Jun 16 17:56:13 2013
@@ -0,0 +1,14 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+  <artifactId>menforcer146-b</artifactId>
+  <version>1.0</version>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+      <artifactId>menforcer146-x</artifactId>
+      <version>2.1</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-1.1.pom
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-1.1.pom?rev=1493553&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-1.1.pom
(added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-1.1.pom
Sun Jun 16 17:56:13 2013
@@ -0,0 +1,6 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+  <artifactId>menforcer146-x</artifactId>
+  <version>1.1</version>
+</project>
\ No newline at end of file

Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-2.1.pom
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-2.1.pom?rev=1493553&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-2.1.pom
(added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-2.1.pom
Sun Jun 16 17:56:13 2013
@@ -0,0 +1,6 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+  <artifactId>menforcer146-x</artifactId>
+  <version>2.1</version>
+</project>
\ No newline at end of file

Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-3.1.pom
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-3.1.pom?rev=1493553&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-3.1.pom
(added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-3.1.pom
Sun Jun 16 17:56:13 2013
@@ -0,0 +1,6 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+  <artifactId>menforcer146-x</artifactId>
+  <version>3.1</version>
+</project>
\ No newline at end of file

Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/invoker.properties
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/invoker.properties?rev=1493553&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/invoker.properties
(added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/invoker.properties
Sun Jun 16 17:56:13 2013
@@ -0,0 +1 @@
+invoker.buildResult=failure
\ No newline at end of file

Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/pom.xml
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/pom.xml?rev=1493553&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/pom.xml
(added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/pom.xml
Sun Jun 16 17:56:13 2013
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.enforcer.its</groupId>
+  <artifactId>menforcer146-a</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>enforce</id>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <configuration>
+              <rules>
+                <requireUpperBoundDeps/>
+              </rules>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+        <artifactId>menforcer146-x</artifactId>
+        <version>1.1</version>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+      <artifactId>menforcer146-b</artifactId>
+      <version>1.0</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/verify.groovy
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/verify.groovy?rev=1493553&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/verify.groovy
(added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/verify.groovy
Sun Jun 16 17:56:13 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+def LS = System.getProperty( "line.separator" )
+File buildLog = new File( basedir, 'build.log' )
+assert buildLog.text.contains( 'Rule 0: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps
failed with message:' )
+
+def message = 'Failed while enforcing RequireUpperBoundDeps. The error(s) are [' + LS+
+'Require upper bound dependencies error for org.apache.maven.plugins.enforcer.its:menforcer146-x:1.1
paths to dependency are:' + LS+
+'+-org.apache.maven.enforcer.its:menforcer146-a:1.0-SNAPSHOT' + LS+
+'  +-org.apache.maven.plugins.enforcer.its:menforcer146-b:1.0' + LS+
+'    +-org.apache.maven.plugins.enforcer.its:menforcer146-x:1.1 (managed) <-- org.apache.maven.plugins.enforcer.its:menforcer146-x:2.1'
+ LS+
+']' + LS
+assert buildLog.text.contains( message )
\ No newline at end of file

Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_success/pom.xml
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_success/pom.xml?rev=1493553&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_success/pom.xml
(added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_success/pom.xml
Sun Jun 16 17:56:13 2013
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.enforcer.its</groupId>
+  <artifactId>menforcer146-a</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>enforce</id>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <configuration>
+              <rules>
+                <requireUpperBoundDeps/>
+              </rules>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+        <artifactId>menforcer146-x</artifactId>
+        <version>3.1</version>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+      <artifactId>menforcer146-b</artifactId>
+      <version>1.0</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file



Mime
View raw message