From b7fb94723c06ef0277ae0c274f6dd318c90f00ea Mon Sep 17 00:00:00 2001
From: Tamas Palfy
+ * It also allows to load native libraries from the extra classpath.
+ *
+ * One can chose to omit the annotation. In this case the loading of native libraries from the extra classpath
+ * is not supported.
+ * Also by default, classes will be loaded by a common NarClassLoader, however it's possible to acquire an
+ * InstanceClassLoader by calling Thread.currentThread().getContextClassLoader() which can be used manually
+ * to load required classes on an instance-by-instance basis
+ * (by calling {@link Class#forName(String, boolean, ClassLoader)} for example).
+ *
*
* @param dynamicallyModifiesClasspath whether or not this property should be used by the framework to modify the classpath
* @return the builder
diff --git a/nifi-docs/src/main/asciidoc/developer-guide.adoc b/nifi-docs/src/main/asciidoc/developer-guide.adoc
index bd79c1ae63..c0c98df5a0 100644
--- a/nifi-docs/src/main/asciidoc/developer-guide.adoc
+++ b/nifi-docs/src/main/asciidoc/developer-guide.adoc
@@ -2479,6 +2479,9 @@ attempts to resolve filesystem resources from the value of the property. The val
comma-separated list of one or more directories or files, where any paths that do not exist are
skipped. If the resource represents a directory, the directory is listed, and all of the files
in that directory are added to the classpath individually.
+These directories also will be scanned for native libraries. If a library is found in one of these
+directories, an OS-handled temporary copy is created and cached before loading it to maintain consistency
+and classloader isolation.
Each property may impose further restrictions on the format of the value through the validators.
For example, using StandardValidators.FILE_EXISTS_VALIDATOR restricts the property to accepting a
diff --git a/nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java b/nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java
index e742d13e3c..a27b10408e 100644
--- a/nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java
+++ b/nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java
@@ -112,8 +112,8 @@ public abstract class AbstractHadoopProcessor extends AbstractProcessor {
public static final PropertyDescriptor ADDITIONAL_CLASSPATH_RESOURCES = new PropertyDescriptor.Builder()
.name("Additional Classpath Resources")
- .description("A comma-separated list of paths to files and/or directories that will be added to the classpath. When specifying a " +
- "directory, all files with in the directory will be added to the classpath, but further sub-directories will not be included.")
+ .description("A comma-separated list of paths to files and/or directories that will be added to the classpath and used for loading native libraries. " +
+ "When specifying a directory, all files with in the directory will be added to the classpath, but further sub-directories will not be included.")
.required(false)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.dynamicallyModifiesClasspath(true)
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/pom.xml
index c9b7ff164d..bfe3d37621 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/pom.xml
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/pom.xml
@@ -22,6 +22,10 @@ language governing permissions and limitations under the License. -->
f^1fIBSpwXHl9Y%^z%8RX^?;zcD(xI-&@!jUJ+ABq>g@
zRh+G
0mBI8;;^E$;-%;6Q>?~e8q!Ac%r;6n+I)rYVfOEd~5*TqdjKy1At
zcOP?$jj-W?Ou1+y@|uFDC2ij&%v5A?H;RnWdrc~ikVCi13g}Ya)S@UQPSemUo&17>
zUvC%i{+y(&U
* +META-INF/
- * +-- bundled-dependencies/
+ * +-- bundled-dependencies/[native]
* +-- <JAR files>
* +-- MANIFEST.MF
*
*
* The MANIFEST.MF file contains the same information as a typical JAR file but * also includes two additional NiFi properties: {@code Nar-Id} and @@ -116,7 +122,7 @@ import org.slf4j.LoggerFactory; * Maven NAR plugin will fail to build the NAR. *
*/ -public class NarClassLoader extends URLClassLoader { +public class NarClassLoader extends AbstractNativeLibHandlingClassLoader { private static final Logger LOGGER = LoggerFactory.getLogger(NarClassLoader.class); @@ -144,7 +150,7 @@ public class NarClassLoader extends URLClassLoader { * @throws IOException if an error occurs while loading the NAR. */ public NarClassLoader(final File narWorkingDirectory) throws ClassNotFoundException, IOException { - super(new URL[0]); + super(new URL[0], initNativeLibDirList(narWorkingDirectory), narWorkingDirectory.getName()); this.narWorkingDirectory = narWorkingDirectory; // process the classpath @@ -163,7 +169,7 @@ public class NarClassLoader extends URLClassLoader { * @throws IOException if an error occurs while loading the NAR. */ public NarClassLoader(final File narWorkingDirectory, final ClassLoader parentClassLoader) throws ClassNotFoundException, IOException { - super(new URL[0], parentClassLoader); + super(new URL[0], parentClassLoader, initNativeLibDirList(narWorkingDirectory), narWorkingDirectory.getName()); this.narWorkingDirectory = narWorkingDirectory; // process the classpath @@ -204,27 +210,25 @@ public class NarClassLoader extends URLClassLoader { } } - @Override - protected String findLibrary(final String libname) { + public File getNARNativeLibDir() { + return getNARNativeLibDir(narWorkingDirectory); + } + + private static List