List of usage examples for org.apache.commons.io FileUtils listFiles
public static Collection listFiles(File directory, String[] extensions, boolean recursive)
From source file:com.ariht.maven.plugins.config.DirectoryReader.java
@SuppressWarnings("rawtypes") private Collection<File> getAllFiles(final File directory) { if (!directory.exists()) { log.warn("Directory does not exist: " + directory.getPath()); return EMPTY_FILE_LIST; }// w w w . j a v a 2 s . c o m final Collection allFiles = FileUtils.listFiles(directory, TrueFileFilter.TRUE, DirectoryFileFilter.DIRECTORY); final Collection<File> files = new ArrayList<File>(allFiles.size()); for (final Object o : allFiles) { if (o != null && o instanceof File) { final File file = (File) o; if (isFileToIgnore(file)) { log.info("Ignoring: " + file.toString()); } else { log.debug("Adding file: " + file.toString()); files.add(file); } } else { log.warn("Not a file: " + ToStringBuilder.reflectionToString(o)); } } return files; }
From source file:com.thoughtworks.go.plugin.infra.plugininfo.GoPluginOSGiManifest.java
private String buildClassPath() { StringBuilder header = new StringBuilder(CLASSPATH_PREFIX); if (!dependenciesDir.exists() || !dependenciesDir.isDirectory()) { return header.toString(); }// w w w . j av a 2 s . c om Collection<File> dependencyJars = FileUtils.listFiles(dependenciesDir, new String[] { "jar" }, false); for (File dependencyJarFileName : dependencyJars) { if (!ACTIVATOR_JAR_NAME.equals(dependencyJarFileName.getName())) { header.append(PLUGIN_DEPS_DIR_PREFIX).append(dependencyJarFileName.getName()); } } return header.toString(); }
From source file:fr.acxio.tools.agia.file.pdf.SplitPDFTaskletTest.java
@Test public void testSplit() throws Exception { SplitPDFTasklet aTasklet = new SplitPDFTasklet(); PageSplittingPDDocumentFactory aDocumentFactory = new PageSplittingPDDocumentFactory(); aDocumentFactory.setSplitAtPage(1);/*from ww w. j a v a2 s . co m*/ aTasklet.setDocumentFactory(aDocumentFactory); FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory(); aSourceFactory.setPattern("file:src/test/resources/testFiles/content*.pdf"); aTasklet.setSourceFactory(aSourceFactory); StandardEvaluationContextFactory aContextFactory = new StandardEvaluationContextFactory(); Map<String, Object> aCommonObjects = new HashMap<String, Object>(); aCommonObjects.put("fu", new FilenameUtils()); DateToStringConverter aDTSConverter = new DateToStringConverter(); aDTSConverter.setDestinationPattern("yyyyMMddhhmmssSSS"); aCommonObjects.put("dc", aDTSConverter); aCommonObjects.put("sr", new SecureRandom()); aContextFactory.setCommonObjects(aCommonObjects); ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory(); aDestinationFactory.setEvaluationContextFactory(aContextFactory); aDestinationFactory.setExpression( "target/ST-N-@{#fu.getBaseName(#in.SOURCE.filename)}-@{#dc.convert(new java.util.Date())}-@{#sr.nextInt(10000)}.pdf"); aTasklet.setDestinationFactory(aDestinationFactory); aTasklet.setForceReplace(false); StepContribution aStepContribution = mock(StepContribution.class); assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null)); Collection<File> aFilesTocheck = FileUtils.listFiles(new File("target"), new WildcardFileFilter("ST-N-*.pdf"), null); assertEquals(4, aFilesTocheck.size()); verify(aStepContribution, times(2)).incrementReadCount(); verify(aStepContribution, times(1)).incrementWriteCount(1); // content1.pdf verify(aStepContribution, times(1)).incrementWriteCount(3); // content2.pdf }
From source file:com.voodoowarez.alclassicist.CtDumpMojo.java
protected Collection<File> fetchFiles() { final Set<File> foundFiles = new HashSet<File>(); final File sourceDirFile = new File(this.sourceDirectory); for (String includePattern : this.includes) { final IOFileFilter filterPattern = new RegexFileFilter(includePattern); final Collection<File> matches = FileUtils.listFiles(sourceDirFile, filterPattern, TrueFileFilter.INSTANCE); foundFiles.addAll(matches);//from ww w . jav a 2s . c om } return foundFiles; }
From source file:de.uni_hildesheim.sse.easy.ant.modelcopy.ModelCopy.java
/** * Starts the copy process.//from www . j a v a2s.c o m * @throws ModelManagementException If IVML files could not be parsed * @throws IOException If files could not be copied. */ private void copy() throws ModelManagementException, IOException { // Initialize loadProject(getSourceFolder(), getMainProject()); Collection<File> originalFiles = FileUtils.listFiles(getSourceFolder(), new EASyModelFilter(), TrueFileFilter.INSTANCE); // Copy all files for (File file : originalFiles) { String relativeFileName = getSourceFolder().toURI().relativize(file.toURI()).getPath(); debugMessage("Processing: " + relativeFileName); File copyDestination = new File(getDestinationFolder(), relativeFileName); if (!copyDestination.exists()) { File destFolder = copyDestination.getParentFile(); destFolder.mkdirs(); if (!relativeFileName.toLowerCase().endsWith(CONFIG_FILE_EXTENSION)) { FileUtils.copyFile(file, copyDestination, false); } else { handleConfigFile(relativeFileName, destFolder); } } } }
From source file:ch.unibas.fittingwizard.infrastructure.RealFitScript.java
public static List<File> getAllFitTabFiles(File rootDir) { logger.info("getAllFitTabFiles"); List<File> files = new ArrayList<>(FileUtils.listFiles(rootDir, new IOFileFilter() { @Override//from w w w . ja v a 2 s .co m public boolean accept(File file) { return file.getName().endsWith(MtpfittabExtension); } @Override public boolean accept(File dir, String name) { return false; } }, TrueFileFilter.TRUE)); if (files.size() == 0) { throw new ScriptExecutionException("Could not find any fit tab results file in " + FilenameUtils.normalize(rootDir.getAbsolutePath())); } for (File file : files) { logger.info("Found fit tab file: " + FilenameUtils.normalize(file.getAbsolutePath())); } return files; }
From source file:com.smash.revolance.ui.model.application.ApplicationFactory.java
private void loadApplication(String appDir, String appId, String impl, String version) throws IOException { if (!appDir.isEmpty() && new File(appDir).isDirectory()) { Collection<File> files = FileUtils.listFiles(new File(appDir), new String[] { "jar" }, false); for (File file : files) { JarFile jar = new JarFile(file); Manifest manifest = jar.getManifest(); Attributes attributes = manifest.getMainAttributes(); String implAttr = attributes.getValue("revolance-ui-explorer-applicationImpl"); String versionAttr = attributes.getValue("revolance-ui-explorer-applicationVersion"); if (implAttr.contentEquals(impl) && (versionAttr.contentEquals(version) || version == null)) { applicationLoaders.put(getKey(appId, impl, version), new JarClassLoader(file.toURI().toURL())); }//from ww w . jav a2 s .co m } } }
From source file:com.c4om.autoconf.ulysses.configanalyzer.packager.CompressedFileConfigurationPackager.java
/** * This method returns a list of subpaths to all the files of a given directory (and its subdirectories). * If a file is provided, it returns a singleton list with the path to the file. * @param file the directory or file/*from ww w .j a v a2 s . co m*/ * @return the list of subpaths */ protected static List<String> getSubPathsRecursive(File file, File baseFile) { if (!(file.isAbsolute())) { throw new IllegalArgumentException( "The provided File object must be absolute. The provided one +(" + file + ") is not."); } if (file.isDirectory()) { Collection<File> files = FileUtils.listFiles(file, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); List<String> result = new ArrayList<>(); for (File currentFile : files) { result.add(relativizeFile(currentFile, baseFile).getPath()); } return result; } else { return Collections.singletonList(relativizeFile(file, baseFile).getPath()); } }
From source file:ijfx.core.imagedb.DefaultImageLoaderService.java
@Override public Collection<File> getAllImagesFromDirectory(File file) { return FileUtils.listFiles(file, getSupportedExtensions(), true); }
From source file:io.cloudslang.lang.commons.services.impl.SlangCompilationServiceImpl.java
@Override public Collection<File> listSlangFiles(File directory, boolean recursive) { Validate.isTrue(directory.isDirectory(), "Parameter '" + directory.getPath() + INVALID_DIRECTORY_ERROR_MESSAGE_SUFFIX); return FileUtils.listFiles(directory, new IOFileFilter() { @Override//from w ww . j a v a 2 s. c o m public boolean accept(File file) { return Extension.SL == Extension.findExtension(file.getName()); } @Override public boolean accept(File file, String name) { return Extension.SL == Extension.findExtension(name); } }, recursive ? TrueFileFilter.INSTANCE : null); }