Search in sources :

Example 1 with FileSystem

use of org.apache.commons.vfs2.FileSystem in project accumulo by apache.

the class AccumuloVFSClassLoader method getClassLoader.

public static ClassLoader getClassLoader() throws IOException {
    ReloadingClassLoader localLoader = loader;
    while (null == localLoader) {
        synchronized (lock) {
            if (null == loader) {
                FileSystemManager vfs = generateVfs();
                // Set up the 2nd tier class loader
                if (null == parent) {
                    parent = AccumuloClassLoader.getClassLoader();
                }
                FileObject[] vfsCP = resolve(vfs, AccumuloClassLoader.getAccumuloProperty(VFS_CLASSLOADER_SYSTEM_CLASSPATH_PROPERTY, ""));
                if (vfsCP.length == 0) {
                    localLoader = createDynamicClassloader(parent);
                    loader = localLoader;
                    return localLoader.getClassLoader();
                }
                // Create the Accumulo Context ClassLoader using the DEFAULT_CONTEXT
                localLoader = createDynamicClassloader(new VFSClassLoader(vfsCP, vfs, parent));
                loader = localLoader;
                // and SequenceFile$Reader was trying to instantiate the key class via WritableName.getClass(String, Configuration)
                for (FileObject fo : vfsCP) {
                    if (fo instanceof HdfsFileObject) {
                        String uri = fo.getName().getRootURI();
                        Configuration c = new Configuration(true);
                        c.set(FileSystem.FS_DEFAULT_NAME_KEY, uri);
                        FileSystem fs = FileSystem.get(c);
                        fs.getConf().setClassLoader(loader.getClassLoader());
                    }
                }
            }
        }
    }
    return localLoader.getClassLoader();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HdfsFileObject(org.apache.commons.vfs2.provider.hdfs.HdfsFileObject) FileSystem(org.apache.hadoop.fs.FileSystem) VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) FileObject(org.apache.commons.vfs2.FileObject) HdfsFileObject(org.apache.commons.vfs2.provider.hdfs.HdfsFileObject) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager)

Example 2 with FileSystem

use of org.apache.commons.vfs2.FileSystem 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 {
    LOG.debug("Configuring class loader with paths = {}", paths);
    if (paths.trim().isEmpty()) {
        LOG.debug("No paths provided. Not returning a ClassLoader.");
        return Optional.empty();
    }
    FileSystemManager vfs = generateVfs();
    FileObject[] objects = resolve(vfs, paths);
    if (objects == null || objects.length == 0) {
        LOG.debug("No Classloader able to be resolved from provided paths. Not returning a ClassLoader.");
        return Optional.empty();
    }
    LOG.debug("vfs = {}, objects = {}", vfs, objects);
    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 3 with FileSystem

use of org.apache.commons.vfs2.FileSystem in project pentaho-metaverse by pentaho.

the class KettleAnalyzerUtil method normalizeFilePath.

/**
 * Utility method for normalizing file paths used in Metaverse Id generation. It will convert a valid path into a
 * consistent path regardless of URI notation or filesystem absolute path.
 *
 * @param filePath full path to normalize
 * @return the normalized path
 */
public static String normalizeFilePath(String filePath) throws MetaverseException {
    try {
        String path = filePath;
        FileObject fo = KettleVFS.getFileObject(filePath);
        try {
            path = getDecodedUriString(fo.getURL().getPath());
        } catch (Throwable t) {
        // Something went wrong with VFS, just try the filePath
        }
        File f = new File(path);
        return f.getAbsolutePath();
    } catch (Exception e) {
        throw new MetaverseException(e);
    }
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) MetaverseException(org.pentaho.metaverse.api.MetaverseException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileNotFoundException(java.io.FileNotFoundException) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) MetaverseException(org.pentaho.metaverse.api.MetaverseException)

Example 4 with FileSystem

use of org.apache.commons.vfs2.FileSystem in project spoofax by metaborg.

the class SpoofaxLanguageTest method discoverLanguage.

/**
 * The 'res://' filesystem redirects to resources inside the tests' JAR file or class file location, which are copied
 * to the class file location from src/test/resources by Maven. The binary files of the Entity language are located
 * in the resources to test language discovery.
 */
@Test
public void discoverLanguage() throws Exception {
    final FileObject location = resourceService.resolve("res://languages");
    final Iterable<ILanguageComponent> languages = languageDiscoveryService.discover(languageDiscoveryService.request(location));
    assertEquals(1, Iterables.size(languages));
    final ILanguageComponent component = Iterables.get(languages, 0);
    final ILanguageImpl impl = Iterables.get(component.contributesTo(), 0);
    final ILanguage language = impl.belongsTo();
    assertEquals("Entity", language.name());
    assertEquals(resourceService.resolve("res://languages/Entity"), component.location());
    final IdentificationFacet identificationFacet = impl.facet(IdentificationFacet.class);
    assertTrue(identificationFacet.identify(resourceService.resolve("ram:///Entity/test.ent")));
    final SyntaxFacet syntaxFacet = impl.facet(SyntaxFacet.class);
    assertEquals(resourceService.resolve("res://languages/Entity/target/metaborg/sdf.tbl"), syntaxFacet.parseTable);
    assertIterableEquals(syntaxFacet.startSymbols, "Start");
    final DynamicClassLoadingFacet dynamicClassLoadingFacet = impl.facet(DynamicClassLoadingFacet.class);
    final StrategoRuntimeFacet strategoRuntimeFacet = impl.facet(StrategoRuntimeFacet.class);
    assertIterableEquals(strategoRuntimeFacet.ctreeFiles, resourceService.resolve("res://languages/Entity/target/metaborg/stratego.ctree"));
    assertIterableEquals(dynamicClassLoadingFacet.jarFiles, resourceService.resolve("res://languages/Entity/target/metaborg/stratego.jar"));
    final AnalysisFacet analysisFacet = impl.facet(AnalysisFacet.class);
    assertEquals("editor-analyze", analysisFacet.strategyName);
}
Also used : DynamicClassLoadingFacet(org.metaborg.spoofax.core.dynamicclassloading.DynamicClassLoadingFacet) ILanguage(org.metaborg.core.language.ILanguage) SyntaxFacet(org.metaborg.spoofax.core.syntax.SyntaxFacet) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) IdentificationFacet(org.metaborg.core.language.IdentificationFacet) FileObject(org.apache.commons.vfs2.FileObject) AnalysisFacet(org.metaborg.spoofax.core.analysis.AnalysisFacet) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) StrategoRuntimeFacet(org.metaborg.spoofax.core.stratego.StrategoRuntimeFacet) Test(org.junit.Test) LanguageServiceTest(org.metaborg.core.test.language.LanguageServiceTest)

