You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by kd...@apache.org on 2023/01/25 23:21:19 UTC

[nifi-maven] 01/02: NIFI-10926 Exclude jdk.tools and com.sun:tools from classpath for extension class loader

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

kdoran pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-maven.git

commit eedc64430f6974f43f1f4c8b65a9ee581fc5ec3b
Author: Bryan Bende <bb...@apache.org>
AuthorDate: Thu Dec 1 15:01:51 2022 -0500

    NIFI-10926 Exclude jdk.tools and com.sun:tools from classpath for extension class loader
    
    This closes #26.
    
    Signed-off-by: Kevin Doran <kd...@apache.org>
---
 .../extraction/ExtensionClassLoaderFactory.java          | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/nifi/extension/definition/extraction/ExtensionClassLoaderFactory.java b/src/main/java/org/apache/nifi/extension/definition/extraction/ExtensionClassLoaderFactory.java
index 66d7f0d..57bbc7d 100644
--- a/src/main/java/org/apache/nifi/extension/definition/extraction/ExtensionClassLoaderFactory.java
+++ b/src/main/java/org/apache/nifi/extension/definition/extraction/ExtensionClassLoaderFactory.java
@@ -24,6 +24,8 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.logging.Log;
@@ -51,6 +53,15 @@ import java.util.Set;
 import java.util.TreeSet;
 
 public class ExtensionClassLoaderFactory {
+
+    private final static Set<String> EXCLUDED_ARTIFACT_IDS;
+    static {
+        final Set<String> excludedArtifactIds = new HashSet<>();
+        excludedArtifactIds.add("jdk.tools:jdk.tools");
+        excludedArtifactIds.add("com.sun:tools");
+        EXCLUDED_ARTIFACT_IDS = Collections.unmodifiableSet(excludedArtifactIds);
+    }
+
     private final Log log;
     private final MavenProject project;
     private final RepositorySystemSession repoSession;
@@ -295,15 +306,14 @@ public class ExtensionClassLoaderFactory {
             projectRequest.setLocalRepository(localRepo);
             projectRequest.setProject(mavenProject);
 
-            final DependencyNode depNode = dependencyGraphBuilder.buildDependencyGraph(projectRequest, null);
+            final ArtifactFilter excludesFilter = new ExclusionSetFilter(EXCLUDED_ARTIFACT_IDS);
+            final DependencyNode depNode = dependencyGraphBuilder.buildDependencyGraph(projectRequest, excludesFilter);
             depNode.accept(nodeVisitor);
         } catch (DependencyGraphBuilderException e) {
             throw new MojoExecutionException("Failed to build dependency tree", e);
         }
     }
 
-
-
     private Set<URL> toURLs(final Artifact artifact) throws MojoExecutionException {
         final Set<URL> urls = new HashSet<>();