Repository: nifi Updated Branches: refs/heads/master 3a4546c08 -> bb738f978
NIFI-1647 This closes #288. fixed validators and config resolution Signed-off-by: joewitt <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/bb738f97 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/bb738f97 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/bb738f97 Branch: refs/heads/master Commit: bb738f978a44e787f8b73ece37361c067a258400 Parents: 3a4546c Author: Oleg Zhurakousky <[email protected]> Authored: Fri Mar 18 09:26:54 2016 -0400 Committer: joewitt <[email protected]> Committed: Fri Mar 18 10:11:00 2016 -0400 ---------------------------------------------------------------------- .../nifi/spring/SpringContextFactory.java | 36 ++++++++++++-------- .../nifi/spring/SpringContextProcessor.java | 26 ++++++-------- 2 files changed, 32 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/bb738f97/nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextFactory.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextFactory.java b/nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextFactory.java index ac95630..b1a474d 100644 --- a/nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextFactory.java +++ b/nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextFactory.java @@ -66,8 +66,8 @@ final class SpringContextFactory { * Thread.contextClassLoader can find such resources. */ static SpringDataExchanger createSpringContextDelegate(String classpath, String config) { - URL[] urls = gatherAdditionalClassPathUrls(classpath); - SpringContextClassLoader contextCl = new SpringContextClassLoader(urls, + List<URL> urls = gatherAdditionalClassPathUrls(classpath); + SpringContextClassLoader contextCl = new SpringContextClassLoader(urls.toArray(new URL[] {}), SpringContextFactory.class.getClassLoader()); ClassLoader tContextCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(contextCl); @@ -98,28 +98,34 @@ final class SpringContextFactory { /** * */ - private static URL[] gatherAdditionalClassPathUrls(String path) { + static List<URL> gatherAdditionalClassPathUrls(String classPathRoot) { if (logger.isDebugEnabled()) { - logger.debug("Adding additional resources from '" + path + "' to the classpath."); + logger.debug("Adding additional resources from '" + classPathRoot + "' to the classpath."); } - File libraryDir = new File(path); - if (libraryDir.exists() && libraryDir.isDirectory()) { - String[] cpResourceNames = libraryDir.list(); + File classPathRootFile = new File(classPathRoot); + if (classPathRootFile.exists() && classPathRootFile.isDirectory()) { + String[] cpResourceNames = classPathRootFile.list(); try { List<URL> urls = new ArrayList<>(); - for (int i = 0; i < cpResourceNames.length; i++) { - URL url = new File(libraryDir, cpResourceNames[i]).toURI().toURL(); - urls.add(url); - if (logger.isDebugEnabled()) { - logger.debug("Identifying additional resource to the classpath: " + url); + for (String resourceName : cpResourceNames) { + File r = new File(classPathRootFile, resourceName); + if (r.getName().toLowerCase().endsWith(".jar") || r.isDirectory()) { + URL url = r.toURI().toURL(); + urls.add(url); + if (logger.isDebugEnabled()) { + logger.debug("Identifying additional resource to the classpath: " + url); + } } } - return urls.toArray(new URL[] {}); + urls.add(classPathRootFile.toURI().toURL()); + + return urls; } catch (Exception e) { - throw new IllegalStateException("Failed to parse user libraries from '" + libraryDir.getAbsolutePath() + "'", e); + throw new IllegalStateException( + "Failed to parse user libraries from '" + classPathRootFile.getAbsolutePath() + "'", e); } } else { - throw new IllegalArgumentException("Path '" + libraryDir.getAbsolutePath() + throw new IllegalArgumentException("Path '" + classPathRootFile.getAbsolutePath() + "' is not valid because it doesn't exist or does not point to a directory."); } } http://git-wip-us.apache.org/repos/asf/nifi/blob/bb738f97/nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java b/nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java index b19c53d..d6ea6af 100644 --- a/nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java +++ b/nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java @@ -20,11 +20,11 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -143,13 +143,13 @@ public class SpringContextProcessor extends AbstractProcessor { .name("Application Context config path") .description("The path to the Spring Application Context configuration file relative to the classpath") .required(true) - .addValidator(new SpringContextConfigValidator()) + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) .build(); public static final PropertyDescriptor CTX_LIB_PATH = new PropertyDescriptor.Builder() .name("Application Context class path") .description("Path to the directory with resources (i.e., JARs, configuration files etc.) required to be on " + "the classpath of the ApplicationContext.") - .addValidator(new SpringContextConfigValidator()) + .addValidator(StandardValidators.createDirectoryExistsValidator(false, false)) .required(true) .build(); public static final PropertyDescriptor SEND_TIMEOUT = new PropertyDescriptor.Builder() @@ -281,6 +281,12 @@ public class SpringContextProcessor extends AbstractProcessor { this.receiveFromSpring(processSession); } + @Override + protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { + SpringContextConfigValidator v = new SpringContextConfigValidator(); + return Collections.singletonList(v.validate(CTX_CONFIG_PATH.getName(), null, validationContext)); + } + /** * */ @@ -425,18 +431,8 @@ public class SpringContextProcessor extends AbstractProcessor { List<URL> urls = new ArrayList<>(); URLClassLoader parentLoader = (URLClassLoader) SpringContextProcessor.class.getClassLoader(); urls.addAll(Arrays.asList(parentLoader.getURLs())); - String[] resourceNames = libDirPathFile.list(); - try { - for (String resourceName : resourceNames) { - File r = new File(libDirPathFile, resourceName); - if (!r.isDirectory() && !r.getName().startsWith(".")) { - URL url = new File(libDirPathFile, resourceName).toURI().toURL(); - urls.add(url); - } - } - } catch (MalformedURLException e) { - throw new IllegalStateException(e); - } + + urls.addAll(SpringContextFactory.gatherAdditionalClassPathUrls(libDirPathFile.getAbsolutePath())); boolean resolvable = false; try (URLClassLoader throwawayCl = new URLClassLoader(urls.toArray(new URL[] {}), null)) { resolvable = throwawayCl.findResource(configPath) != null;
