[1/2] maven git commit: [MNG-6240] Duplicate components in plugin extension realm when plugin depends on maven-aether-resolver [Forced Update!]

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[1/2] maven git commit: [MNG-6240] Duplicate components in plugin extension realm when plugin depends on maven-aether-resolver [Forced Update!]

khmarbaise
Repository: maven
Updated Branches:
  refs/heads/MNG-6123-detect-self-references 502c86eaa -> 78c3d183d (forced update)


[MNG-6240] Duplicate components in plugin extension realm when plugin depends on maven-aether-resolver

Maven Core needs to export the maven-aether-provider artifact so that its components do not get added twice in plugin realm. This happens if the build uses an extension plugin depending on maven-aether-provider, before it was renamed to maven-resolver-provider


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/a1fe4219
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/a1fe4219
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/a1fe4219

Branch: refs/heads/MNG-6123-detect-self-references
Commit: a1fe42199565f76007a97f47cd4a848fd9b63482
Parents: 12d6471
Author: Guillaume Boué <[hidden email]>
Authored: Fri Jun 9 23:25:31 2017 +0200
Committer: Guillaume Boué <[hidden email]>
Committed: Wed Jun 14 19:55:41 2017 +0200

----------------------------------------------------------------------
 maven-core/src/main/resources/META-INF/maven/extension.xml | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/a1fe4219/maven-core/src/main/resources/META-INF/maven/extension.xml
----------------------------------------------------------------------
diff --git a/maven-core/src/main/resources/META-INF/maven/extension.xml b/maven-core/src/main/resources/META-INF/maven/extension.xml
index 1f0b95f..c5f40b5 100644
--- a/maven-core/src/main/resources/META-INF/maven/extension.xml
+++ b/maven-core/src/main/resources/META-INF/maven/extension.xml
@@ -134,6 +134,11 @@ under the License.
     <exportedArtifact>org.sonatype.sisu:sisu-inject-plexus</exportedArtifact>
     <exportedArtifact>org.eclipse.sisu:org.eclipse.sisu.plexus</exportedArtifact>
     <exportedArtifact>org.apache.maven:maven-artifact</exportedArtifact>
+    <!--
+      | MNG-6240: Plugins might depend on maven-aether-provider <= 3.3.9 before the rename to maven-resolver-provider.
+      | Since backwards-compatibility was kept, Maven Core also provides this artifact.
+     -->
+    <exportedArtifact>org.apache.maven:maven-aether-provider</exportedArtifact>
     <exportedArtifact>org.apache.maven:maven-resolver-provider</exportedArtifact>
     <exportedArtifact>org.apache.maven:maven-artifact-manager</exportedArtifact>
     <exportedArtifact>org.apache.maven:maven-compat</exportedArtifact>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[2/2] maven git commit: [MNG-6123] detect self references in POM and fail fast o Added unit test and self referencing pom

khmarbaise
[MNG-6123] detect self references in POM and fail fast
 o Added unit test and self referencing pom


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/78c3d183
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/78c3d183
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/78c3d183

Branch: refs/heads/MNG-6123-detect-self-references
Commit: 78c3d183d7a489591193d39c5ac9340a4410ef8c
Parents: a1fe421
Author: Karl Heinz Marbaise <[hidden email]>
Authored: Tue Apr 4 22:46:11 2017 +0200
Committer: Karl Heinz Marbaise <[hidden email]>
Committed: Sat Jul 15 11:44:00 2017 +0200

----------------------------------------------------------------------
 .../model/validation/DefaultModelValidator.java | 49 ++++++++++++++++++--
 .../validation/DefaultModelValidatorTest.java   | 13 ++++++
 .../validation/raw-model/self-referencing.xml   | 38 +++++++++++++++
 3 files changed, 97 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/78c3d183/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
----------------------------------------------------------------------
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
index 2e7985f..809df21 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
@@ -131,6 +131,9 @@ public class DefaultModelValidator
 
             validate20RawDependencies( problems, m.getDependencies(), "dependencies.dependency", request );
 
