private List<URL> findJarsIn(FileObject path, final int maxdepth, final Set<String> paths) throws FileSystemException { FileObject[] jars = path.findFiles( new FileSelector() { @Override public boolean includeFile(FileSelectInfo info) throws Exception { for (String path : paths) { if (info.getFile().getURL().toString().endsWith(path)) { return false; } } return info.getFile().getName().getBaseName().endsWith(JAR_EXTENSION); } @Override public boolean traverseDescendents(FileSelectInfo info) throws Exception { for (String path : paths) { if (info.getFile().getURL().toString().endsWith(path)) { return false; } } return info.getDepth() <= maxdepth; } }); List<URL> jarUrls = new ArrayList<URL>(); for (FileObject jar : jars) { jarUrls.add(jar.getURL()); } return jarUrls; }
/** * Attempt to find any Hadoop configuration as a direct descendant of the provided directory. * * @param baseDir Directory to look for Hadoop configurations in * @throws ConfigurationException */ private void findHadoopConfigurations( FileObject baseDir, ActiveHadoopConfigurationLocator activeLocator) throws ConfigurationException { configurations = new HashMap<String, HadoopConfiguration>(); try { if (!baseDir.exists()) { throw new ConfigurationException( BaseMessages.getString( PKG, "Error.HadoopConfigurationDirectoryDoesNotExist", baseDir.getURL())); } for (FileObject f : baseDir.findFiles( new FileSelector() { @Override public boolean includeFile(FileSelectInfo info) throws Exception { return info.getDepth() == 1 && FileType.FOLDER.equals(info.getFile().getType()); } @Override public boolean traverseDescendents(FileSelectInfo info) throws Exception { return info.getDepth() == 0; } })) { // Only load the specified configuration (ID should match the basename, we allow // case-insensitivity) if (f.getName().getBaseName().equalsIgnoreCase(activeLocator.getActiveConfigurationId())) { HadoopConfiguration config = loadHadoopConfiguration(f); if (config != null) { configurations.put(config.getIdentifier(), config); } } } } catch (FileSystemException ex) { throw new ConfigurationException( BaseMessages.getString( PKG, "Error.UnableToLoadConfigurations", baseDir.getName().getFriendlyURI()), ex); } }