List of usage examples for org.apache.commons.io FileUtils listFiles
public static Collection listFiles(File directory, String[] extensions, boolean recursive)
From source file:adalid.util.io.FileBrowser.java
private boolean readFiles() { Collection<File> list = FileUtils.listFiles(resourcesFolder, fileFilter(), dirFilter()); SmallFile sf;/*from w w w .ja v a 2 s.c om*/ Charset charset; String name; String extension; for (File file : list) { sf = new SmallFile(file.getPath()); sf.read(); charset = sf.getCharset(); name = sf.getName(); extension = StringUtils.defaultIfBlank(sf.getExtension().toLowerCase(), "?"); if (charset == null) { readingErrors++; logger.error(name + " could not be read using any of the specified character sets "); } else if (sf.isEmpty()) { readingWarnings++; logger.warn(name + " is empty "); } else { files.put(sf.getPath(), sf); updateFileTypes(charset + ""); updateFileTypes(charset + " / " + extension); } } return true; }
From source file:com.offbynull.coroutines.antplugin.InstrumentTask.java
@Override public void execute() throws BuildException { // Check classpath if (classpath == null) { throw new BuildException("Classpath not set"); }/*from w w w . ja va 2s . c om*/ // Check source directory if (sourceDirectory == null) { throw new BuildException("Source directory not set"); } if (!sourceDirectory.isDirectory()) { throw new BuildException("Source directory is not a directory: " + sourceDirectory.getAbsolutePath()); } // Check target directory if (targetDirectory == null) { throw new BuildException("Target directory not set"); } try { FileUtils.forceMkdir(targetDirectory); } catch (IOException ioe) { throw new BuildException("Unable to create target directory", ioe); } // Check JDK libs directory if (jdkLibsDirectory == null) { throw new BuildException("JDK libs directory not set"); } if (!jdkLibsDirectory.isDirectory()) { throw new BuildException( "JDK libs directory is not a directory: " + jdkLibsDirectory.getAbsolutePath()); } List<File> combinedClasspath; try { log("Getting compile classpath", Project.MSG_DEBUG); combinedClasspath = Arrays.stream(classpath.split(";")).map(x -> x.trim()).filter(x -> !x.isEmpty()) .map(x -> new File(x)).collect(Collectors.toList()); log("Getting bootstrap classpath", Project.MSG_DEBUG); combinedClasspath.addAll(FileUtils.listFiles(jdkLibsDirectory, new String[] { "jar" }, true)); log("Classpath for instrumentation is as follows: " + combinedClasspath, Project.MSG_INFO); } catch (Exception ex) { throw new BuildException("Unable to get compile classpath elements", ex); } Instrumenter instrumenter; try { log("Creating instrumenter...", Project.MSG_INFO); instrumenter = new Instrumenter(combinedClasspath); log("Processing " + sourceDirectory.getAbsolutePath() + " ... ", Project.MSG_INFO); instrumentPath(instrumenter); } catch (Exception ex) { throw new BuildException("Failed to instrument", ex); } }
From source file:com.amazonaws.eclipse.dynamodb.testtool.TestToolProcess.java
/** * Searches within the install directory for the native libraries required * by DyanmoDB Local (i.e. SQLite) and returns the directory containing the * native libraries.//w ww .j a v a 2s . c o m * * @return The directory within the install directory where native libraries * were found; otherwise, if no native libraries are found, the * install directory is returned. */ private File findLibraryDirectory() { // Mac and Linux libraries start with "libsqlite4java-" so // use that pattern to identify the library directory IOFileFilter fileFilter = new AbstractFileFilter() { public boolean accept(File dir, String name) { return name.startsWith("libsqlite4java-"); } }; Collection<File> files = FileUtils.listFiles(installDirectory, fileFilter, TrueFileFilter.INSTANCE); // Log a warning if we can't identify the library directory, // and then just try to use the install directory if (files == null || files.isEmpty()) { Status status = new Status(IStatus.WARNING, DynamoDBPlugin.PLUGIN_ID, "Unable to find DynamoDB Local native libraries in " + installDirectory); AwsToolkitCore.getDefault().getLog().log(status); return installDirectory; } return files.iterator().next().getParentFile(); }
From source file:net.certiv.antlr.project.regen.ReGen.java
private void updateRuleSet(Map<String, Unit> units) { int existing = units.size(); int pastPrime = 0; int primary = 0; for (Unit u : units.values()) { if (u.primary) pastPrime++;/* w ww .j a va2 s .co m*/ u.primary = false; } File[] modelRoots = config.findModelRoots(config.getModelBasePath()); for (File root : modelRoots) { if (root.isFile()) { primary += evaluateUnit(units, null, root); } else if (root.isDirectory()) { int num = config.getCheckedTypes().size(); String[] checkedTypes = config.getCheckedTypes().toArray(new String[num]); for (File file : FileUtils.listFiles(root, checkedTypes, true)) { primary += evaluateUnit(units, root, file); } } } int nowNon = units.size() - primary; int netPrimary = primary - pastPrime; int netNon = nowNon - (existing - pastPrime); Log.info(this, "Units: " + units.size() + " [primary=" + primary + ", non=" + nowNon + "]" + " (net=" + netPrimary + "/" + netNon + ")"); Log.info(this, "Base model package identified as: " + config.getRuleSet().modelBasePackage); Log.info(this, "Model grammar identified as: " + config.getRuleSet().modelGrammar); try { config.saveRuleSet(); } catch (IOException e) { Log.fatal(this, "Failed to save updated rule set", e); } }
From source file:it.geosolutions.geostore.services.rest.auditing.AuditingTestsUtils.java
static void checkDirectoryIsEmpty(File directory) { Assert.assertEquals(FileUtils.listFiles(directory, null, false).size(), 0); }
From source file:net.peakplatform.sonar.plugins.spring.file.SpringProjectFileSystem.java
public List<InputFile> getFiles() { List<InputFile> result = Lists.newArrayList(); if (getSourceDirs() == null) { return result; }/*from www.ja va 2s . c om*/ IOFileFilter suffixFilter = getFileSuffixFilter(); WildcardPattern[] exclusionPatterns = getExclusionPatterns(true); IOFileFilter visibleFileFilter = HiddenFileFilter.VISIBLE; for (File dir : getSourceDirs()) { if (dir.exists()) { // exclusion filter IOFileFilter exclusionFilter = new ExclusionFilter(dir, exclusionPatterns); // visible filter List<IOFileFilter> fileFilters = Lists.newArrayList(visibleFileFilter, suffixFilter, exclusionFilter); // inclusion filter String inclusionPattern = (String) project.getProperty(SpringPlugin.INCLUDE_FILE_FILTER); if (inclusionPattern != null) { fileFilters.add(new InclusionFilter(dir, inclusionPattern)); } fileFilters.addAll(this.filters); // create DefaultInputFile for each file. List<File> files = (List<File>) FileUtils.listFiles(dir, new AndFileFilter(fileFilters), HiddenFileFilter.VISIBLE); for (File file : files) { String relativePath = DefaultProjectFileSystem.getRelativePath(file, dir); result.add(new DefaultInputFile(dir, relativePath)); } } } return result; }
From source file:ctrus.pa.bow.DefaultBagOfWords.java
protected Collection<File> getSourceDocuments(String wildCard) throws MissingOptionException { File sourceDir = new File(_options.getOption(DefaultOptions.SOURCE_DIR)); CtrusHelper.printToConsole("Choosen source folder - " + sourceDir.getAbsolutePath()); if (sourceDir.exists()) { return FileUtils.listFiles(sourceDir, new WildcardFileFilter(wildCard), DirectoryFileFilter.DIRECTORY); } else {/*ww w . j a va 2 s.c o m*/ throw new MissingOptionException("Unable to find source directory!"); } }
From source file:de.extra.client.plugins.outputplugin.mtomws.WsCxfIT.java
/** * @return// w w w. ja v a 2 s . c o m * @throws XmlMappingException * @throws IOException */ private List<RequestTransport> createTestsTransportsWithFileAttachment() throws XmlMappingException, IOException { logger.info("Looking for Inptut into the Directory: " + inputDirectory.getAbsolutePath()); final List<RequestTransport> transports = new ArrayList<RequestTransport>(); final Collection<File> listFiles = FileUtils.listFiles(inputDirectory, TrueFileFilter.INSTANCE, null); for (final File inputFile : listFiles) { final RequestTransport requestTransport = createDummyRequestTransport(); final RequestTransport filledTransport = fillInputFile(requestTransport, inputFile); transports.add(filledTransport); logger.info("Find File to send: " + inputFile.getName()); logger.info("ChecksumCRC32: " + FileUtils.checksumCRC32(inputFile)); logger.info("Filesize: " + FileUtils.sizeOf(inputFile)); } return transports; }
From source file:it.wingstech.csslesser.LessifyMojo.java
@Override public void execute() throws MojoExecutionException { srcFolderName = srcFolderName.replace('\\', File.separatorChar).replace('/', File.separatorChar); outputFolderName = outputFolderName.replace('\\', File.separatorChar).replace('/', File.separatorChar); if (lessResources == null || lessResources.length == 0) { lessResources = new Resource[1]; lessResources[0] = new Resource(); lessResources[0].setDirectory(srcFolderName); }// w w w . j av a2 s .co m for (Resource resource : lessResources) { String[] resources = getIncludedFiles(resource); String directory = resource.getDirectory(); getLog().info("Copying resources..."); for (String path : resources) { try { FileUtils.copyFile( new File(project.getBasedir() + File.separator + directory + File.separator + path), new File(outputFolderName + File.separator + path)); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } } if (lessify) { getLog().info("Performing less transformation..."); LessEngine engine = new LessEngine(); for (String path : resources) { if (path.toUpperCase().endsWith(".LESS")) { try { File inputFile = new File(outputFolderName + File.separator + path); File outputFile = new File(outputFolderName + File.separator + path.substring(0, path.length() - 5) + ".css"); getLog().info("LESS processing file: " + path + " ..."); engine.compile(inputFile, outputFile); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } } } } if (cssCompress) { getLog().info("Performing css compression..."); Collection<File> inputFiles = FileUtils.listFiles(new File(outputFolderName), new String[] { "css" }, true); for (File inputFile : inputFiles) { getLog().info("Compressing file: " + inputFile.getPath() + " ..."); compress(inputFile); } } if (cssInline) { getLog().info("Performing css inlining..."); Collection<File> inputFiles = FileUtils.listFiles(new File(outputFolderName), new String[] { "css" }, true); for (File inputFile : inputFiles) { getLog().info("Inlining file: " + inputFile.getPath() + " ..."); inline(inputFile, "."); } } } }
From source file:com.ning.arecibo.util.timeline.persistent.Replayer.java
public void purgeOldFiles(final DateTime purgeIfOlderDate) { final Collection<File> files = FileUtils.listFiles(new File(path), new String[] { "bin" }, false); for (final File file : files) { if (FileUtils.isFileOlder(file, new Date(purgeIfOlderDate.getMillis()))) { if (!file.delete()) { log.warn("Unable to delete file: {}", file.getAbsolutePath()); }/*from w ww . j av a 2s . com*/ } } }