/** * Creates a new NarClassLoader. The parentClassLoader may be null. * * @param narDirectory root directory of nar * @param parentClassLoader parent classloader of nar * @return the nar classloader * @throws IOException ioe * @throws ClassNotFoundException cfne */ private static ClassLoader createNarClassLoader(final File narDirectory, final ClassLoader parentClassLoader) throws IOException, ClassNotFoundException { logger.debug("Loading NAR file: " + narDirectory.getAbsolutePath()); final ClassLoader narClassLoader = new NarClassLoader(narDirectory, parentClassLoader); logger.info("Loaded NAR file: " + narDirectory.getAbsolutePath() + " as class loader " + narClassLoader); return narClassLoader; }
/** * Adds URLs for the resources unpacked from this NAR: * <ul><li>the root: for classes, <tt>NAR-INF</tt>, etc.</li> * <li><tt>NAR-INF/bundled-dependencies</tt>: for config files, <tt>.so</tt>s, * etc.</li> * <li><tt>NAR-INF/bundled-dependencies/*.jar</tt>: for dependent * libraries</li></ul> * * @param root the root directory of the unpacked NAR. * @throws IOException if the URL list could not be updated. */ private void updateClasspath(File root) throws IOException { addURL(root.toURI().toURL()); // for compiled classes, WEB-INF, NAR-INF/, etc. File dependencies = new File(root, "NAR-INF/bundled-dependencies"); if (!dependencies.isDirectory()) { LOGGER.warn(narWorkingDirectory + " does not contain NAR-INF/bundled-dependencies!"); } addURL(dependencies.toURI().toURL()); if (dependencies.isDirectory()) { final File[] jarFiles = dependencies.listFiles(JAR_FILTER); if (jarFiles != null) { Arrays.sort(jarFiles, Comparator.comparing(File::getName)); for (File libJar : jarFiles) { addURL(libJar.toURI().toURL()); } } } }
/** * Construct a nar class loader with the specific parent. * * @param narWorkingDirectory directory to explode nar contents to * @param parentClassLoader parent class loader of this nar * @throws IllegalArgumentException if the NAR is missing the Java Services * API file for <tt>FlowFileProcessor</tt> implementations. * @throws ClassNotFoundException if any of the <tt>FlowFileProcessor</tt> * implementations defined by the Java Services API cannot be loaded. * @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); this.narWorkingDirectory = narWorkingDirectory; // process the classpath updateClasspath(narWorkingDirectory); }
/** * Construct a nar class loader. * * @param narWorkingDirectory directory to explode nar contents to * @throws IllegalArgumentException if the NAR is missing the Java Services * API file for <tt>FlowFileProcessor</tt> implementations. * @throws ClassNotFoundException if any of the <tt>FlowFileProcessor</tt> * implementations defined by the Java Services API cannot be loaded. * @throws IOException if an error occurs while loading the NAR. */ public NarClassLoader(final File narWorkingDirectory) throws ClassNotFoundException, IOException { super(new URL[0]); this.narWorkingDirectory = narWorkingDirectory; // process the classpath updateClasspath(narWorkingDirectory); }
/** * Creates a new NarClassLoader. The parentClassLoader may be null. * * @param narDirectory root directory of nar * @param parentClassLoader parent classloader of nar * @return the nar classloader * @throws IOException ioe * @throws ClassNotFoundException cfne */ private static ClassLoader createNarClassLoader(final File narDirectory, final ClassLoader parentClassLoader) throws IOException, ClassNotFoundException { logger.debug("Loading NAR file: " + narDirectory.getAbsolutePath()); final ClassLoader narClassLoader = new NarClassLoader(narDirectory, parentClassLoader); logger.info("Loaded NAR file: " + narDirectory.getAbsolutePath() + " as class loader " + narClassLoader); return narClassLoader; }
/** * Adds URLs for the resources unpacked from this NAR: * <ul><li>the root: for classes, <tt>META-INF</tt>, etc.</li> * <li><tt>META-INF/dependencies</tt>: for config files, <tt>.so</tt>s, * etc.</li> * <li><tt>META-INF/dependencies/*.jar</tt>: for dependent * libraries</li></ul> * * @param root the root directory of the unpacked NAR. * @throws IOException if the URL list could not be updated. */ private void updateClasspath(File root) throws IOException { addURL(root.toURI().toURL()); // for compiled classes, META-INF/, etc. File dependencies = new File(root, "META-INF/bundled-dependencies"); if (!dependencies.isDirectory()) { LOGGER.warn(narWorkingDirectory + " does not contain META-INF/bundled-dependencies!"); } addURL(dependencies.toURI().toURL()); if (dependencies.isDirectory()) { for (File libJar : dependencies.listFiles(JAR_FILTER)) { addURL(libJar.toURI().toURL()); } } }
/** * Construct a nar class loader. * * @param narWorkingDirectory directory to explode nar contents to * @throws IllegalArgumentException if the NAR is missing the Java Services * API file for <tt>FlowFileProcessor</tt> implementations. * @throws ClassNotFoundException if any of the <tt>FlowFileProcessor</tt> * implementations defined by the Java Services API cannot be loaded. * @throws IOException if an error occurs while loading the NAR. */ public NarClassLoader(final File narWorkingDirectory) throws ClassNotFoundException, IOException { super(new URL[0]); this.narWorkingDirectory = narWorkingDirectory; // process the classpath updateClasspath(narWorkingDirectory); }
/** * Creates a new NarClassLoader. The parentClassLoader may be null. * * @param narDirectory root directory of nar * @param parentClassLoader parent classloader of nar * @return the nar classloader * @throws IOException ioe * @throws ClassNotFoundException cfne */ private static ClassLoader createNarClassLoader(final File narDirectory, final ClassLoader parentClassLoader) throws IOException, ClassNotFoundException { logger.debug("Loading NAR file: " + narDirectory.getAbsolutePath()); final ClassLoader narClassLoader = new NarClassLoader(narDirectory, parentClassLoader); logger.info("Loaded NAR file: " + narDirectory.getAbsolutePath() + " as class loader " + narClassLoader); return narClassLoader; }
/** * Adds URLs for the resources unpacked from this NAR: * <ul><li>the root: for classes, <tt>META-INF</tt>, etc.</li> * <li><tt>META-INF/dependencies</tt>: for config files, <tt>.so</tt>s, * etc.</li> * <li><tt>META-INF/dependencies/*.jar</tt>: for dependent * libraries</li></ul> * * @param root the root directory of the unpacked NAR. * @throws IOException if the URL list could not be updated. */ private void updateClasspath(File root) throws IOException { addURL(root.toURI().toURL()); // for compiled classes, META-INF/, etc. File dependencies = new File(root, "META-INF/bundled-dependencies"); if (!dependencies.isDirectory()) { LOGGER.warn(narWorkingDirectory + " does not contain META-INF/bundled-dependencies!"); } addURL(dependencies.toURI().toURL()); if (dependencies.isDirectory()) { for (File libJar : dependencies.listFiles(JAR_FILTER)) { addURL(libJar.toURI().toURL()); } } }
/** * Construct a nar class loader. * * @param narWorkingDirectory directory to explode nar contents to * @throws IllegalArgumentException if the NAR is missing the Java Services * API file for <tt>FlowFileProcessor</tt> implementations. * @throws ClassNotFoundException if any of the <tt>FlowFileProcessor</tt> * implementations defined by the Java Services API cannot be loaded. * @throws IOException if an error occurs while loading the NAR. */ public NarClassLoader(final File narWorkingDirectory) throws ClassNotFoundException, IOException { super(new URL[0]); this.narWorkingDirectory = narWorkingDirectory; // process the classpath updateClasspath(narWorkingDirectory); }
/** * Construct a nar class loader with the specific parent. * * @param narWorkingDirectory directory to explode nar contents to * @param parentClassLoader parent class loader of this nar * @throws IllegalArgumentException if the NAR is missing the Java Services * API file for <tt>FlowFileProcessor</tt> implementations. * @throws ClassNotFoundException if any of the <tt>FlowFileProcessor</tt> * implementations defined by the Java Services API cannot be loaded. * @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); this.narWorkingDirectory = narWorkingDirectory; // process the classpath updateClasspath(narWorkingDirectory); }
/** * Construct a nar class loader with the specific parent. * * @param narWorkingDirectory directory to explode nar contents to * @param parentClassLoader parent class loader of this nar * @throws IllegalArgumentException if the NAR is missing the Java Services * API file for <tt>FlowFileProcessor</tt> implementations. * @throws ClassNotFoundException if any of the <tt>FlowFileProcessor</tt> * implementations defined by the Java Services API cannot be loaded. * @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); this.narWorkingDirectory = narWorkingDirectory; // process the classpath updateClasspath(narWorkingDirectory); }