List of usage examples for org.apache.commons.io FileUtils listFiles
public static Collection listFiles(File directory, String[] extensions, boolean recursive)
From source file:edu.isistan.carcha.evaluator.CarchaEvaluator.java
/** * Evaluate.//from w w w . j a v a 2 s.c o m * * @param goldenDirectory the golden directory * @param annotatedDirectory the annotated directory * @throws UIMAException the uIMA exception * @throws IOException Signals that an I/O exception has occurred. */ public void evaluate(File goldenDirectory, File annotatedDirectory) throws UIMAException, IOException { File[] goldens = FileUtils.listFiles(goldenDirectory, new String[] { "xmi" }, false).toArray(new File[] {}); File[] annotated = FileUtils.listFiles(annotatedDirectory, new String[] { "xmi" }, false) .toArray(new File[] {}); for (int i = 0; i < goldens.length; i++) { String goldenFileName = goldens[i].getName(); String annotatedFileName = annotated[i].getName(); logger.info("\n----------------\nComparing " + goldenFileName + " with " + annotatedFileName + "\n----------------\n"); List<String> goldenSentences = Utils.extractCoveredTextAnnotations(goldens[i].getAbsolutePath(), Sentence.class); List<String> goldenConcern = Utils.extractCoveredTextAnnotations(goldens[i].getAbsolutePath(), DesignDecision.class); List<String> discoveredConcern = Utils.extractCoveredTextAnnotations(annotated[i].getAbsolutePath(), DesignDecision.class); goldenSentences.removeAll(discoveredConcern); goldenConcern.removeAll(discoveredConcern); logger.info("untraced concerns " + goldenConcern.size()); logger.info("untraced sentences " + goldenSentences.size()); } }
From source file:io.jenkins.plugins.pipelineaction.sources.GlobalRepoPipelineActionSet.java
/** * Rebuilds the list of {@link GlobalRepoPipelineAction}s and update {@link ExtensionList} accordingly. */// w w w. j a v a2 s. co m @Override public synchronized void rebuild() { File actionsDir = new File(repo.workspace, GlobalRepoPipelineAction.ACTIONS_PREFIX); // first time, build the initial list if (ours == null) ours = new CopyOnWriteList<PipelineAction>(); if (actionsDir.exists()) { Collection<File> children = FileUtils.listFiles(actionsDir, null, true // Recursive ); List<PipelineAction> list = new ArrayList<PipelineAction>(); for (File child : children) { if (!child.getName().endsWith(".groovy") || child.isDirectory()) continue; String className = child.getName().substring(0, child.getName().length() - 7); // Using className as name as well for right now. try { GroovyCodeSource scriptSource = new GroovyCodeSource(child); GlobalRepoPipelineAction action = new GlobalRepoPipelineAction(scriptSource, className, className, PipelineActionType.STANDARD, // Only supporting standard from global repo for now. Collections.<String, Boolean>emptyMap(), // No fields defined for now. true // Defaulting <></>o needing a node ); list.add(action); } catch (IOException e) { // Probably could be a better error message... throw new IllegalStateException("Could not open script source - " + getFullStackTrace(e)); } ours.replaceBy(list); } } }
From source file:mitm.application.djigzo.DjigzoConfigurator.java
@SuppressWarnings("unchecked") private static void initializeRegistry() { /*/* w ww .j ava 2s. c om*/ * Load additional spring config files and sort them. */ Collection<File> unsortedConfigFiles = FileUtils.listFiles(new File(additionalSpringConfigDir), new String[] { "xml" }, true /* recursive */); ArrayList<File> sortedConfigFiles = new ArrayList<File>(unsortedConfigFiles); Collections.sort(sortedConfigFiles, DefaultFileComparator.DEFAULT_COMPARATOR); String[] configFiles = new String[sortedConfigFiles.size() + 1]; /* * The main config should be loaded first */ configFiles[0] = springConfig; for (int i = 1; i < configFiles.length; i++) { configFiles[i] = sortedConfigFiles.get(i - 1).getPath(); } logger.info("spring config files: {}", StringUtils.join(configFiles, ", ")); DjigzoServiceRegistry.initialize(configFiles); }
From source file:localSPs.CubbyAPI.java
public double getStorageSize() throws IOException { BigInteger num = new BigInteger("1024"); String ans = ""; BigInteger totalMemory = new BigInteger("5368709120"); BigInteger used;/*from w ww.ja v a 2 s. com*/ File dir = new File(ROOT_PATH); long totalUsed = 0; // total bytes List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (File file : files) { totalUsed += file.length(); } used = new BigInteger(String.valueOf(totalUsed)); ans = totalMemory.subtract(used).divide(num).divide(num).toString();//MB return (Double.parseDouble(ans)); }
From source file:massbank.svn.SVNRegisterUtil.java
/** * Update to the svn//ww w .j a v a 2 s .c om */ private static boolean update(String targetDbName, boolean isRecord) { String baseUrl = MassBankEnv.get(MassBankEnv.KEY_BASE_URL); GetConfig conf = new GetConfig(baseUrl); String[] confNames = conf.getSiteName(); String[] confDbNames = conf.getDbName(); boolean found = false; int i = 0; for (i = 0; i < confDbNames.length; i++) { if (targetDbName.equals(confDbNames[i])) { found = true; break; } } if (!found) { return false; } String basePath = ""; String[] extensions = null; String subDirName = ""; if (isRecord) { basePath = MassBankEnv.get(MassBankEnv.KEY_ANNOTATION_PATH); extensions = new String[] { "txt" }; subDirName = "record"; } else { basePath = MassBankEnv.get(MassBankEnv.KEY_MOLFILE_PATH); extensions = new String[] { "mol", "tsv" }; subDirName = "molfile"; } String repoDirName = confNames[i]; String path1 = basePath + targetDbName; String path2 = SVNUtils.getWorkCopyPath(repoDirName, SVNOperation.WC_BACKUP_UPLOAD) + File.separator + subDirName; SVNOperation ope = null; try { ope = new SVNOperation(repoDirName, SVNOperation.WC_BACKUP_UPLOAD); File dir1 = new File(path1); File dir2 = new File(path2); if (!dir2.exists()) { dir2.mkdirs(); } List<File> fileList1 = (List<File>) FileUtils.listFiles(dir1, extensions, false); List<File> fileList2 = (List<File>) FileUtils.listFiles(dir2, extensions, false); FileDifference diff = new FileDifference(fileList1, fileList2); String[] addFilePaths = diff.getAddFilePaths(); String[] delFileNames = diff.getDeleteFileNames(); if (addFilePaths.length > 0) { ope.addEntry(addFilePaths, subDirName); } if (delFileNames.length > 0) { ope.deleteEntry(delFileNames, subDirName); } ope.end(); return true; } catch (Exception e) { e.printStackTrace(); ope.end(); return false; } }
From source file:com.tera.common.configuration.properties.CPropertyLoader.java
/** * @param directory/*from w ww . ja v a2 s.co m*/ * @return * @throws IOException */ private Properties[] loadPropertiesFromDirectory(File directory) throws IOException { Collection<File> dirFiles = FileUtils.listFiles(directory, new String[] { "properties" }, true); return loadPropertiesFromFiles(dirFiles.toArray(new File[dirFiles.size()])); }
From source file:net.ageto.gyrex.impex.common.steps.impl.filename.FirstFilenameInAlphabeticalOrder.java
@SuppressWarnings("unchecked") @Override/* w w w . j av a2 s. co m*/ protected StatusStep process() { // file path String filepath = (String) getInputParam( FirstFilenameInAlphabeticalOrderDefinition.InputParamNames.INPUT_FILEPATH.name()); // file extensions ArrayList<String> fileExtension = (ArrayList<String>) getInputParam( FirstFilenameInAlphabeticalOrderDefinition.InputParamNames.INPUT_FILE_EXTENSION_FILTER.name()); String[] fileExtensionsArray = fileExtension == null ? null : (String[]) fileExtension.toArray(); // recursive, include subdirectories Boolean recursive = (Boolean) getInputParam( FirstFilenameInAlphabeticalOrderDefinition.InputParamNames.INPUT_INCLUDE_SUBDIRECTORIES.name()); // all files from the given file path Collection<File> listFiles = FileUtils.listFiles(new File(filepath), fileExtensionsArray, BooleanUtils.toBoolean(recursive)); if (listFiles.size() == 0) { processWarn("No file was found in folder \"{0}\" with file extension \"{1}\".", filepath, StringUtils.defaultIfEmpty(StringUtils.join(fileExtensionsArray, " "), "*")); // cancel process return StatusStep.CANCEL; } // fetch first file (alphabetical order) for (File file : listFiles) { setOutputParam(FirstFilenameInAlphabeticalOrderDefinition.OutputParamNames.OUTPUT_FILENAME.name(), file.getAbsolutePath()); processInfo("File \"{0}\" was found in folder \"{1}\" with file extension \"{2}\".", file.getAbsolutePath(), filepath, StringUtils.defaultIfEmpty(StringUtils.join(fileExtensionsArray, " "), "*")); break; } processInfo("{0} has been completed successfully.", ID); return StatusStep.OK; }
From source file:ch.sventschui.maven.visualizer.VisualizerMojo.java
public void execute() throws MojoExecutionException { this.createOutputDir(); for (String directory : this.directories) { this.poms.addAll(FileUtils.listFiles(new File(directory), new PomFileFilter(), new TargetFileFilter())); }// w ww .ja v a2 s. co m for (File pom : this.poms) { Model model = null; FileReader reader = null; MavenXpp3Reader mavenreader = new MavenXpp3Reader(); try { reader = new FileReader(pom); model = mavenreader.read(reader); model.setPomFile(pom); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XmlPullParserException e) { // TODO Auto-generated catch block e.printStackTrace(); } MavenProject project = new MavenProject(model); MavenArtifact base = new MavenArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion()); if (this.filter.matches(base)) { this.store.addArtifact(base); for (Dependency artifact : project.getDependencies()) { MavenArtifact dependency = new MavenArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); if (this.filter.matches(dependency)) { this.store.addArtifact(dependency); this.store.addRelationship(base, dependency); } } } } try { FileWriter fstream = new FileWriter(new File(this.outputDir, "test.json")); BufferedWriter out = new BufferedWriter(fstream); out.write(this.store.toJSON()); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.github.cereda.arara.rulechecker.RuleUtils.java
/** * Finds all rules from the provided directory. * @param directory The provided directory. * @return A list of files matching the rule pattern. *///from w w w . java2 s. com public static List<File> findRules(File directory) { // we expect a directory, if not, halt if (!directory.isDirectory()) { // print error message System.err.println(WordUtils.wrap("Fatal exception: The provided argument could not " + "be resolved to a proper directory. I am afraid " + "I won't be able to continue. Please make sure the " + "argument resolves to a valid directory reference. " + "The application will halt now.", 60)); System.exit(1); } // we have a valid directory, in that case, return // a list of all files ending with .yaml return new ArrayList(FileUtils.listFiles(directory, new SuffixFileFilter(".yaml"), FalseFileFilter.FALSE)); }
From source file:com.mirth.connect.cli.launcher.CommandLineLauncher.java
private static void addManifestToClasspath(ManifestEntry[] manifestEntries, List<URL> urls) throws Exception { for (ManifestEntry manifestEntry : manifestEntries) { File manifestEntryFile = new File(manifestEntry.getName()); if (manifestEntryFile.exists()) { if (manifestEntryFile.isDirectory()) { ManifestDirectory manifestDir = (ManifestDirectory) manifestEntry; IOFileFilter fileFilter = null; if (manifestDir.getExcludes().length > 0) { fileFilter = FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.notFileFilter(new NameFileFilter(manifestDir.getExcludes()))); } else { fileFilter = FileFilterUtils.fileFileFilter(); }/*from w w w .j ava2s . c om*/ Collection<File> pathFiles = FileUtils.listFiles(manifestEntryFile, fileFilter, FileFilterUtils.trueFileFilter()); for (File pathFile : pathFiles) { logger.trace("adding library to classpath: " + pathFile.getAbsolutePath()); urls.add(pathFile.toURI().toURL()); } } else { logger.trace("adding library to classpath: " + manifestEntryFile.getAbsolutePath()); urls.add(manifestEntryFile.toURI().toURL()); } } else { logger.warn("manifest path not found: " + manifestEntryFile.getAbsolutePath()); } } }