+            validate20RawDependenciesSelfReferencing( problems, m, m.getDependencies(), "dependencies.dependency",
+                                                      request );
+
             if ( m.getDependencyManagement() != null )
             {
                 validate20RawDependencies( problems, m.getDependencyManagement().getDependencies(),
@@ -344,12 +347,12 @@ public class DefaultModelValidator
 
         Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
 
-        validateEffectiveDependencies( problems, m.getDependencies(), false, request );
+        validateEffectiveDependencies( problems, m, m.getDependencies(), false, request );
 
         DependencyManagement mgmt = m.getDependencyManagement();
         if ( mgmt != null )
         {
-            validateEffectiveDependencies( problems, mgmt.getDependencies(), true, request );
+            validateEffectiveDependencies( problems, m, mgmt.getDependencies(), true, request );
         }
 
         if ( request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
@@ -524,7 +527,28 @@ public class DefaultModelValidator
         }
     }
 
-    private void validateEffectiveDependencies( ModelProblemCollector problems, List<Dependency> dependencies,
+    private void validate20RawDependenciesSelfReferencing( ModelProblemCollector problems, Model m,
+                                                           List<Dependency> dependencies, String prefix,
+                                                           ModelBuildingRequest request )
+    {
+        for ( Dependency dependency : dependencies )
+        {
+            String key = dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion();
+            String mKey = m.getGroupId() + ":" + m.getArtifactId() + ":" + m.getVersion();
+            if ( key.equals( mKey ) )
+            {
+                // This means a module which is build has a dependency which has the same
+                // groupId, artifactId and version coordinates. This is in consequence
+                // a self reference or in other words a circular reference which can not
+                // being resolved.
+                addViolation( problems, Severity.FATAL, Version.V31, prefix + " " + key, key, "is referencing itself.",
+                              dependency );
+
+            }
+        }
+    }
+
+    private void validateEffectiveDependencies( ModelProblemCollector problems, Model m, List<Dependency> dependencies,
                                                 boolean management, ModelBuildingRequest request )
     {
         Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
@@ -551,11 +575,30 @@ public class DefaultModelValidator
                      */
                     validateEnum( prefix + "scope", problems, Severity.WARNING, Version.V20, d.getScope(),
                                   d.getManagementKey(), d, "provided", "compile", "runtime", "test", "system" );
+
+                    validateEffectiveModelAgainstDependency( prefix, problems, m, d, request );
                 }
             }
         }
     }
 
+    private void validateEffectiveModelAgainstDependency( String prefix, ModelProblemCollector problems, Model m,
+                                                          Dependency d, ModelBuildingRequest request )
+    {
+        String key = d.getGroupId() + ":" + d.getArtifactId() + ":" + d.getVersion();
+        String mKey = m.getGroupId() + ":" + m.getArtifactId() + ":" + m.getVersion();
+        if ( key.equals( mKey ) )
+        {
+            // This means a module which is build has a dependency which has the same
+            // groupId, artifactId and version coordinates. This is in consequence
+            // a self reference or in other words a circular reference which can not
+            // being resolved.
+            addViolation( problems, Severity.FATAL, Version.V31, prefix + " " + key, key, "is referencing itself.", d );
+
+        }
+
+    }
+
     private void validate20EffectivePluginDependencies( ModelProblemCollector problems, Plugin plugin,
                                                         ModelBuildingRequest request )
     {

http://git-wip-us.apache.org/repos/asf/maven/blob/78c3d183/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
----------------------------------------------------------------------
diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
index 4da3c87..5614daf 100644
--- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
@@ -714,4 +714,17 @@ public class DefaultModelValidatorTest
         assertContains( result.getWarnings().get( 1 ),
                 "'dependencies.dependency.version' for test:b:jar is either LATEST or RELEASE (both of them are being deprecated)" );
     }
+
+    public void testSelfReferencingDependencyInRawModel()
+        throws Exception
+    {
+        SimpleProblemCollector result = validateRaw( "raw-model/self-referencing.xml" );
+
+        assertViolations( result, 1, 0, 0 );
+
+        assertEquals( "'dependencies.dependency com.example.group:testinvalidpom:0.0.1-SNAPSHOT' for com.example.group:testinvalidpom:0.0.1-SNAPSHOT is referencing itself.",
+                      result.getFatals().get( 0 ) );
+
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/78c3d183/maven-model-builder/src/test/resources/poms/validation/raw-model/self-referencing.xml
----------------------------------------------------------------------
diff --git a/maven-model-builder/src/test/resources/poms/validation/raw-model/self-referencing.xml b/maven-model-builder/src/test/resources/poms/validation/raw-model/self-referencing.xml
new file mode 100644
index 0000000..a902896
--- /dev/null
+++ b/maven-model-builder/src/test/resources/poms/validation/raw-model/self-referencing.xml
@@ -0,0 +1,38 @@
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.example.group</groupId>
+ <artifactId>testinvalidpom</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <description>
+ This will test if the module validator recognized that this
+ dependency is the same as the module itself.
+ </description>
+ <dependencies>
+ <dependency>
+ <groupId>com.example.group</groupId>
+ <artifactId>testinvalidpom</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file

Loading...