ajarmoniuk commented on code in PR #198: URL: https://github.com/apache/maven-enforcer/pull/198#discussion_r1056806120
########## enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java: ########## @@ -51,58 +46,41 @@ public class DependencyConvergence implements EnforcerRule { private List<String> excludes; + private DependencyVersionMap dependencyVersionMap; + public void setUniqueVersions(boolean uniqueVersions) { this.uniqueVersions = uniqueVersions; } - // CHECKSTYLE_OFF: LineLength - /** - * Uses the {@link EnforcerRuleHelper} to populate the values of the - * {@link DependencyTreeBuilder#buildDependencyTree(MavenProject, ArtifactRepository, ArtifactFactory, ArtifactMetadataSource, ArtifactFilter, ArtifactCollector)} - * factory method. <br/> - * This method simply exists to hide all the ugly lookup that the {@link EnforcerRuleHelper} has to do. - * - * @param helper - * @return a Dependency Node which is the root of the project's dependency tree - * @throws EnforcerRuleException - */ - // CHECKSTYLE_ON: LineLength - private DependencyNode getNode(EnforcerRuleHelper helper) throws EnforcerRuleException { - try { - MavenProject project = (MavenProject) helper.evaluate("${project}"); - MavenSession session = (MavenSession) helper.evaluate("${session}"); - DependencyCollectorBuilder dependencyCollectorBuilder = - helper.getComponent(DependencyCollectorBuilder.class); - ArtifactRepository repository = (ArtifactRepository) helper.evaluate("${localRepository}"); - - ProjectBuildingRequest buildingRequest = - new DefaultProjectBuildingRequest(session.getProjectBuildingRequest()); - buildingRequest.setProject(project); - buildingRequest.setLocalRepository(repository); - ArtifactFilter filter = (Artifact a) -> - ("compile".equalsIgnoreCase(a.getScope()) || "runtime".equalsIgnoreCase(a.getScope())) - && !a.isOptional(); - - return dependencyCollectorBuilder.collectDependencyGraph(buildingRequest, filter); - } catch (ExpressionEvaluationException | ComponentLookupException e) { - throw new EnforcerRuleException("Unable to lookup a component " + e.getLocalizedMessage(), e); - } catch (DependencyCollectorBuilderException e) { - throw new EnforcerRuleException("Could not build dependency tree " + e.getLocalizedMessage(), e); - } - } - @Override public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { if (log == null) { log = helper.getLog(); } try { - DependencyNode node = getNode(helper); - DependencyVersionMap visitor = new DependencyVersionMap(log); - visitor.setUniqueVersions(uniqueVersions); - node.accept(visitor); - List<CharSequence> errorMsgs = new ArrayList<>(); - errorMsgs.addAll(getConvergenceErrorMsgs(visitor.getConflictedVersionNumbers(includes, excludes))); + DependencyNode node = ArtifactUtils.resolveTransitiveDependencies( + helper, + // TODO: use a modified version of ExclusionDependencySelector to process excludes and includes + new DependencySelector() { + @Override + public boolean selectDependency(Dependency dependency) { + // regular OptionalDependencySelector only discriminates optional dependencies at level 2+ + return !dependency.isOptional() + // regular ScopeDependencySelector is case-sensitive + && !dependency.getScope().equalsIgnoreCase(Artifact.SCOPE_TEST); + } + + @Override + public DependencySelector deriveChildSelector(DependencyCollectionContext context) { + return this; + } + }, + new ExclusionDependencySelector()); Review Comment: Changed to: new OptionalDependencySelector(), new ScopeDependencySelector(SCOPE_TEST, SCOPE_PROVIDED), new ExclusionDependencySelector()); -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org