use of org.apache.commons.io.filefilter.IOFileFilter in project cu-kfs by CU-CommunityApps.
the class CuBatchFileLookupableHelperServiceImpl method getSearchResults.
@Override
public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
List<BatchFile> results = new ArrayList<BatchFile>();
IOFileFilter filter = FileFilterUtils.fileFileFilter();
String fileNamePattern = fieldValues.get("fileName");
IOFileFilter fileNameBasedFilter = getFileNameBasedFilter(fileNamePattern);
if (fileNameBasedFilter != null) {
filter = FileFilterUtils.andFileFilter(filter, fileNameBasedFilter);
}
String lastModifiedDate = fieldValues.get("lastModifiedDate");
IOFileFilter lastModifiedDateBasedFilter = getLastModifiedDateBasedFilter(lastModifiedDate);
if (lastModifiedDateBasedFilter != null) {
filter = FileFilterUtils.andFileFilter(filter, lastModifiedDateBasedFilter);
}
BatchFileFinder finder = new BatchFileFinder(results, filter);
List<File> selectedDirectories = getSelectedDirectories(getSelectedPaths());
if (selectedDirectories.isEmpty()) {
List<File> rootDirectories = retrieveRootDirectories();
finder.find(rootDirectories);
} else {
finder.find(selectedDirectories);
}
return results;
}
use of org.apache.commons.io.filefilter.IOFileFilter in project cu-kfs by CU-CommunityApps.
the class BatchFileSearchService method getFiles.
private List<BatchFile> getFiles(MultivaluedMap<String, String> fieldValues) {
List<BatchFile> results = new ArrayList<>();
IOFileFilter filter = FileFilterUtils.fileFileFilter();
String fileNamePattern = fieldValues.getFirst("fileName");
IOFileFilter fileNameBasedFilter = getFileNameBasedFilter(fileNamePattern);
if (fileNameBasedFilter != null) {
filter = FileFilterUtils.and(filter, fileNameBasedFilter);
}
String lastModifiedDate = fieldValues.getFirst("lastModifiedDate");
IOFileFilter lastModifiedDateBasedFilter = getLastModifiedDateBasedFilter(lastModifiedDate);
if (lastModifiedDateBasedFilter != null) {
filter = FileFilterUtils.and(filter, lastModifiedDateBasedFilter);
}
List<String> pathPatterns = fieldValues.get("path");
List<File> directories = getDirectoriesToSearch(pathPatterns);
BatchFileSearchService.BatchFileFinder finder = new BatchFileSearchService.BatchFileFinder(results, filter);
finder.find(directories);
return results;
}
use of org.apache.commons.io.filefilter.IOFileFilter in project walkmod-core by walkmod.
the class FileResource method iterator.
@Override
public Iterator<File> iterator() {
String fileNormalized = FilenameUtils.normalize(file.getAbsolutePath(), true);
if (includes != null) {
for (int i = 0; i < includes.length; i++) {
if (!includes[i].startsWith(fileNormalized)) {
includes[i] = fileNormalized + "/" + includes[i];
}
if (includes[i].endsWith("**")) {
includes[i] = includes[i].substring(0, includes[i].length() - 3);
}
}
}
if (excludes != null) {
for (int i = 0; i < excludes.length; i++) {
if (!excludes[i].startsWith(fileNormalized)) {
excludes[i] = fileNormalized + "/" + excludes[i];
}
if (excludes[i].endsWith("**")) {
excludes[i] = excludes[i].substring(0, excludes[i].length() - 3);
}
}
}
if (file.isDirectory()) {
IOFileFilter filter = null;
IOFileFilter directoryFilter = TrueFileFilter.INSTANCE;
if (excludes != null || includes != null) {
directoryFilter = new IOFileFilter() {
@Override
public boolean accept(File dir, String name) {
boolean excludesEval = false;
boolean includesEval = false;
String aux = FilenameUtils.normalize(name, true);
if (excludes != null) {
for (int i = 0; i < excludes.length && !excludesEval; i++) {
excludesEval = (FilenameUtils.wildcardMatch(aux, excludes[i]) || dir.getAbsolutePath().startsWith(excludes[i]));
}
}
if (includes != null) {
for (int i = 0; i < includes.length && !includesEval; i++) {
includesEval = matches(aux, includes[i]);
}
} else {
includesEval = true;
}
return (includesEval && !excludesEval) || (includes == null && excludes == null);
}
@Override
public boolean accept(File file) {
boolean excludesEval = false;
boolean includesEval = false;
String aux = FilenameUtils.normalize(file.getAbsolutePath(), true);
if (excludes != null) {
for (int i = 0; i < excludes.length && !excludesEval; i++) {
excludesEval = (FilenameUtils.wildcardMatch(aux, excludes[i]) || file.getParentFile().getAbsolutePath().startsWith(excludes[i]));
}
}
if (includes != null) {
for (int i = 0; i < includes.length && !includesEval; i++) {
includesEval = matches(aux, includes[i]);
}
} else {
includesEval = true;
}
boolean result = (includesEval && !excludesEval) || (includes == null && excludes == null);
return result;
}
};
if (extensions == null) {
filter = directoryFilter;
} else {
String[] suffixes = toSuffixes(extensions);
filter = new SuffixFileFilter(suffixes);
}
} else {
if (extensions == null) {
filter = TrueFileFilter.INSTANCE;
} else {
String[] suffixes = toSuffixes(extensions);
filter = new SuffixFileFilter(suffixes);
}
}
return FileUtils.listFiles(file, filter, directoryFilter).iterator();
}
Collection<File> aux = new LinkedList<File>();
if (extensions == null) {
aux.add(file);
}
return aux.iterator();
}
use of org.apache.commons.io.filefilter.IOFileFilter in project che by eclipse.
the class JGitConnection method cloneWithSparseCheckout.
@Override
public void cloneWithSparseCheckout(String directory, String remoteUrl) throws GitException, UnauthorizedException {
//TODO rework this code when jgit will support sparse-checkout. Tracked issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=383772
if (directory == null) {
throw new GitException("Subdirectory for sparse-checkout is not specified");
}
clone(CloneParams.create(remoteUrl));
final String sourcePath = getWorkingDir().getPath();
final String keepDirectoryPath = sourcePath + "/" + directory;
IOFileFilter folderFilter = new DirectoryFileFilter() {
public boolean accept(File dir) {
String directoryPath = dir.getPath();
return !(directoryPath.startsWith(keepDirectoryPath) || directoryPath.startsWith(sourcePath + "/.git"));
}
};
Collection<File> files = org.apache.commons.io.FileUtils.listFilesAndDirs(getWorkingDir(), TrueFileFilter.INSTANCE, folderFilter);
try {
DirCache index = getRepository().lockDirCache();
int sourcePathLength = sourcePath.length() + 1;
files.stream().filter(File::isFile).forEach(file -> index.getEntry(file.getPath().substring(sourcePathLength)).setAssumeValid(true));
index.write();
index.commit();
for (File file : files) {
if (keepDirectoryPath.startsWith(file.getPath())) {
continue;
}
if (file.exists()) {
FileUtils.delete(file, FileUtils.RECURSIVE);
}
}
} catch (IOException exception) {
String message = generateExceptionMessage(exception);
throw new GitException(message, exception);
}
}
use of org.apache.commons.io.filefilter.IOFileFilter in project atlas by alibaba.
the class TPatchTool method processBundleFiles.
/**
* 处理bundle的patch文件
*
* @param newBundleFile
* @param baseBundleFile
* @param patchTmpDir
* @param diffTxtFile
*/
private void processBundleFiles(File newBundleFile, File baseBundleFile, File patchTmpDir, File diffTxtFile) throws IOException, RecognitionException, PatchException {
String bundleName = FilenameUtils.getBaseName(newBundleFile.getName());
File destPatchBundleDir = new File(patchTmpDir, bundleName);
if (!isModifyBundle(newBundleFile.getName())) {
return;
}
final File newBundleUnzipFolder = new File(newBundleFile.getParentFile(), bundleName);
final File baseBundleUnzipFolder = new File(baseBundleFile.getParentFile(), bundleName);
if (null != baseBundleFile && baseBundleFile.isFile() && baseBundleFile.exists() && !noPatchBundles.contains(baseBundleFile.getName().replace("_", ".").substring(3, baseBundleFile.getName().length() - 3)) && diffBundleDex) {
// 解压文件
// 判断dex的差异性
ZipUtils.unzip(newBundleFile, newBundleUnzipFolder.getAbsolutePath());
ZipUtils.unzip(baseBundleFile, baseBundleUnzipFolder.getAbsolutePath());
File destDex = new File(destPatchBundleDir, DEX_NAME);
File tmpDexFolder = new File(patchTmpDir, bundleName + "-dex");
createBundleDexPatch(newBundleUnzipFolder, baseBundleUnzipFolder, destDex, tmpDexFolder, diffTxtFile);
// 比较其他资源文件的差异性
Collection<File> newBundleResFiles = FileUtils.listFiles(newBundleUnzipFolder, new IOFileFilter() {
@Override
public boolean accept(File file) {
// 不包括dex文件
if (file.getName().endsWith(".dex")) {
return false;
}
String relativePath = PathUtils.toRelative(newBundleUnzipFolder, file.getAbsolutePath());
if (null != notIncludeFiles && pathMatcher.match(notIncludeFiles, relativePath)) {
return false;
}
return true;
}
@Override
public boolean accept(File file, String s) {
return accept(new File(file, s));
}
}, TrueFileFilter.INSTANCE);
for (File newBundleResFile : newBundleResFiles) {
String resPath = PathUtils.toRelative(newBundleUnzipFolder, newBundleResFile.getAbsolutePath());
File baseBundleResFile = new File(baseBundleUnzipFolder, resPath);
File destResFile = new File(destPatchBundleDir, resPath);
if (baseBundleResFile.exists()) {
if (isFileModify(newBundleResFile, baseBundleResFile, bundleName, resPath)) {
// 修改的资源
FileUtils.copyFile(newBundleResFile, destResFile);
}
} else {
// 新增的资源
FileUtils.copyFile(newBundleResFile, destResFile);
}
}
} else {
// 新增的bundle,直接全量解压
FileUtils.copyFileToDirectory(newBundleFile, patchTmpDir);
}
}
Aggregations