Search in sources :

Example 11 with IOFileFilter

use of org.apache.commons.io.filefilter.IOFileFilter in project applause by applause.

the class FileUtils method listFiles.

/**
 * Finds files within a given directory (and optionally its subdirectories)
 * which match an array of extensions.
 *
 * @param directory  the directory to search in
 * @param extensions  an array of extensions, ex. {"java","xml"}. If this
 * parameter is <code>null</code>, all files are returned.
 * @param recursive  if true all subdirectories are searched as well
 * @return an collection of java.io.File with the matching files
 */
public static Collection<File> listFiles(File directory, String[] extensions, boolean recursive) {
    IOFileFilter filter;
    if (extensions == null) {
        filter = TrueFileFilter.INSTANCE;
    } else {
        String[] suffixes = toSuffixes(extensions);
        filter = new SuffixFileFilter(suffixes);
    }
    return listFiles(directory, filter, (recursive ? TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE));
}
Also used : IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter)

Example 12 with IOFileFilter

use of org.apache.commons.io.filefilter.IOFileFilter in project druid by druid-io.

the class LocalInputSource method getDirectoryListingIterator.

private Iterator<File> getDirectoryListingIterator() {
    if (baseDir == null) {
        return Collections.emptyIterator();
    } else {
        final IOFileFilter fileFilter;
        if (files == null) {
            fileFilter = new WildcardFileFilter(filter);
        } else {
            fileFilter = new AndFileFilter(new WildcardFileFilter(filter), new NotFileFilter(new NameFileFilter(files.stream().map(File::getName).collect(Collectors.toList()), IOCase.SENSITIVE)));
        }
        Iterator<File> fileIterator = FileUtils.iterateFiles(baseDir.getAbsoluteFile(), fileFilter, TrueFileFilter.INSTANCE);
        if (!fileIterator.hasNext()) {
            // base dir & filter are guaranteed to be non-null here
            // (by construction and non-null check of baseDir a few lines above):
            log.info("Local inputSource filter [%s] for base dir [%s] did not match any files", filter, baseDir);
        }
        return fileIterator;
    }
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) NotFileFilter(org.apache.commons.io.filefilter.NotFileFilter) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) File(java.io.File)

Example 13 with IOFileFilter

use of org.apache.commons.io.filefilter.IOFileFilter in project ignite by apache.

the class CacheGroupMetricsWithIndexTest method testIndexRebuildCountPartitionsLeft.

/**
 * Test number of partitions need to finished indexes rebuilding.
 */
@Test
public void testIndexRebuildCountPartitionsLeft() throws Exception {
    pds = true;
    Ignite ignite = startGrid(0);
    ignite.cluster().active(true);
    IgniteCache<Object, Object> cache1 = ignite.cache(CACHE_NAME);
    for (int i = 0; i < 100_000; i++) {
        Long id = (long) i;
        BinaryObjectBuilder o = ignite.binary().builder(OBJECT_NAME).setField(KEY_NAME, id).setField(COLUMN1_NAME, i / 2).setField(COLUMN2_NAME, "str" + Integer.toHexString(i));
        cache1.put(id, o.build());
    }
    ignite.cluster().active(false);
    File dir = U.resolveWorkDirectory(U.defaultWorkDirectory(), DFLT_STORE_DIR, false);
    IOFileFilter filter = FileFilterUtils.nameFileFilter("index.bin");
    Collection<File> idxBinFiles = FileUtils.listFiles(dir, filter, TrueFileFilter.TRUE);
    for (File indexBin : idxBinFiles) U.delete(indexBin);
    ignite.cluster().active(true);
    MetricRegistry metrics = cacheGroupMetrics(0, GROUP_NAME).get2();
    LongMetric idxBuildCntPartitionsLeft = metrics.findMetric("IndexBuildCountPartitionsLeft");
    assertTrue("Timeout wait start rebuild index", waitForCondition(() -> idxBuildCntPartitionsLeft.value() > 0, 30_000));
    assertTrue("Timeout wait finished rebuild index", GridTestUtils.waitForCondition(() -> idxBuildCntPartitionsLeft.value() == 0, 30_000));
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) Ignite(org.apache.ignite.Ignite) LongMetric(org.apache.ignite.spi.metric.LongMetric) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) File(java.io.File) Test(org.junit.Test)

