/** * 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. }
private void cleanupIncrementalBackupDirectory(FolderInfo sourceFolder, List<ItemInfo> currentFolderChildren, File targetDir) { //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); }
protected File getFirstSpiritFileSyncFolder(final File directory) throws FileNotFoundException { checkIsDirectory(directory); final Collection<File> directories = FileUtils.listFilesAndDirs(testFolder.getRoot(), new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.DIRECTORY); for (final File candidate : directories) { if (candidate.getName().equals(".FirstSpirit")) { return candidate; } } throw new FileNotFoundException("Cannot find .FirstSpirit folder in directory " + directory.getAbsolutePath()); }
protected boolean containsSubDirectory(final File directory, final String subDirectoryName) { checkIsDirectory(directory); final Collection<File> directories = FileUtils.listFilesAndDirs(testFolder.getRoot(), new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.DIRECTORY); for (final File candidate : directories) { if (candidate.getName().equals(subDirectoryName)) { return true; } } return false; }
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])); }
private void exportEtcDirectory(ExportSettings settings) { try { 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); } }
private void exportHaEtcDirectory(ExportSettings settings) { if (artifactoryHome.isHaConfigured()) { try { File targetBackupDir = new File(settings.getBaseDir(), "ha-etc"); // TODO: [by fsi] Find a way to copy with permissions kept FileUtils.copyDirectory(artifactoryHome.getHaAwareEtcDir(), targetBackupDir, new NotFileFilter(new NameFileFilter("artifactory.lic"))); checkSecurityFolder(targetBackupDir); } catch (IOException e) { settings.getStatusHolder().error( "Failed to export etc directory: " + artifactoryHome.getEtcDir().getAbsolutePath(), e, log); } } }
/** * Locates the artifacts that were removed from the repo since last backup, but still remain in the backup folder * and clean them out. * * @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()); } } } } } }
private String createDirectoryOptionList(File[] rootlist, File directory) throws IOException { StringBuffer optionlist = new StringBuffer(); File webappPath = Imcms.getPath(); for (int i = 0; i < rootlist.length; i++) { String dirname = getPathRelativeTo(webappPath, rootlist[i]); optionlist.append(getDirectoryOption(File.separator + dirname + File.separator, File.separator + dirname + File.separator)); } File parent = directory.getCanonicalFile().getParentFile(); if (isUnderRoot(parent, rootlist)) { optionlist.append(getDirectoryOption(".." + File.separator, ".." + File.separator)); } File[] dirlist = directory.listFiles((FileFilter) DirectoryFileFilter.INSTANCE); Arrays.sort(dirlist, getFileComparator()); for (int i = 0; null != dirlist && i < dirlist.length; i++) { optionlist.append(getDirectoryOption(dirlist[i].getName() + File.separator, dirlist[i].getName() + File.separator)); } File[] filelist = directory.listFiles((FileFilter) new NotFileFilter(DirectoryFileFilter.INSTANCE)); Arrays.sort(filelist, getFileComparator()); for (int i = 0; null != filelist && i < filelist.length; i++) { String formatedFileSize = HumanReadable.getHumanReadableByteSize(filelist[i].length()); String filename = filelist[i].getName(); String fileNameAndSize = filename + " [" + formatedFileSize + "]"; optionlist.append("<option value=\""); optionlist.append(StringEscapeUtils.escapeHtml4(filename)); optionlist.append("\">"); optionlist.append(StringEscapeUtils.escapeHtml4(fileNameAndSize)); optionlist.append("</option>"); } return optionlist.toString(); }
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; }
/** * Retrieves all the sub directories from a root directory. * * @param path * the root path. * @return the sub directories. */ public static List<String> getAllDirsAsString(String path) { List<File> dirs = (List<File>) FileUtils.listFilesAndDirs(new File(path), new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.DIRECTORY); List<String> dirsNames = new ArrayList<>(); for (File f : dirs) { dirsNames.add(f.getAbsolutePath()); } return dirsNames; }
private Collection<File> getClassFiles() { if (classesDirectory.isDirectory()) { IOFileFilter fileFilter = new SuffixFileFilter(".class"); IOFileFilter dirFilter = new NotFileFilter(new WildcardFileFilter("*-INF")); // META-INF, APP-INF, etc. return FileUtils.listFiles(classesDirectory, fileFilter, dirFilter); } else { return Collections.EMPTY_LIST; } }
/** * Versionalize packages from source to dest. * @param src Source directory * @param dest Destination * @throws IOException If some IO problem */ private void versionalize(@NotNull final File src, @NotNull final File dest) throws IOException { final Collection<File> dirs = FileUtils.listFilesAndDirs( src, new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.DIRECTORY ); final String name = String.format( "%s-%s-%s.txt", VersionalizeMojo.cleanup(this.project.getGroupId()), VersionalizeMojo.cleanup(this.project.getArtifactId()), VersionalizeMojo.cleanup(this.project.getPackaging()) ); for (final File dir : dirs) { if (VersionalizeMojo.files(dir, "*.java").isEmpty()) { continue; } final File ddir = new File( dest, StringUtils.substring( dir.getCanonicalPath(), src.getCanonicalPath().length() + 1 ) ); final File version = new File(ddir, name); if (version.getParentFile().mkdirs()) { Logger.info(this, "created dir %s", version.getParentFile()); } FileUtils.write(version, this.text(ddir)); Logger.info(this, "File %s added", version); } }
private File[] getLocalDirContents() { FileFilter fileFilter = new NotFileFilter(new RegexFileFilter("^.vlt-sync.+$")); File[] localDirContents = this.localDir.listFiles(fileFilter); return localDirContents; }
public static IOFileFilter notFileFilter( IOFileFilter filter ) { return new NotFileFilter( filter ); }
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)); }
public FilenameFilter createFilenameFilter() { //create the new filter to exclude these file names return new NotFileFilter(new WildcardFileFilter(exclude.toArray(new String[] {}))); }
/** * Retrieves all the sub directories from a root directory. * * @param path * the root path. * @return the sub directories. */ public static List<File> getAllDirs(String path) { return (List<File>) FileUtils.listFilesAndDirs(new File(path), new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.DIRECTORY); }