Skip to content

Commit

Permalink
[MENFORCER-426] Reproduce issue
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Mar 20, 2023
1 parent 57746a1 commit baff3ad
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void execute() throws EnforcerRuleException {
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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
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;

Expand Down Expand Up @@ -133,4 +135,36 @@ private DependencyNode resolveTransitiveDependencies(boolean verbose, Dependency
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;
}
}
39 changes: 39 additions & 0 deletions maven-enforcer-plugin/src/it/mrm/repository/menforcer426-a-1.0.pom
Original file line number Diff line number Diff line change
@@ -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>
34 changes: 34 additions & 0 deletions maven-enforcer-plugin/src/it/mrm/repository/menforcer426-b-1.0.pom
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit baff3ad

Please sign in to comment.