Example 14 with IOFileFilter

use of org.apache.commons.io.filefilter.IOFileFilter in project jo-client-platform by jo-source.

the class TemplateReplacer method copyAndReplace.

public static void copyAndReplace(final String[] args, final ReplacementConfig config) throws Exception {
    if (args.length != 2) {
        // CHECKSTYLE:OFF
        System.out.println("Usage: " + TemplateReplacer.class.getSimpleName() + " <sourceDirectory> <destinationDirectory>");
        // CHECKSTYLE:ON
        return;
    }
    final File source = new File(args[0]);
    if (!source.exists() || !source.isDirectory()) {
        // CHECKSTYLE:OFF
        System.out.println("Source directory doesn't exist: " + source);
        // CHECKSTYLE:ON
        return;
    }
    final File destination = new File(args[1]);
    if (destination.exists()) {
        // CHECKSTYLE:OFF
        System.out.println("Destination directory is not empty: " + destination);
        // CHECKSTYLE:ON
        return;
    }
    final String encoding = config.getEncoding();
    Collection<Tuple<String, String>> replacements = new HashSet<Tuple<String, String>>(config.getReplacements());
    final Collection<Tuple<String[], String[]>> packageReplacements = config.getPackageReplacements();
    replacements.addAll(getReplacementsFromPackageReplacements(packageReplacements));
    replacements = getSortedReplacements(replacements);
    Collection<Tuple<String, String>> pathReplacements = getPathReplacementsFromPackageReplacements(packageReplacements);
    pathReplacements.addAll(replacements);
    pathReplacements = getSortedReplacements(pathReplacements);
    final IOFileFilter targetFilter = FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter("target"));
    final IOFileFilter directoryFilter = FileFilterUtils.makeSVNAware(targetFilter);
    final IOFileFilter pomFileFilter = FileFilterUtils.nameFileFilter("pom.xml", IOCase.INSENSITIVE);
    final IOFileFilter javaFileFilter = FileFilterUtils.suffixFileFilter("java", IOCase.INSENSITIVE);
    final int sourcePathLength = source.getPath().length();
    for (final File file : list(source, directoryFilter)) {
        String subPath = replace(file.getPath().substring(sourcePathLength), pathReplacements);
        subPath = replace(subPath, replacements);
        final File destinationFile = new File(destination.getPath() + subPath);
        if (file.isDirectory()) {
            if (!destinationFile.exists()) {
                if (!ignorePath(destinationFile, packageReplacements)) {
                    if (!destinationFile.mkdirs()) {
                        throw new IllegalStateException("Failed to create directory: " + destinationFile);
                    }
                }
            }
        } else {
            final Tuple<IOFileFilter, String> fileReplacement = getFileReplacement(destinationFile, config.getFileReplacements());
            if (fileReplacement != null) {
                if (!EmptyCheck.isEmpty(fileReplacement.getSecond())) {
                    FileUtils.writeStringToFile(destinationFile, fileReplacement.getSecond(), encoding);
                }
            } else if (config.getJavaHeader() != null && javaFileFilter.accept(destinationFile)) {
                String text = FileUtils.readFileToString(file, encoding);
                if (config.getModififyFilesFilter().accept(destinationFile)) {
                    text = replace(text, replacements);
                }
                final int startIndex = text.indexOf("/*");
                int endIndex = text.indexOf("*/");
                if (startIndex != -1 && endIndex != -1) {
                    endIndex += 2;
                    text = text.substring(0, startIndex) + config.getJavaHeader() + text.substring(endIndex, text.length());
                }
                FileUtils.writeStringToFile(destinationFile, text, encoding);
            } else if (config.getParentPomVersion() != null && pomFileFilter.accept(destinationFile)) {
                String text = FileUtils.readFileToString(file, encoding);
                if (config.getModififyFilesFilter().accept(destinationFile)) {
                    text = replace(text, replacements);
                }
                int parentStartIndex = text.indexOf("<parent>");
                final int parentEndIndex = text.indexOf("</parent>");
                if (parentStartIndex != -1 && parentEndIndex != -1) {
                    parentStartIndex += 8;
                    String parentText = text.substring(parentStartIndex, parentEndIndex);
                    final String replacement = "<version>" + config.getParentPomVersion() + "</version>";
                    parentText = parentText.replaceAll("<version>.*</version>", replacement);
                    text = text.substring(0, parentStartIndex) + parentText + text.substring(parentEndIndex, text.length());
                }
                FileUtils.writeStringToFile(destinationFile, text, encoding);
            } else if (config.getModififyFilesFilter().accept(destinationFile)) {
                String text = FileUtils.readFileToString(file, encoding);
                text = replace(text, replacements);
                FileUtils.writeStringToFile(destinationFile, text, encoding);
            } else {
                FileUtils.copyFile(file, destinationFile);
            }
        }
    }
}
Also used : IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) File(java.io.File) Tuple(org.jowidgets.util.Tuple) HashSet(java.util.HashSet)

Example 15 with IOFileFilter

use of org.apache.commons.io.filefilter.IOFileFilter in project jo-client-platform by jo-source.

the class TemplateReplacer method createConfig.

private static ReplacementConfig createConfig() {
    final ReplacementConfig config = new ReplacementConfig();
    final Set<Tuple<String, String>> replacements = new HashSet<Tuple<String, String>>();
    replacements.add(new Tuple<String, String>("TemplateSample1", "MongodbSample1"));
    replacements.add(new Tuple<String, String>("Sample1", "Sample1"));
    replacements.add(new Tuple<String, String>("sample1", "sample1"));
    // replacements.add(new Tuple<String, String>("<vendor>jowidgets.org</vendor>", "<vendor>myorg.de</vendor>"));
    config.setReplacements(replacements);
    final Set<Tuple<String[], String[]>> packageReplacements = new HashSet<Tuple<String[], String[]>>();
    final String[] packageReplacementSource = new String[] { "org", "jowidgets", "samples", "template", "sample1" };
    final String[] packageReplacementDestination = new String[] { "org", "jowidgets", "samples", "mongodb", "sample1" };
    packageReplacements.add(new Tuple<String[], String[]>(packageReplacementSource, packageReplacementDestination));
    config.setPackageReplacements(packageReplacements);
    final IOFileFilter modifyFilesFilter = new SuffixFileFilter(new String[] { "java", "project", "xml", "MF", "htm", "html", "jnlp", "template.vm", "org.jowidgets.cap.ui.api.login.ILoginService", "org.jowidgets.security.api.IAuthenticationService", "org.jowidgets.security.api.IAuthorizationService", "org.jowidgets.service.api.IServiceProviderHolder" }, IOCase.INSENSITIVE);
    config.setModififyFilesFilter(modifyFilesFilter);
    // config.setJavaHeader("/* \n * Copyright (c) 2013 \n */");
    config.setParentPomVersion("0.0.1-SNAPSHOT");
    return config;
}
Also used : IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) Tuple(org.jowidgets.util.Tuple) HashSet(java.util.HashSet)

Aggregations

IOFileFilter (org.apache.commons.io.filefilter.IOFileFilter)32 File (java.io.File)23 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)6 SuffixFileFilter (org.apache.commons.io.filefilter.SuffixFileFilter)4 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)4 Test (org.junit.Test)4 BatchFile (org.kuali.kfs.sys.batch.BatchFile)4 URL (java.net.URL)3 PatchFile (com.taobao.android.outputs.PatchFile)2 TpatchFile (com.taobao.android.outputs.TpatchFile)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 ZipFile (java.util.zip.ZipFile)2 AndFileFilter (org.apache.commons.io.filefilter.AndFileFilter)2 DirectoryFileFilter (org.apache.commons.io.filefilter.DirectoryFileFilter)2 NotFileFilter (org.apache.commons.io.filefilter.NotFileFilter)2 FileAlterationMonitor (org.apache.commons.io.monitor.FileAlterationMonitor)2 FileAlterationObserver (org.apache.commons.io.monitor.FileAlterationObserver)2 Ignite (org.apache.ignite.Ignite)2