This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch MENFORCER-426
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git

commit baff3adb4463a01886ca47bae340e16162e6220e
Author: Slawomir Jaranowski <s.jaranow...@gmail.com>
AuthorDate: Tue Mar 21 00:27:41 2023 +0100

    [MENFORCER-426] Reproduce issue
---
 .../rules/dependency/DependencyConvergence.java    |  1 +
 .../enforcer/rules/dependency/ResolveUtil.java     | 34 +++++++++++++
 .../src/it/mrm/repository/menforcer426-a-1.0.pom   | 39 ++++++++++++++
 .../src/it/mrm/repository/menforcer426-b-1.0.pom   | 34 +++++++++++++
 .../projects/dependency-convergence-ranges/pom.xml | 59 ++++++++++++++++++++++
 5 files changed, 167 insertions(+)

diff --git 
a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/DependencyConvergence.java
 
b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/DependencyConvergence.java
index 13e22c6..426909b 100644
--- 
a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/DependencyConvergence.java
+++ 
b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/DependencyConvergence.java
@@ -79,6 +79,7 @@ public final class DependencyConvergence extends 
AbstractStandardEnforcerRule {
                 
getConvergenceErrorMsgs(dependencyVersionMap.getConflictedVersionNumbers(includes,
 excludes));
 
         if (!errorMsgs.isEmpty()) {
+            getLog().debug(() -> resolveUtil.dumpTree(node));
             throw new EnforcerRuleException("Failed while enforcing 
releasability." + System.lineSeparator()
                     + String.join(System.lineSeparator(), errorMsgs));
         }
diff --git 
a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/ResolveUtil.java
 
b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/ResolveUtil.java
index 19d4a20..d17a9dd 100644
--- 
a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/ResolveUtil.java
+++ 
b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/ResolveUtil.java
@@ -37,9 +37,11 @@ import org.eclipse.aether.collection.CollectRequest;
 import org.eclipse.aether.collection.DependencyCollectionException;
 import org.eclipse.aether.collection.DependencySelector;
 import org.eclipse.aether.graph.DependencyNode;
+import org.eclipse.aether.graph.DependencyVisitor;
 import org.eclipse.aether.util.graph.manager.DependencyManagerUtils;
 import org.eclipse.aether.util.graph.selector.AndDependencySelector;
 import org.eclipse.aether.util.graph.transformer.ConflictResolver;
+import org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor;
 
 import static java.util.Optional.ofNullable;
 
@@ -133,4 +135,36 @@ class ResolveUtil {
             throw new EnforcerRuleException("Could not build dependency tree " 
+ e.getLocalizedMessage(), e);
         }
     }
+
+    /**
+     * Dump a {@link DependencyNode} as a tree.
+     *
+     * @param rootNode node to inspect
+     * @return dependency tree as String
+     */
+    public CharSequence dumpTree(DependencyNode rootNode) {
+        StringBuilder result = new StringBuilder(System.lineSeparator());
+
+        rootNode.accept(new TreeDependencyVisitor(new DependencyVisitor() {
+            String indent = "";
+
+            @Override
+            public boolean visitEnter(org.eclipse.aether.graph.DependencyNode 
dependencyNode) {
+                result.append(indent);
+                result.append("Node: ").append(dependencyNode);
+                result.append(" data map: ").append(dependencyNode.getData());
+                result.append(System.lineSeparator());
+                indent += "  ";
+                return true;
+            }
+
+            @Override
+            public boolean visitLeave(org.eclipse.aether.graph.DependencyNode 
dependencyNode) {
+                indent = indent.substring(0, indent.length() - 2);
+                return true;
+            }
+        }));
+
+        return result;
+    }
 }
diff --git a/maven-enforcer-plugin/src/it/mrm/repository/menforcer426-a-1.0.pom 
b/maven-enforcer-plugin/src/it/mrm/repository/menforcer426-a-1.0.pom
new file mode 100644
index 0000000..c203ffa
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/mrm/repository/menforcer426-a-1.0.pom
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  * 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>org.apache.maven.plugins.enforcer.its</groupId>
+  <artifactId>menforcer426-a</artifactId>
+  <version>1.0</version>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+      <artifactId>menforcer426-b</artifactId>
+      <version>1.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+      <artifactId>menforcer128_api</artifactId>
+      <version>[1.0.0,2.0.0)</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file
diff --git a/maven-enforcer-plugin/src/it/mrm/repository/menforcer426-b-1.0.pom 
b/maven-enforcer-plugin/src/it/mrm/repository/menforcer426-b-1.0.pom
new file mode 100644
index 0000000..9582e37
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/mrm/repository/menforcer426-b-1.0.pom
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  * 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>org.apache.maven.plugins.enforcer.its</groupId>
+  <artifactId>menforcer426-b</artifactId>
+  <version>1.0</version>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+      <artifactId>menforcer128_api</artifactId>
+      <version>[1.0.0,2.0.0)</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file
diff --git 
a/maven-enforcer-plugin/src/it/projects/dependency-convergence-ranges/pom.xml 
b/maven-enforcer-plugin/src/it/projects/dependency-convergence-ranges/pom.xml
new file mode 100644
index 0000000..cf0c83a
--- /dev/null
+++ 
b/maven-enforcer-plugin/src/it/projects/dependency-convergence-ranges/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  * 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>test</groupId>
+  <artifactId>menforcer426</artifactId>
+  <version>1.0</version>
+  
+  <url>https://issues.apache.org/jira/browse/MENFORCER-426</url>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+      <artifactId>menforcer426-a</artifactId>
+      <version>1.0</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>enforce</id>
+            <configuration>
+              <rules>
+                <dependencyConvergence/>
+              </rules>
+            </configuration>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
\ No newline at end of file

Reply via email to