use of org.apache.commons.vfs2.VFS in project pentaho-kettle by pentaho.
the class JobEntryDeleteFile method execute.
public Result execute(Result previousResult, int nr) {
Result result = previousResult;
result.setResult(false);
// Set Embedded NamedCluter MetatStore Provider Key so that it can be passed to VFS
if (parentJobMeta.getNamedClusterEmbedManager() != null) {
parentJobMeta.getNamedClusterEmbedManager().passEmbeddedMetastoreKey(this, parentJobMeta.getEmbeddedMetastoreProviderKey());
}
if (filename != null) {
String realFilename = getRealFilename();
FileObject fileObject = null;
try {
fileObject = KettleVFS.getFileObject(realFilename, this);
if (!fileObject.exists()) {
if (isFailIfFileNotExists()) {
// File doesn't exist and fail flag is on.
result.setResult(false);
logError(BaseMessages.getString(PKG, "JobEntryDeleteFile.ERROR_0004_File_Does_Not_Exist", realFilename));
} else {
// File already deleted, no reason to try to delete it
result.setResult(true);
if (log.isBasic()) {
logBasic(BaseMessages.getString(PKG, "JobEntryDeleteFile.File_Already_Deleted", realFilename));
}
}
} else {
boolean deleted = fileObject.delete();
if (!deleted) {
logError(BaseMessages.getString(PKG, "JobEntryDeleteFile.ERROR_0005_Could_Not_Delete_File", realFilename));
result.setResult(false);
result.setNrErrors(1);
}
if (log.isBasic()) {
logBasic(BaseMessages.getString(PKG, "JobEntryDeleteFile.File_Deleted", realFilename));
}
result.setResult(true);
}
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobEntryDeleteFile.ERROR_0006_Exception_Deleting_File", realFilename, e.getMessage()), e);
result.setResult(false);
result.setNrErrors(1);
} finally {
if (fileObject != null) {
try {
fileObject.close();
} catch (IOException ex) {
/* Ignore */
}
}
}
} else {
logError(BaseMessages.getString(PKG, "JobEntryDeleteFile.ERROR_0007_No_Filename_Is_Defined"));
}
return result;
}
use of org.apache.commons.vfs2.VFS in project pentaho-kettle by pentaho.
the class RepositoryVfsProvider method registerRepoVFS.
private void registerRepoVFS() {
FileSystemManager fsm = KettleVFS.getInstance().getFileSystemManager();
if (fsm instanceof DefaultFileSystemManager) {
try {
((DefaultFileSystemManager) fsm).addProvider(SCHEME, this);
final Spoon spoon = Spoon.getInstance();
System.out.println();
} catch (Exception ex) {
throw new RuntimeException("Error initialize repo:// VFS", ex);
}
}
}
use of org.apache.commons.vfs2.VFS in project metron by apache.
the class VFSClassloaderUtil method generateVfs.
/**
* Create a FileSystem manager suitable for our purposes.
* This manager supports files of the following types:
* * res - resource files
* * jar
* * tar
* * bz2
* * tgz
* * zip
* * HDFS
* * FTP
* * HTTP/S
* * file
* @return vfs
* @throws FileSystemException
*/
public static FileSystemManager generateVfs() throws FileSystemException {
DefaultFileSystemManager vfs = new DefaultFileSystemManager();
vfs.addProvider("res", new org.apache.commons.vfs2.provider.res.ResourceFileProvider());
vfs.addProvider("zip", new org.apache.commons.vfs2.provider.zip.ZipFileProvider());
vfs.addProvider("gz", new org.apache.commons.vfs2.provider.gzip.GzipFileProvider());
vfs.addProvider("ram", new org.apache.commons.vfs2.provider.ram.RamFileProvider());
vfs.addProvider("file", new org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider());
vfs.addProvider("jar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
vfs.addProvider("http", new org.apache.commons.vfs2.provider.http.HttpFileProvider());
vfs.addProvider("https", new org.apache.commons.vfs2.provider.https.HttpsFileProvider());
vfs.addProvider("ftp", new org.apache.commons.vfs2.provider.ftp.FtpFileProvider());
vfs.addProvider("ftps", new org.apache.commons.vfs2.provider.ftps.FtpsFileProvider());
vfs.addProvider("war", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
vfs.addProvider("par", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
vfs.addProvider("ear", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
vfs.addProvider("sar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
vfs.addProvider("ejb3", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
vfs.addProvider("tmp", new org.apache.commons.vfs2.provider.temp.TemporaryFileProvider());
vfs.addProvider("tar", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
vfs.addProvider("tbz2", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
vfs.addProvider("tgz", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
vfs.addProvider("bz2", new org.apache.commons.vfs2.provider.bzip2.Bzip2FileProvider());
vfs.addProvider("hdfs", new HdfsFileProvider());
vfs.addExtensionMap("jar", "jar");
vfs.addExtensionMap("zip", "zip");
vfs.addExtensionMap("gz", "gz");
vfs.addExtensionMap("tar", "tar");
vfs.addExtensionMap("tbz2", "tar");
vfs.addExtensionMap("tgz", "tar");
vfs.addExtensionMap("bz2", "bz2");
vfs.addMimeTypeMap("application/x-tar", "tar");
vfs.addMimeTypeMap("application/x-gzip", "gz");
vfs.addMimeTypeMap("application/zip", "zip");
vfs.setFileContentInfoFactory(new FileContentInfoFilenameFactory());
vfs.setFilesCache(new SoftRefFilesCache());
vfs.setReplicator(new UniqueFileReplicator(new File(System.getProperty("java.io.tmpdir"))));
vfs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
vfs.init();
return vfs;
}
use of org.apache.commons.vfs2.VFS 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()]);
}
use of org.apache.commons.vfs2.VFS in project pentaho-platform by pentaho.
the class MondrianVfsTest method runCatalogTest.
private String runCatalogTest(final String expectedCatalog, final MondrianSchemaAnnotator annotator, final boolean annotationsExist) throws IOException {
MondrianVfs vfs = new MondrianVfs() {
@Override
FileObject getCatalogFileObject(final String catalog, final String fileName) {
assertEquals(expectedCatalog, catalog);
try {
if (fileName.equals("schema.xml")) {
return FileObjectTestHelper.mockFile(schemaContent, true);
}
if (fileName.equals("annotations.xml")) {
return FileObjectTestHelper.mockFile(annotationsContent, annotationsExist);
}
fail("unrecognized File");
return null;
} catch (FileSystemException e) {
fail(e.getMessage());
return null;
}
}
@Override
MondrianSchemaAnnotator getAnnotator() {
return annotator;
}
};
FileObject file = vfs.findFile(null, "mondrian:" + expectedCatalog, null);
return IOUtils.toString(file.getContent().getInputStream());
}
Aggregations