ajarmoniuk commented on code in PR #198:
URL: https://github.com/apache/maven-enforcer/pull/198#discussion_r1051782468


##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanTransitiveDependencies.java:
##########
@@ -127,55 +130,27 @@ private static boolean searchTree(DependencyNode node, 
int level, ArtifactMatche
 
     @Override
     public void execute(EnforcerRuleHelper helper) throws 
EnforcerRuleException {
-        this.helper = helper;
-
-        if (excludes == null) {
-            excludes = Collections.emptyList();
-        }
-        if (includes == null) {
-            includes = Collections.emptyList();
-        }
-
-        final ArtifactMatcher exclusions = new ArtifactMatcher(excludes, 
includes);
-
-        DependencyNode rootNode = null;
-
+        MavenSession session;
         try {
-            MavenProject project = (MavenProject) 
helper.evaluate("${project}");
-            MavenSession session = (MavenSession) 
helper.evaluate("${session}");
-
-            ProjectBuildingRequest buildingRequest =
-                    new 
DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
-            buildingRequest.setProject(project);
-
-            rootNode = 
createDependencyGraphBuilder().buildDependencyGraph(buildingRequest, null);
-        } catch (Exception e) {
-            throw new EnforcerRuleException("Error: Could not construct 
dependency tree.", e);
-        }
-
-        String message = getMessage();
-        StringBuilder generatedMessage = null;
-        if (message == null) {
-            generatedMessage = new StringBuilder();
+            session = (MavenSession) helper.evaluate("${session}");
+        } catch (ExpressionEvaluationException e) {
+            throw new RuntimeException(e);
         }
-
+        ArtifactTypeRegistry artifactTypeRegistry =
+                session.getRepositorySession().getArtifactTypeRegistry();
+        ArtifactMatcher exclusions = new ArtifactMatcher(excludes, includes);
+        Set<Dependency> directDependencies = 
session.getCurrentProject().getDependencies().parallelStream()
+                .map(d -> RepositoryUtils.toDependency(d, 
artifactTypeRegistry))
+                .collect(Collectors.toSet());

Review Comment:
   Collectors are not. noneMatch, anyMatch should be safe, but I can replace 
those too just to be on the safe side. 



-- 
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

Reply via email to