mirror of https://github.com/apache/nifi.git
NIFI-1647 This closes #288. fixed validators and config resolution
Signed-off-by: joewitt <joewitt@apache.org>
This commit is contained in:
parent
3a4546c08a
commit
bb738f978a
|
@ -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();
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue