/** * Scan a directory for packages that match. This method is used prior to * finding a matching directory. Once the package names is matched * handleDir() is used. * * @param classes * The classes that have been found. * @param packageName * The package name for classes to find. * @param dir * The directory to scan. * @param cFilter * The class acceptance filter. */ private static void scanDir(Set<String> classes, String packageName, File dir, ClassPathFilter cFilter) { if (!dir.exists()) { return; } if (dir.isDirectory()) { if (dir.getPath().endsWith(packageName.replace('.', '/'))) { // we have a match handleDir(classes, packageName, dir, cFilter); } else { // no match check next level for (File file : dir.listFiles((FileFilter) new AndFileFilter(DirectoryFileFilter.DIRECTORY, new NotFileFilter(new PrefixFileFilter("."))))) { scanDir(classes, packageName, file, cFilter); } } } // if it is not a directory we don't process it here as we are looking // for directories that start with the packageName. }
/** * Return set of file user identifiers from a list of files * * @param user user who uploaded or will upload file * @param files list of files objects * @return Set containing all user identifiers from list of files * * @see org.kuali.kfs.sys.batch.BatchInputFileSetType#extractFileUserIdentifiers(org.kuali.rice.kim.api.identity.Person, java.util.List) */ public Set<String> extractFileUserIdentifiers(Person user, List<File> files) { Set<String> extractedFileUserIdentifiers = new TreeSet<String>(); StringBuilder buf = new StringBuilder(); buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(user.getPrincipalName()).append(FILE_NAME_PART_DELIMITER); String prefixString = buf.toString(); IOFileFilter prefixFilter = new PrefixFileFilter(prefixString); IOFileFilter suffixFilter = new SuffixFileFilter(CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION); IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter); for (File file : files) { if (combinedFilter.accept(file)) { String fileName = file.getName(); if (fileName.endsWith(CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION)) { extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION)); } else { LOG.error("Unable to determine file user identifier for file name: " + fileName); throw new RuntimeException("Unable to determine file user identifier for file name: " + fileName); } } } return extractedFileUserIdentifiers; }
/** * Find files while input can use wildcard * or ? * * @param filesStr File path(s) delimited by delimiter * @param delimiter Separator of file paths. * @return List of absolute path of files */ public static Collection<String> listFiles(String filesStr, String delimiter) { ValidationUtils.validateNotEmpty(filesStr, "fileStr"); List<String> files = new ArrayList<String>(); for (String s : filesStr.split(delimiter)) { File f = new File(s); if (!f.getName().contains("*") && !f.getName().contains("?")) { files.add(f.getAbsolutePath()); continue; } FileFilter fileFilter = new AndFileFilter(new WildcardFileFilter(f.getName()), FileFileFilter.FILE); File parent = f.getParentFile() == null ? f : f.getParentFile(); File[] filteredFiles = parent.listFiles(fileFilter); if(filteredFiles == null) { continue; } for (File file : filteredFiles) { files.add(file.getAbsolutePath()); } } return files; }
private Map<Integer, String> prepareLogFiles() { Map<Integer, String> logFiles = new HashMap<Integer, String>(); int fileIndex = 0; for (SimpleCustomProperty logTemplate : this.logViewerConfiguration.getLogTemplates()) { String logTemplatePattern = logTemplate.getValue2(); if (StringHelper.isEmpty(logTemplatePattern)) { continue; } String logTemplatePath = FilenameUtils.getFullPath(logTemplatePattern); String logTemplateFile = FilenameUtils.getName(logTemplatePattern); File logTemplateBaseDir = new File(logTemplatePath); FileFilter fileFilter = new AndFileFilter(FileFileFilter.FILE, new WildcardFileFilter(logTemplateFile)); File[] files = logTemplateBaseDir.listFiles(fileFilter); if (files == null) { continue; } for (int i = 0; i < files.length; i++) { logFiles.put(fileIndex++, files[i].getPath()); } } return logFiles; }
private void addSources(ProjectDefinition project) { final File basedir = project.getBaseDir(); logger.debug(basedir.getAbsolutePath()); // TODO: ignore child modules folders more properly IOFileFilter custom = new IOFileFilter() { @Override public boolean accept(File file) { return file.isDirectory() && !(new File(file, "pom.xml").exists()) || file.getAbsolutePath().equals( basedir.getAbsolutePath()); } @Override public boolean accept(File dir, String name) { return false; } }; Collection<File> files = FileUtils.listFiles(basedir, new SuffixFileFilter(".process"), new AndFileFilter( new NotFileFilter(new PrefixFileFilter("target")), custom)); project.addSources(files.toArray(new File[0])); }
/** * Gets the directory walker for the default directories * @param customAges the custom ages, because custom age directories will not be purged * @return a new FilePurgeDirectoryWalker */ protected FilePurgeDirectoryWalker getDefaultDirectoryWalker(List<FilePurgeCustomAge> customAges) { IOFileFilter ageFileFilter = buildDefaultAgeFileFilter(); if (customAges != null && customAges.size() > 0) { AndFileFilter andFileFilter = new AndFileFilter(); andFileFilter.addFileFilter(ageFileFilter); andFileFilter.addFileFilter(buildAnyDirectoryButCustomAgeDirectoryFileFilter(customAges)); return new FilePurgeDirectoryWalker(andFileFilter); } else { return new FilePurgeDirectoryWalker(ageFileFilter); } }
/** * @return an IOFileFilter which represents the files that should be culled by this FilePurgeCustomAge */ public IOFileFilter getFileFilter() { AndFileFilter andFileFilter = new AndFileFilter(); MaxAgePurgeFileFilter maxAgeFilter = new MaxAgePurgeFileFilter(this); DirectoryNameFileFilter directoryNameFilter = new DirectoryNameFileFilter(this); andFileFilter.addFileFilter(maxAgeFilter); andFileFilter.addFileFilter(directoryNameFilter); return andFileFilter; }
/** * Return set of file user identifiers from a list of files * * @param user user who uploaded or will upload file * @param files list of files objects * @return Set containing all user identifiers from list of files * @see org.kuali.ole.sys.batch.BatchInputFileSetType#extractFileUserIdentifiers(org.kuali.rice.kim.api.identity.Person, java.util.List) */ public Set<String> extractFileUserIdentifiers(Person user, List<File> files) { Set<String> extractedFileUserIdentifiers = new TreeSet<String>(); StringBuilder buf = new StringBuilder(); buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(user.getPrincipalName()).append(FILE_NAME_PART_DELIMITER); String prefixString = buf.toString(); IOFileFilter prefixFilter = new PrefixFileFilter(prefixString); IOFileFilter suffixFilter = new OrFileFilter(new SuffixFileFilter(EnterpriseFeederService.DATA_FILE_SUFFIX), new SuffixFileFilter(EnterpriseFeederService.RECON_FILE_SUFFIX)); IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter); for (File file : files) { if (combinedFilter.accept(file)) { String fileName = file.getName(); if (fileName.endsWith(EnterpriseFeederService.DATA_FILE_SUFFIX)) { extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, EnterpriseFeederService.DATA_FILE_SUFFIX)); } else if (fileName.endsWith(EnterpriseFeederService.RECON_FILE_SUFFIX)) { extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, EnterpriseFeederService.RECON_FILE_SUFFIX)); } else { LOG.error("Unable to determine file user identifier for file name: " + fileName); throw new RuntimeException("Unable to determine file user identifier for file name: " + fileName); } } } return extractedFileUserIdentifiers; }
public static Collection<File> getPomFiles( File repoPath ) { Collection<File> pomFiles = new ArrayList<File>(); Collection<File> leafDirectories = getLeafDirectories( repoPath ); for ( File leafDirectory : leafDirectories ) { IOFileFilter fileFilter = new AndFileFilter( new WildcardFileFilter( "*.pom" ), new NotFileFilter( new SuffixFileFilter( "sha1" ) ) ); pomFiles.addAll( FileUtils.listFiles( leafDirectory, fileFilter, null ) ); } return pomFiles; }
@Override public void execute() throws MojoExecutionException, MojoFailureException { this.pluginDescriptor = ((PluginDescriptor) getPluginContext().get("pluginDescriptor")); if (this.mavenHome == null ) { String mavenEnv = System.getenv("M2_HOME"); Validate.notEmpty(mavenEnv, "M2_HOME is not set you can used the maven-home configuration!"); mavenHome = new File(mavenEnv); } if (!mavenHome.exists() ) { throw new IllegalArgumentException("maven home (M2_HOME or maven-home configuration) is set to bad location : " + mavenHome.getAbsolutePath()); } OrFileFilter prefixFileFilter = new OrFileFilter(); prefixFileFilter.addFileFilter(new PrefixFileFilter("VDoc")); prefixFileFilter.addFileFilter(new PrefixFileFilter("VDP")); AndFileFilter fileFilter = new AndFileFilter(); fileFilter.addFileFilter(prefixFileFilter); fileFilter.addFileFilter(new SuffixFileFilter(".jar")); File[] earFiles = earFolder.listFiles((FileFilter) fileFilter); getLog().info("Scan the vdoc.ear folder"); deployFiles(earFiles); getLog().info("Scan the vdoc.ear/lib folder"); File[] earLibFiles = new File(earFolder, "lib").listFiles((FileFilter) fileFilter); deployFiles(earLibFiles); buildParentPom("sdk"); buildParentPom("sdk.advanced"); }
/** * Return set of file user identifiers from a list of files * * @param user user who uploaded or will upload file * @param files list of files objects * @return Set containing all user identifiers from list of files * @see org.kuali.kfs.sys.batch.BatchInputFileSetType#extractFileUserIdentifiers(org.kuali.rice.kim.api.identity.Person, java.util.List) */ public Set<String> extractFileUserIdentifiers(Person user, List<File> files) { Set<String> extractedFileUserIdentifiers = new TreeSet<String>(); StringBuilder buf = new StringBuilder(); buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(user.getPrincipalName()).append(FILE_NAME_PART_DELIMITER); String prefixString = buf.toString(); IOFileFilter prefixFilter = new PrefixFileFilter(prefixString); IOFileFilter suffixFilter = new OrFileFilter(new SuffixFileFilter(EnterpriseFeederService.DATA_FILE_SUFFIX), new SuffixFileFilter(EnterpriseFeederService.RECON_FILE_SUFFIX)); IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter); for (File file : files) { if (combinedFilter.accept(file)) { String fileName = file.getName(); if (fileName.endsWith(EnterpriseFeederService.DATA_FILE_SUFFIX)) { extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, EnterpriseFeederService.DATA_FILE_SUFFIX)); } else if (fileName.endsWith(EnterpriseFeederService.RECON_FILE_SUFFIX)) { extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, EnterpriseFeederService.RECON_FILE_SUFFIX)); } else { LOG.error("Unable to determine file user identifier for file name: " + fileName); throw new RuntimeException("Unable to determine file user identifier for file name: " + fileName); } } } return extractedFileUserIdentifiers; }
public List<InputFile> getFiles() { List<InputFile> result = Lists.newArrayList(); if (getSourceDirs() == null) { return result; } 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; }
private File[] findLogFiles() { File dir = new File("build"); return dir.listFiles((FileFilter)new AndFileFilter( new PrefixFileFilter("LoggerFactoryTest"), new SuffixFileFilter(".log"))); }
protected void executeReadFolder(final CommandLine cmdLine) throws IOException, JMSException, ScriptException { final long fileAgeMS = 1000; String pathFilter = cmdLine.getOptionValue(CMD_READ_FOLDER); if( pathFilter.isEmpty() ){ output("Option " + CMD_READ_FOLDER + " requires a path and wildcard filename."); } // expression will be like: /path/to/file/*.txt // Last index of / will divide filter from path File directory = Paths.get(".").toFile(); String filter = pathFilter; int indexOfPathFilterSeparator = pathFilter.lastIndexOf('/'); if( indexOfPathFilterSeparator > 0){ // path + filename/filter String path = pathFilter.substring(0, indexOfPathFilterSeparator); directory = new File(path); if ( pathFilter.endsWith("/")) { output("Option " + CMD_READ_FOLDER + " cannot end with /. Please pass a wildcard filename after path."); return; } else { filter = pathFilter.substring(indexOfPathFilterSeparator + 1); } } AndFileFilter fileFilters = new AndFileFilter(); fileFilters.addFileFilter(new WildcardFileFilter(filter)); fileFilters.addFileFilter(new AgeFileFilter(System.currentTimeMillis() - fileAgeMS)); long startTime = System.currentTimeMillis(); long waitTime = Long.parseLong(cmdLine.getOptionValue(CMD_WAIT,"0")); long endTime = startTime + waitTime; do { Collection<File> files = FileUtils.listFiles(directory, fileFilters, null); // no recursion for(File file : files) { putData("@"+file.getAbsolutePath(),cmdLine); if (!file.delete()) { output("Failed to delete file " + file.getName()); } output("File " + file.getName() + " sent"); } try { Thread.sleep(SLEEP_TIME_BETWEEN_FILE_CHECK); } catch (InterruptedException e) { output("Interrupted"); break; } } while( endTime > System.currentTimeMillis()); }