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);
}
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);
}
}
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;
}
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);
}
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()]);
}
Aggregations