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:18 UTC

[nifi-maven] branch main updated (0b6788c -> cc26442)

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

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


    from 0b6788c  NIFI-10906 Set version to 1.4.0-SNAPSHOT
     new eedc644  NIFI-10926 Exclude jdk.tools and com.sun:tools from classpath for extension class loader
     new cc26442  NIFI-10927 Remove service files from parent class loader before discovering class names

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../extraction/ExtensionClassLoaderFactory.java      | 16 +++++++++++++---
 .../extraction/ExtensionDefinitionFactory.java       | 20 +++++++++++++++-----
 2 files changed, 28 insertions(+), 8 deletions(-)


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

Posted by kd...@apache.org.
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<>();
 


[nifi-maven] 02/02: NIFI-10927 Remove service files from parent class loader before discovering class names

Posted by kd...@apache.org.
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 cc264428959b9e41f3bc7cae852f43b060bc248a
Author: Bryan Bende <bb...@apache.org>
AuthorDate: Thu Dec 1 12:15:52 2022 -0500

    NIFI-10927 Remove service files from parent class loader before discovering class names
    
    This closes #27.
    
    Signed-off-by: Kevin Doran <kd...@apache.org>
---
 .../extraction/ExtensionDefinitionFactory.java       | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/nifi/extension/definition/extraction/ExtensionDefinitionFactory.java b/src/main/java/org/apache/nifi/extension/definition/extraction/ExtensionDefinitionFactory.java
index 1f2f037..d8cabd3 100644
--- a/src/main/java/org/apache/nifi/extension/definition/extraction/ExtensionDefinitionFactory.java
+++ b/src/main/java/org/apache/nifi/extension/definition/extraction/ExtensionDefinitionFactory.java
@@ -137,19 +137,29 @@ public class ExtensionDefinitionFactory {
     }
 
     private Set<String> discoverClassNames(final String extensionType) throws IOException {
-        final Set<String> classNames = new HashSet<>();
+        final Set<URL> resourceUrls = new HashSet<>();
 
         final Enumeration<URL> resources = extensionClassLoader.getResources(SERVICES_DIRECTORY + extensionType);
-
         while (resources.hasMoreElements()) {
-            final URL resourceUrl = resources.nextElement();
-            classNames.addAll(discoverClassNames(extensionClassLoader, resourceUrl));
+            resourceUrls.add(resources.nextElement());
         }
 
+        final ClassLoader parentClassLoader = extensionClassLoader.getParent();
+        if (parentClassLoader != null) {
+            final Enumeration<URL> parentResources = parentClassLoader.getResources(SERVICES_DIRECTORY + extensionType);
+            while (parentResources.hasMoreElements()) {
+                resourceUrls.remove(parentResources.nextElement());
+            }
+        }
+
+        final Set<String> classNames = new HashSet<>();
+        for (final URL resourceUrl : resourceUrls) {
+            classNames.addAll(discoverClassNames(resourceUrl));
+        }
         return classNames;
     }
 
-    private Set<String> discoverClassNames(final ClassLoader classLoader, final URL serviceUrl) throws IOException {
+    private Set<String> discoverClassNames(final URL serviceUrl) throws IOException {
         final Set<String> classNames = new HashSet<>();
 
         try (final InputStream in = serviceUrl.openStream();