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