List of usage examples for org.apache.commons.vfs2 FileSelectInfo getBaseFolder
FileObject getBaseFolder();
From source file:org.pentaho.hadoop.shim.common.DistributedCacheUtilImpl.java
/** * Attempts to find a plugin's installation folder on disk within all known plugin folder locations * * @param pluginFolderName Name of plugin folder * @return Tuple of [(FileObject) Location of the first plugin folder found as a direct descendant of one of the known * plugin folder locations, (String) Relative path from parent] * @throws KettleFileException Error getting plugin folders *//*from w ww.ja v a2s.c o m*/ protected Object[] findPluginFolder(final String pluginFolderName) throws KettleFileException { List<PluginFolderInterface> pluginFolders = PluginFolder.populateFolders(null); if (pluginFolders != null) { for (PluginFolderInterface pluginFolder : pluginFolders) { FileObject folder = KettleVFS.getFileObject(pluginFolder.getFolder()); try { if (folder.exists()) { FileObject[] files = folder.findFiles(new FileSelector() { @Override public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception { if (fileSelectInfo.getFile().equals(fileSelectInfo.getBaseFolder())) { // Do not consider the base folders return false; } // Determine relative name to compare int baseNameLength = fileSelectInfo.getBaseFolder().getName().getPath().length() + 1; String relativeName = fileSelectInfo.getFile().getName().getPath() .substring(baseNameLength); // Compare plugin folder name with the relative name return pluginFolderName.equals(relativeName); } @Override public boolean traverseDescendents(FileSelectInfo fileSelectInfo) throws Exception { return true; } }); if (files != null && files.length > 0) { return new Object[] { files[0], folder.getName().getRelativeName(files[0].getName()) }; // Return the first match } } } catch (FileSystemException ex) { throw new KettleFileException("Error searching for folder '" + pluginFolderName + "'", ex); } } } return null; }