Search in sources :

Example 1 with VFSClassLoader

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()));
}
Also used : VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) FileObject(org.apache.commons.vfs2.FileObject) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager)

Example 2 with VFSClassLoader

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!");
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) FileObject(org.apache.commons.vfs2.FileObject) FileObject(org.apache.commons.vfs2.FileObject) Map(java.util.Map)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)2 VFSClassLoader (org.apache.commons.vfs2.impl.VFSClassLoader)2 Map (java.util.Map)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)1 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)1