Example 5 with FileSystem

use of org.apache.commons.vfs2.FileSystem in project artisynth_core by artisynth.

the class FileCacher method copy.

public boolean copy(URIx from, URIx to, FileTransferMonitor monitor) throws FileSystemException {
    FileObject fromFile = null;
    FileObject toFile = null;
    // clear authenticators
    setAuthenticator(fsOpts, null);
    setIdentityFactory(fsOpts, null);
    // loop through authenticators until we either succeed or cancel
    boolean cancel = false;
    while (toFile == null && cancel == false) {
        toFile = resolveRemote(to);
    }
    cancel = false;
    while (fromFile == null && cancel == false) {
        fromFile = resolveRemote(from);
    }
    if (fromFile == null || !fromFile.exists()) {
        throw new FileSystemException("Cannot find source file <" + from.toString() + ">", new FileNotFoundException("<" + from.toString() + ">"));
    }
    if (toFile == null) {
        throw new FileSystemException("Cannot find destination <" + to.toString() + ">", new FileNotFoundException("<" + to.toString() + ">"));
    }
    // monitor the file transfer progress
    if (monitor != null) {
        monitor.monitor(fromFile, toFile, -1, fromFile.getName().getBaseName());
        monitor.start();
        monitor.fireStartEvent(toFile);
    }
    // transfer content
    try {
        if (fromFile.isFile()) {
            toFile.copyFrom(fromFile, Selectors.SELECT_SELF);
        } else if (fromFile.isFolder()) {
            // final FileObject fileSystem = manager.createFileSystem(remoteFile);
            toFile.copyFrom(fromFile, new AllFileSelector());
        // fileSystem.close();
        }
        if (monitor != null) {
            monitor.fireCompleteEvent(toFile);
        }
    } catch (Exception e) {
        throw new FileTransferException("Failed to complete transfer of " + fromFile.getURL() + " to " + toFile.getURL(), e);
    } finally {
        // close files if we need to
        fromFile.close();
        toFile.close();
        if (monitor != null) {
            monitor.release(toFile);
            monitor.stop();
        }
    }
    return true;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) AllFileSelector(org.apache.commons.vfs2.AllFileSelector) FileNotFoundException(java.io.FileNotFoundException) FileObject(org.apache.commons.vfs2.FileObject) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileNotFoundException(java.io.FileNotFoundException) JSchException(com.jcraft.jsch.JSchException)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)49 Test (org.junit.Test)30 FileSystemException (org.apache.commons.vfs2.FileSystemException)26 FileSystem (org.apache.commons.vfs2.FileSystem)19 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)18 Path (org.apache.hadoop.fs.Path)16 IOException (java.io.IOException)15 Configuration (org.apache.hadoop.conf.Configuration)15 FileName (org.apache.commons.vfs2.FileName)14 File (java.io.File)13 AllFileSelector (org.apache.commons.vfs2.AllFileSelector)13 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)13 FileSystem (org.apache.hadoop.fs.FileSystem)13 GenericFileName (org.apache.commons.vfs2.provider.GenericFileName)12 FileNotFoundException (java.io.FileNotFoundException)10 UserAuthenticationData (org.apache.commons.vfs2.UserAuthenticationData)9 URI (java.net.URI)7 PrivilegedActionException (java.security.PrivilegedActionException)7 FileNotFolderException (org.apache.commons.vfs2.FileNotFolderException)7 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)6