List of usage examples for org.apache.commons.io.filefilter NotFileFilter NotFileFilter
public NotFileFilter(IOFileFilter filter)
From source file:io.manasobi.utils.FileUtils.java
/** * ? ? . //from w w w. j ava 2 s . c o m * * @param dir * @param includeRootDir ?? ? ? . (true ? ?? ?) * @return ? ? */ public static List<String> listDirNames(String dir, boolean includeRootDir) { List<File> dirs = (List<File>) org.apache.commons.io.FileUtils.listFilesAndDirs(new File(dir), new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.DIRECTORY); List<String> dirNameList = new ArrayList<String>(); int index = 0; for (File dirUnit : dirs) { if (index++ == 0 && !includeRootDir) { continue; } dirNameList.add(dirUnit.getAbsolutePath()); index++; } return dirNameList; }
From source file:io.manasobi.utils.FileUtils.java
/** * ? ? File ? . //from w ww . j a va2 s.c om * * @param dir * @param includeRootDir ?? ? ? . (true ? ?? ?) * @return ? ? File ? */ public static File[] listDirs(String dir, boolean includeRootDir) { List<File> dirs = (List<File>) org.apache.commons.io.FileUtils.listFilesAndDirs(new File(dir), new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.DIRECTORY); List<File> dirList = new ArrayList<File>(); int index = 0; for (File dirUnit : dirs) { if (index++ == 0 && !includeRootDir) { continue; } dirList.add(dirUnit); index++; } return dirList.toArray(new File[dirList.size()]); }
From source file:org.angcms.util.ResourceUtils.java
public static List<String> getFilesName(String directory, List<String> extensions) { File rootDir = new File(getRealPath(directory)); IOFileFilter filesFilter = new SuffixFileFilter(extensions, IOCase.INSENSITIVE); IOFileFilter notDirectory = new NotFileFilter(DirectoryFileFilter.INSTANCE); FilenameFilter fileFilter = new AndFileFilter(filesFilter, notDirectory); String[] resultFiles = rootDir.list(fileFilter); Arrays.sort(resultFiles);// w ww .j a v a 2 s . com if (resultFiles.length > 0) { return Arrays.asList(resultFiles); } return new ArrayList<String>(); }
From source file:org.apache.fop.layoutengine.LayoutEngineTestSuite.java
public static IOFileFilter decorateWithDisabledList(IOFileFilter filter) throws IOException { String disabled = System.getProperty("fop.layoutengine.disabled"); if (disabled != null && disabled.length() > 0) { filter = new AndFileFilter( new NotFileFilter(new NameFileFilter(readDisabledTestcases(new File(disabled)))), filter); }/*from w w w .ja v a2s . c o m*/ return filter; }
From source file:org.apache.fop.layoutengine.LayoutEngineTestUtils.java
/** * Removes from {@code filter} any tests that have been disabled. * * @param filter the filter populated with tests * @param disabled name of the file containing disabled test cases. If null or empty, * no file is read/*from w w w .j ava 2 s . c o m*/ * @return {@code filter} minus any disabled tests */ public static IOFileFilter decorateWithDisabledList(IOFileFilter filter, String disabled) { if (disabled != null && disabled.length() > 0) { filter = new AndFileFilter( new NotFileFilter( new NameFileFilter(LayoutEngineTestUtils.readDisabledTestcases(new File(disabled)))), filter); } return filter; }
From source file:org.apache.maven.plugins.scmpublish.ScmPublishPublishScmMojo.java
/** * Update scm checkout directory with content. * * @param checkout the scm checkout directory * @param dir the content to put in scm (can be <code>null</code>) * @param doNotDeleteDirs directory names that should not be deleted from scm even if not in new content: * used for modules, which content is available only when staging * @throws IOException// ww w . java 2 s . c o m */ private void update(File checkout, File dir, List<String> doNotDeleteDirs) throws IOException { String[] files = checkout.list(new NotFileFilter(new NameFileFilter(scmProvider.getScmSpecificFilename()))); Set<String> checkoutContent = new HashSet<String>(Arrays.asList(files)); List<String> dirContent = (dir != null) ? Arrays.asList(dir.list()) : Collections.<String>emptyList(); Set<String> deleted = new HashSet<String>(checkoutContent); deleted.removeAll(dirContent); MatchPatterns ignoreDeleteMatchPatterns = null; List<String> pathsAsList = new ArrayList<String>(0); if (ignorePathsToDelete != null && ignorePathsToDelete.length > 0) { ignoreDeleteMatchPatterns = MatchPatterns.from(ignorePathsToDelete); pathsAsList = Arrays.asList(ignorePathsToDelete); } for (String name : deleted) { if (ignoreDeleteMatchPatterns != null && ignoreDeleteMatchPatterns.matches(name, true)) { getLog().debug( name + " match one of the patterns '" + pathsAsList + "': do not add to deleted files"); continue; } getLog().debug("file marked for deletion: " + name); File file = new File(checkout, name); if ((doNotDeleteDirs != null) && file.isDirectory() && (doNotDeleteDirs.contains(name))) { // ignore directory not available continue; } if (file.isDirectory()) { update(file, null, null); } this.deleted.add(file); } for (String name : dirContent) { File file = new File(checkout, name); File source = new File(dir, name); if (source.isDirectory()) { directories++; if (!checkoutContent.contains(name)) { this.added.add(file); file.mkdir(); } update(file, source, null); } else { if (checkoutContent.contains(name)) { this.updated.add(file); } else { this.added.add(file); } copyFile(source, file); } } }
From source file:org.apache.rat.Report.java
public static final void main(String args[]) throws Exception { final ReportConfiguration configuration = new ReportConfiguration(); configuration.setHeaderMatcher(Defaults.createDefaultMatcher()); Options opts = buildOptions();//www . ja va 2 s . co m PosixParser parser = new PosixParser(); CommandLine cl = null; try { cl = parser.parse(opts, args); } catch (ParseException e) { System.err.println("Please use the \"--help\" option to see a list of valid commands and options"); System.exit(1); return; // dummy return (won't be reached) to avoid Eclipse complaint about possible NPE for "cl" } if (cl.hasOption('h')) { printUsage(opts); } args = cl.getArgs(); if (args == null || args.length != 1) { printUsage(opts); } else { Report report = new Report(args[0]); if (cl.hasOption('a') || cl.hasOption('A')) { configuration.setAddingLicenses(true); configuration.setAddingLicensesForced(cl.hasOption('f')); configuration.setCopyrightMessage(cl.getOptionValue("c")); } if (cl.hasOption(EXCLUDE_CLI)) { String[] excludes = cl.getOptionValues(EXCLUDE_CLI); if (excludes != null) { final FilenameFilter filter = new NotFileFilter(new WildcardFileFilter(excludes)); report.setInputFileFilter(filter); } } else if (cl.hasOption(EXCLUDE_FILE_CLI)) { String excludeFileName = cl.getOptionValue(EXCLUDE_FILE_CLI); if (excludeFileName != null) { List<String> excludes = FileUtils.readLines(new File(excludeFileName)); final OrFileFilter orFilter = new OrFileFilter(); for (String exclude : excludes) { orFilter.addFileFilter(new RegexFileFilter(exclude)); } final FilenameFilter filter = new NotFileFilter(orFilter); report.setInputFileFilter(filter); } } if (cl.hasOption('x')) { report.report(System.out, configuration); } else { if (!cl.hasOption(STYLESHEET_CLI)) { report.styleReport(System.out, configuration); } else { String[] style = cl.getOptionValues(STYLESHEET_CLI); if (style.length != 1) { System.err.println("please specify a single stylesheet"); System.exit(1); } try { report(System.out, report.getDirectory(System.out), new FileInputStream(style[0]), configuration); } catch (FileNotFoundException fnfe) { System.err.println("stylesheet " + style[0] + " doesn't exist"); System.exit(1); } } } } }
From source file:org.artifactory.repo.db.importexport.DbRepoExportHandler.java
private void cleanupIncrementalBackupDirectory(FolderInfo sourceFolder, List<ItemInfo> currentFolderChildren, File targetDir) {/* w w w .j a v a2 s. c o m*/ //Metadata File filter IOFileFilter metadataFilter = new MetadataFileFilter(); //List all artifacts Collection<File> artifacts = Sets .newHashSet(targetDir.listFiles((FileFilter) new NotFileFilter(metadataFilter))); cleanArtifacts(currentFolderChildren, artifacts); //List all sub-target metadata Collection<File> subTargetMetadataFiles = FileUtils.listFiles(targetDir, metadataFilter, DirectoryFileFilter.INSTANCE); cleanMetadata(currentFolderChildren, subTargetMetadataFiles); //List all target metadata File targetDirMetadataContainerFolder = getMetadataContainerFolder(targetDir); Collection<File> targetMetadataFiles = FileUtils.listFiles(targetDirMetadataContainerFolder, metadataFilter, DirectoryFileFilter.INSTANCE); cleanTargetMetadata(sourceFolder, targetMetadataFiles); }
From source file:org.artifactory.repo.db.importexport.DbRepoExportHandler.java
/** * Locates the artifacts that were removed from the repo since last backup, but still remain in the backup folder * and clean them out.//from ww w . j av a 2s .c o m * * @param currentVfsFolderItems List of vfs items in the current vfs folder * @param artifacts List of artifact files in the current target folder */ private void cleanArtifacts(List<ItemInfo> currentVfsFolderItems, Collection<File> artifacts) { for (File artifact : artifacts) { if (artifact != null) { String ileName = artifact.getName(); ItemInfo itemInfo = getItemByName(currentVfsFolderItems, ileName); if (itemInfo == null) { if (artifact.isDirectory()) { // If a directory does not exist in data store - we need to recursively handle all of his children as well Collection<File> childArtifacts = Sets.newHashSet( artifact.listFiles((FileFilter) new NotFileFilter(new MetadataFileFilter()))); cleanArtifacts(Collections.<ItemInfo>emptyList(), childArtifacts); } log.debug("Deleting {} from the incremental backup dir since it was " + "deleted from the repository", artifact.getAbsolutePath()); boolean deleted = FileUtils.deleteQuietly(artifact); if (!deleted) { log.warn("Failed to delete {}", artifact.getAbsolutePath()); } // now delete the metadata folder of the file/folder is it exists File metadataFolder = getMetadataContainerFolder(artifact); if (metadataFolder.exists()) { deleted = FileUtils.deleteQuietly(metadataFolder); if (!deleted) { log.warn("Failed to delete metadata folder {}", metadataFolder.getAbsolutePath()); } } } } } }
From source file:org.artifactory.spring.ArtifactoryApplicationContext.java
private void exportEtcDirectory(ExportSettings settings) { try {/*from w ww .ja v a 2 s . c o m*/ File targetBackupDir = new File(settings.getBaseDir(), "etc"); // TODO: [by fsi] Find a way to copy with permissions kept FileUtils.copyDirectory(artifactoryHome.getEtcDir(), targetBackupDir, new NotFileFilter(new NameFileFilter("artifactory.lic")), true); checkSecurityFolder(targetBackupDir); } catch (IOException e) { settings.getStatusHolder().error( "Failed to export etc directory: " + artifactoryHome.getEtcDir().getAbsolutePath(), e, log); } }