use of org.apache.commons.vfs2.impl.VFSClassLoader in project metron by apache.
the class VFSClassloaderUtil method configureClassloader.
/**
* Create a classloader backed by a virtual filesystem which can handle the following URI types:
* * res - resource files
* * jar
* * tar
* * bz2
* * tgz
* * zip
* * HDFS
* * FTP
* * HTTP/S
* * file
* @param paths A set of comma separated paths. The paths are URIs or URIs with a regex pattern at the end.
* @return A classloader object if it can create it
* @throws FileSystemException
*/
public static Optional<ClassLoader> configureClassloader(String paths) throws FileSystemException {
if (paths.trim().isEmpty()) {
return Optional.empty();
}
FileSystemManager vfs = generateVfs();
FileObject[] objects = resolve(vfs, paths);
if (objects == null || objects.length == 0) {
return Optional.empty();
}
return Optional.of(new VFSClassLoader(objects, vfs, vfs.getClass().getClassLoader()));
}
use of org.apache.commons.vfs2.impl.VFSClassLoader in project metron by apache.
the class ClasspathFunctionResolver method initialize.
@Override
public void initialize(Context context) {
super.initialize(context);
if (context != null) {
Optional<Object> optional = context.getCapability(STELLAR_CONFIG, false);
if (optional.isPresent()) {
Map<String, Object> stellarConfig = (Map<String, Object>) optional.get();
if (LOG.isDebugEnabled()) {
LOG.debug("Setting up classloader using the following config: {}", stellarConfig);
}
include(STELLAR_SEARCH_INCLUDES_KEY.get(stellarConfig, String.class).split(STELLAR_SEARCH_DELIMS));
exclude(STELLAR_SEARCH_EXCLUDES_KEY.get(stellarConfig, String.class).split(STELLAR_SEARCH_DELIMS));
Optional<ClassLoader> vfsLoader = Optional.empty();
try {
vfsLoader = VFSClassloaderUtil.configureClassloader(STELLAR_VFS_PATHS.get(stellarConfig, String.class));
if (vfsLoader.isPresent()) {
LOG.debug("CLASSLOADER LOADED WITH: {}", STELLAR_VFS_PATHS.get(stellarConfig, String.class));
if (LOG.isDebugEnabled()) {
for (FileObject fo : ((VFSClassLoader) vfsLoader.get()).getFileObjects()) {
LOG.error("{} - {}", fo.getURL(), fo.exists());
}
}
classLoaders(vfsLoader.get());
}
} catch (FileSystemException e) {
LOG.error("Unable to process filesystem: {}", e.getMessage(), e);
}
} else {
LOG.info("No stellar config set; I'm reverting to the context classpath with no restrictions.");
if (LOG.isDebugEnabled()) {
try {
throw new IllegalStateException("No config set, stacktrace follows.");
} catch (IllegalStateException ise) {
LOG.error(ise.getMessage(), ise);
}
}
}
} else {
throw new IllegalStateException("CONTEXT IS NULL!");
}
}
Aggregations