Search in sources :

Example 31 with FileSystemManager

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

the class AccumuloVFSClassLoaderTest method testCacheDirectoryConfigured.

@Test
public void testCacheDirectoryConfigured() throws Exception {
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
    String cacheDir = "/some/random/cache/dir";
    File conf = folder1.newFile("accumulo-site.xml");
    FileWriter out = new FileWriter(conf);
    out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    out.append("<configuration>\n");
    out.append("<property>\n");
    out.append("<name>general.classpaths</name>\n");
    out.append("<value></value>\n");
    out.append("</property>\n");
    out.append("<property>\n");
    out.append("<name>" + AccumuloVFSClassLoader.VFS_CACHE_DIR + "</name>\n");
    out.append("<value>" + cacheDir + "</value>\n");
    out.append("</property>\n");
    out.append("</configuration>\n");
    out.close();
    Whitebox.setInternalState(AccumuloClassLoader.class, "accumuloConfigUrl", conf.toURI().toURL());
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
    AccumuloVFSClassLoader.getClassLoader();
    FileSystemManager manager = AccumuloVFSClassLoader.generateVfs();
    UniqueFileReplicator replicator = Whitebox.getInternalState(manager, "fileReplicator");
    File tempDir = Whitebox.getInternalState(replicator, "tempDir");
    String tempDirParent = tempDir.getParent();
    String tempDirName = tempDir.getName();
    Assert.assertTrue(cacheDir.equals(tempDirParent));
    Assert.assertTrue(tempDirName.startsWith("accumulo-vfs-cache-"));
    Assert.assertTrue(tempDirName.endsWith(System.getProperty("user.name", "nouser")));
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 32 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project pivot by apache.

the class VFSBrowser method setManager.

public void setManager(FileSystemManager manager) throws FileSystemException {
    FileSystemManager previousManager = this.manager;
    if (manager == null) {
        this.manager = VFS.getManager();
    } else {
        this.manager = manager;
    }
    FileObject baseFile = this.manager.getBaseFile();
    if (baseFile != null) {
        baseFileName = baseFile.getName();
    }
    if (previousManager != null && previousManager != this.manager) {
        fileBrowserListeners.managerChanged(this, previousManager);
    }
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) FileSystemManager(org.apache.commons.vfs2.FileSystemManager)

Example 33 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project jackrabbit by apache.

the class VFSFileSystem method createFileSystemManager.

/**
 * Creates a {@link FileSystemManager} instance.
 * @return a {@link FileSystemManager} instance.
 * @throws FileSystemException if an error occurs creating the manager.
 */
protected FileSystemManager createFileSystemManager() throws FileSystemException {
    FileSystemManager fileSystemManager = null;
    try {
        if (getFileSystemManagerClassName() == null) {
            fileSystemManager = new StandardFileSystemManager();
        } else {
            final Class<?> mgrClass = Class.forName(getFileSystemManagerClassName());
            fileSystemManager = (FileSystemManager) mgrClass.newInstance();
        }
        if (fileSystemManager instanceof DefaultFileSystemManager) {
            ((DefaultFileSystemManager) fileSystemManager).init();
        }
    } catch (final Exception e) {
        throw new FileSystemException("Could not create file system manager of class: " + getFileSystemManagerClassName(), e);
    }
    return fileSystemManager;
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException)

Example 34 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project jackrabbit by apache.

the class VFSFileSystem method init.

// -----------------------------------------------------------< FileSystem >
@Override
public void init() throws FileSystemException {
    overridePropertiesFromConfig();
    if (baseFolderUri == null) {
        throw new FileSystemException("VFS base folder URI must be set.");
    }
    fileSystemManager = createFileSystemManager();
    FileName baseFolderName = null;
    try {
        baseFolderName = fileSystemManager.resolveURI(baseFolderUri);
        final FileSystemOptions fso = getFileSystemOptions();
        if (fso != null) {
            baseFolder = fileSystemManager.resolveFile(baseFolderUri, fso);
        } else {
            baseFolder = fileSystemManager.resolveFile(baseFolderUri);
        }
        baseFolder.createFolder();
    } catch (org.apache.commons.vfs2.FileSystemException e) {
        throw new FileSystemException("Could not initialize the VFS base folder at '" + (baseFolderName == null ? "" : baseFolderName.getFriendlyURI()) + "'.", e);
    }
    log.info("VFSFileSystem initialized at the base path, {}.", baseFolderUri);
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FileName(org.apache.commons.vfs2.FileName) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 35 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project metron by apache.

the class VFSClassloaderUtil method resolve.

/**
 * Resolve a set of URIs into FileObject objects.
 * This is not recursive. The URIs can refer directly to a file or directory or an optional regex at the end.
 * (NOTE: This is NOT a glob).
 * @param vfs The file system manager to use to resolve URIs
 * @param uris comma separated URIs and URI + globs
 * @return
 * @throws FileSystemException
 */
static FileObject[] resolve(FileSystemManager vfs, String uris) throws FileSystemException {
    if (uris == null) {
        return new FileObject[0];
    }
    ArrayList<FileObject> classpath = new ArrayList<>();
    for (String path : uris.split(",")) {
        path = path.trim();
        if (path.equals("")) {
            continue;
        }
        FileObject fo = vfs.resolveFile(path);
        switch(fo.getType()) {
            case FILE:
            case FOLDER:
                classpath.add(fo);
                break;
            case IMAGINARY:
                // assume its a pattern
                String pattern = fo.getName().getBaseName();
                if (fo.getParent() != null && fo.getParent().getType() == FileType.FOLDER) {
                    FileObject[] children = fo.getParent().getChildren();
                    for (FileObject child : children) {
                        if (child.getType() == FileType.FILE && child.getName().getBaseName().matches(pattern)) {
                            classpath.add(child);
                        }
                    }
                } else {
                    LOG.warn("ignoring classpath entry {}", fo);
                }
                break;
            default:
                LOG.warn("ignoring classpath entry {}", fo);
                break;
        }
    }
    return classpath.toArray(new FileObject[classpath.size()]);
}
Also used : ArrayList(java.util.ArrayList) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

FileSystemManager (org.apache.commons.vfs2.FileSystemManager)30 FileObject (org.apache.commons.vfs2.FileObject)29 FileSystemException (org.apache.commons.vfs2.FileSystemException)21 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)17 File (java.io.File)12 IOException (java.io.IOException)11 StandardFileSystemManager (org.apache.commons.vfs2.impl.StandardFileSystemManager)7 Test (org.junit.Test)6 FileContent (org.apache.commons.vfs2.FileContent)4 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)4 OutputStream (java.io.OutputStream)3 RepositoryException (javax.jcr.RepositoryException)3 FileName (org.apache.commons.vfs2.FileName)3 SoftRefFilesCache (org.apache.commons.vfs2.cache.SoftRefFilesCache)3 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Map (java.util.Map)2