/** * Recurse in the folder to get the list all files and folders * <ul> * <li>do not recurse in svn folder</li> * <li>do not recurse in cvs folder</li> * <li>do not match .bak files</li> * <li>do not match .old files</li> * </ul> * * @param folder the folder to parse * @param ioFileFilter additionnal IOFilter */ @SuppressWarnings("unchecked") public Collection<String> listFiles(File folder, IOFileFilter ioFileFilter) { if (ioFileFilter == null) { ioFileFilter = FileFilterUtils.fileFileFilter(); } OrFileFilter oldFilesFilter = new OrFileFilter(); for (String exclude : DEFAULT_EXCLUDES_SUFFIXES) { oldFilesFilter.addFileFilter(FileFilterUtils.suffixFileFilter(exclude)); } IOFileFilter notOldFilesFilter = FileFilterUtils.notFileFilter(oldFilesFilter); Collection<File> files = FileUtils.listFiles(folder, FileFilterUtils.andFileFilter(ioFileFilter, notOldFilesFilter), FileFilterUtils.makeSVNAware(FileFilterUtils.makeCVSAware(null))); Collection<String> ret = newArrayList(); for (File file : files) { ret.add(file.getAbsolutePath()); } return ret; }
/** * Returns each compile source root of a given <code>MavenProject</code> as a <code>Repository</code> instance * providing access to the Java files it contains. * Silently ignores compile source roots that do not exist in the file system. * * @since 2.0.0 */ @Nonnull protected Collection<Repository> getJavaFilesOfCompileSourceRootsAsRepositories(@Nonnull MavenProject project) { Collection<Repository> codeRepositories = newArrayList(); for (String compileSourceRoot : emptyIfNull(project.getCompileSourceRoots())) { File compileSourceDirectory = new File(compileSourceRoot); if (!compileSourceDirectory.exists()) { logger.debug(" Compile Source Directory [{}] does not exist?", compileSourceDirectory); continue; } codeRepositories.add(new Repository(compileSourceDirectory, new OrFileFilter(DIRECTORY, new RegexFileFilter(".*\\.java$", INSENSITIVE)))); logger.debug(" Found source directory [{}].", compileSourceRoot); } return codeRepositories; }
@Override public void initialize(final SrcGen4JContext context, final ParserConfig config) { // This type of parser always needs a configuration Contract.requireArgNotNull("config", config); name = config.getName(); varMap = config.getParent().getVarMap(); LOG.debug("Initialize parser: " + name); parserConfig = getConcreteConfig(config); modelFilter = new RegexFileFilter(parserConfig.getModelFilter()); templateFilter = new RegexFileFilter(parserConfig.getTemplateFilter()); fileFilter = new OrFileFilter(modelFilter, templateFilter); this.context = context; }
/** * Gets a directory walker which will * @param customAges the custom ages to purge files for * @return a new FilePurgeDirectoryWalker which will walk directories for us */ protected FilePurgeDirectoryWalker getCustomAgesDirectoryWalker(List<FilePurgeCustomAge> customAges) { OrFileFilter fileFilter = new OrFileFilter(); for (FilePurgeCustomAge customAge : customAges) { fileFilter.addFileFilter(customAge.getFileFilter()); } return new FilePurgeDirectoryWalker(fileFilter); }
/** * 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; }
@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; }
/** * Walks the baseDir recursively and deletes files that match filter. When traversing directories, does not follow symbolic links. * * @param baseDir * @param filter * @throws IOException */ public static void walkAndDelete(File baseDir, IOFileFilter filter) throws IOException { File[] files = baseDir.listFiles((FileFilter)new OrFileFilter(DirectoryFileFilter.INSTANCE, filter)); if (files == null) { return; } for (File f : files) { // Just try to delete it first // Will work for normal files, empty dirs and links (dir or file) // Avoid need for dealing with links later on if (f.delete()) { continue; } else if (f.isDirectory()) { // check the filter for directory before walking it as walking might affect the filter // conditions such as directory modified time boolean toBeDeleted = false; if (filter.accept(f)) { toBeDeleted = true; } // walk into dir walkAndDelete(f, filter); // possibly delete dir if (toBeDeleted) { f.delete(); } } } }
public static IOFileFilter orFileFilter( IOFileFilter ... filters ) { return new OrFileFilter( Arrays.asList( filters ) ); }
protected FileFilter getFileSectionCopyFilter(Class<?> suiteClass) { List<String> excludes = getFileSectionCopyExcludes(suiteClass); List<IOFileFilter> excludeFilters = new ArrayList<>(excludes.size()); excludes.forEach(x -> excludeFilters.add(new WildcardFileFilter(x))); return new NotFileFilter(new OrFileFilter(excludeFilters)); }