Example usage for org.apache.commons.io.filefilter TrueFileFilter INSTANCE

List of usage examples for org.apache.commons.io.filefilter TrueFileFilter INSTANCE

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.

Prototype

IOFileFilter INSTANCE

To view the source code for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.

Click Source Link

Document

Singleton instance of true filter.

Usage

From source file:org.cleartk.test.util.LicenseTestUtil.java

public static void testFilesGPL(String directoryName, IOFileFilter fileFilter, List<String> excludePackageNames,
        List<String> excludeFiles) throws IOException {

    List<String> filesMissingLicense = new ArrayList<String>();
    File directory = new File(directoryName);
    Iterator<?> files = org.apache.commons.io.FileUtils.iterateFiles(directory, fileFilter,
            TrueFileFilter.INSTANCE);

    while (files.hasNext()) {
        File file = (File) files.next();
        String fileText = FileUtils.file2String(file);

        if (excludePackage(file, excludePackageNames)) {
            continue;
        }//from  w w w  .j  ava2  s.com
        if (excludeFile(file, excludeFiles)) {
            continue;
        }

        if (fileText.indexOf("Copyright (c) ") == -1 || fileText.indexOf("GNU General Public License") == -1) {
            filesMissingLicense.add(file.getPath());
        } else {
            if (fileText.indexOf("Copyright (c) ", 300) == -1)
                filesMissingLicense.add(file.getPath());
        }

    }

    if (filesMissingLicense.size() > 0) {
        String message = String.format("%d source files with no license. ", filesMissingLicense.size());
        System.err.println(message);
        Collections.sort(filesMissingLicense);
        for (String path : filesMissingLicense) {
            System.err.println(path);
        }
        Assert.fail(message);
    }

}

From source file:org.clickframes.testframes.TestPreparationUtil.java

/**
 * Use this advanced interface to only run tests approved by this filter
 *
 * @param appspec/*from w w  w .  j a v  a 2 s.  c o m*/
 * @param filenameFilter
 *
 * @throws Exception
 *
 * @author Vineet Manohar
 */
@SuppressWarnings("unchecked")
static void prepareAllTestSuites(final TestProfile testProfile, Techspec techspec, Appspec appspec,
        String filterName, final FileFilter fileFilter) throws Exception {
    File suiteSourceDirectory = new File(
            "src" + File.separator + "test" + File.separator + "selenium" + File.separator + "clickframes");

    File suiteTargetDirectory = new File(
            "target" + File.separator + "clickframes" + File.separator + "selenium" + File.separator
                    + ClickframeUtils.convertSlashToPathSeparator(filterName) + File.separator + "tests");

    // copy selected tests from source to suite directory
    FileUtils.deleteDirectory(suiteTargetDirectory);
    suiteTargetDirectory.mkdirs();

    // select for suites which match the given pattern

    IOFileFilter regexIOFilter = new IOFileFilter() {
        @Override
        public boolean accept(File file) {
            return fileFilter.accept(file);
        }

        @Override
        public boolean accept(File dir, String name) {
            return fileFilter.accept(new File(dir, name));
        }
    };

    Collection<File> filesFound;

    if (suiteSourceDirectory.exists() && suiteSourceDirectory.isDirectory()) {
        filesFound = FileUtils.listFiles(suiteSourceDirectory, regexIOFilter,
                FileFilterUtils.makeSVNAware(FileFilterUtils.makeCVSAware(TrueFileFilter.INSTANCE)));
    } else {
        filesFound = new ArrayList<File>();
    }

    log.info(filesFound.size() + " files found for " + fileFilter + " => " + filesFound);

    Map<File, String> listOfFlattenedSuites = new LinkedHashMap<File, String>();

    StepFilter profileStepFilter = new StepFilter() {
        @Override
        public SeleniumTestStep filter(SeleniumTestCase testCase, SeleniumTestStep testStep) {
            // if testCase name is "applicationInitialize.html", apply
            // substitution vars

            if (testCase.getFile().getName().equals("applicationInitialize.html")) {
                String target = testStep.getTarget();

                // apply profile
                target = VelocityHelper.resolveText(testProfile.getProperties(), target);

                // modify step
                testStep.setTarget(target);
            }

            return testStep;
        }
    };

    for (File sourceSuiteFile : filesFound) {
        int counter = 1;

        File targetSuiteFile;
        do {
            // name is 'some-suite.html'
            // remove suite - as multisuite runner uses suite as a keyword
            targetSuiteFile = new File(suiteTargetDirectory, sourceSuiteFile.getName()
                    .replaceAll(".html$", counter++ + ".html").replaceAll("suite", ""));
        } while (targetSuiteFile.exists());

        validateFilePathLength(targetSuiteFile);

        // flatten
        SeleniumUtils.flattenTestSuiteToTestCase(sourceSuiteFile, targetSuiteFile, profileStepFilter);

        // store names
        listOfFlattenedSuites.put(targetSuiteFile, getRelativePath(sourceSuiteFile.getAbsolutePath()));
    }

    // write one master suite to suite target directory
    File masterTestSuite = new File(suiteTargetDirectory, "master-test-suite.html");
    SeleniumUtils.testCasesToTestSuite(listOfFlattenedSuites, masterTestSuite);

    File resultsDir = new File(
            "target" + File.separator + "clickframes" + File.separator + "selenium" + File.separator
                    + ClickframeUtils.convertSlashToPathSeparator(filterName) + File.separator + "results");

    FileUtils.deleteDirectory(resultsDir);

    resultsDir.mkdirs();

    // prepare user extensions
    File userExtensionsFile = new File(System.getProperty("java.io.tmpdir"), "user-extensions.js");
    if (userExtensionsFile.exists()) {
        userExtensionsFile.delete();
    }
}

From source file:org.codequarks.uglifyjsplugin.UglifyJs2Mojo.java

public void execute() throws MojoExecutionException {
    JsFileFilter jsFileFilter = new JsFileFilter(jsExcludes);
    Collection<File> jsFiles = FileUtils.listFiles(jsSourceDir, jsFileFilter, TrueFileFilter.INSTANCE);
    for (File file : jsFiles) {
        try {//from  w  w w. ja va  2  s .c o m
            Process proc = runUglifyJs2Process(file);
            if (proc.waitFor() != 0) {
                warnOfUglifyJs2Error(proc.getErrorStream(), file.getName());
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to execute uglifyjs process", e);
        } catch (InterruptedException e) {
            throw new MojoExecutionException("UglifyJs process interrupted", e);
        }
    }
}

From source file:org.codice.ddf.configuration.migration.ExportMigrationContextImpl.java

@Override
public Stream<ExportMigrationEntry> entries(Path path, boolean recurse) {
    final ExportMigrationEntryImpl entry = new ExportMigrationEntryImpl(this, path);

    if (!isDirectory(entry)) {
        return Stream.empty();
    }//from  w  w w.  j  a  va 2 s.  co  m
    return FileUtils
            .listFiles(entry.getFile(), TrueFileFilter.INSTANCE, recurse ? TrueFileFilter.INSTANCE : null)
            .stream().map(File::toPath).map(this::getEntry);
}

From source file:org.codice.ddf.configuration.migration.ExportMigrationContextImpl.java

@Override
public Stream<ExportMigrationEntry> entries(Path path, boolean recurse, PathMatcher filter) {
    Validate.notNull(filter, "invalid null path filter");
    final ExportMigrationEntryImpl entry = new ExportMigrationEntryImpl(this, path);

    if (!isDirectory(entry)) {
        return Stream.empty();
    }/*from   ww w . ja v  a  2s.  com*/
    return FileUtils
            .listFiles(entry.getFile(), TrueFileFilter.INSTANCE, recurse ? TrueFileFilter.INSTANCE : null)
            .stream().map(File::toPath).map(p -> new ExportMigrationEntryImpl(this, p))
            .filter(e -> filter.matches(e.getPath())).map(e -> entries.computeIfAbsent(e.getPath(), p -> e));
}

From source file:org.codice.ddf.configuration.migration.ImportMigrationDirectoryEntryImpl.java

@Override
public boolean restore(boolean required) {
    if (restored == null) {
        super.restored = false; // until proven otherwise
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Importing {}...", toDebugString());
        }//from   ww  w.  j a  v a 2 s . com
        // a directory is always exported by the framework, as such we can safely extend our
        // privileges
        AccessUtils.doPrivileged(() -> {
            final PathUtils pathUtils = getContext().getPathUtils();
            final Path apath = getAbsolutePath();
            // find all existing files and keep track of it relative from ddf.home to absolute path
            final Map<Path, Path> existingFiles = FileUtils
                    .listFiles(apath.toFile(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).stream()
                    .map(File::toPath).collect(Collectors.toMap(pathUtils::relativizeFromDDFHome, p -> p));

            // it is safe to ignore the 'required' parameter since if we get here, we have a
            // directory
            // exported to start with and all files underneath are always optional so pass false to
            // restore()
            if (fileEntries.stream().peek(me -> existingFiles.remove(me.getPath())).map(me -> me.restore(false))
                    .reduce(true, Boolean::logicalAnd)) {
                if (!filtered) {
                    // all files from the original system were exported under this directory, so remove
                    // all files that were not on the original system but are found on the current one
                    final MigrationReport report = getReport();

                    existingFiles.forEach((p, ap) -> PathUtils.cleanQuietly(ap, report));
                    // cleanup all empty directories left underneath this entry's path
                    PathUtils.cleanQuietly(apath, report);
                }
                SecurityLogger.audit("Imported directory {}", apath);
                super.restored = true;
            } else {
                SecurityLogger.audit("Error importing directory {}", apath);
                getReport().record(new MigrationException(Messages.IMPORT_PATH_COPY_ERROR, getPath(),
                        pathUtils.getDDFHome(), "some directory entries failed"));
            }
        });
    }
    return restored;
}

From source file:org.codice.ui.admin.docs.DocsSparkApplication.java

public File getDocumentationHtml() {

    if (!DOCS_ROOT_DIR.toFile().exists()) {
        return null;
    }/*from ww w .  j a  v a  2s.c om*/

    Collection<File> files = FileUtils.listFiles(DOCS_ROOT_DIR.toFile(),
            new NameFileFilter("documentation.html"), TrueFileFilter.INSTANCE);

    if (files.isEmpty()) {
        return null;
    }

    return files.iterator().next().getAbsoluteFile();
}

From source file:org.craftercms.studio.impl.v1.repository.alfresco.AlfrescoContentRepository.java

private void bootstrapDir(File dir, String rootPath) {

    Collection<File> children = FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);/*w  w  w. ja v  a2s.  co  m*/
    for (File child : children) {
        String childPath = child.getAbsolutePath();
        logger.debug("BOOTSTRAP Processing path: {0}", childPath);
        if (!rootPath.equals(childPath)) {
            String relativePath = childPath.replace(rootPath, "");
            relativePath = relativePath.replace(File.separator, "/");
            String parentPath = child.getParent().replace(rootPath, "");
            parentPath = parentPath.replace(File.separator, "/");
            if (StringUtils.isEmpty(parentPath)) {
                parentPath = "/";
            }
            if (child.isDirectory()) {
                createFolderInternalCMIS(parentPath, child.getName());
            } else if (child.isFile()) {
                try {
                    writeContentCMIS(relativePath, FileUtils.openInputStream(child));
                } catch (IOException e) {
                    logger.error("Error while bootstrapping file: " + relativePath, e);
                }
            }
        }
    }
}

From source file:org.datavyu.models.db.MongoDatastore.java

/**
 * Spin up the mongo instance so that we can query and do stuff with it.
 *///  w  w w  . j av a  2  s .c o m
public static void startMongo() {
    // Unpack the mongo executable.
    try {
        String mongoDir;
        switch (Datavyu.getPlatform()) {
        case MAC:
            mongoDir = NativeLoader.unpackNativeApp(mongoOSXLocation);
            break;
        case WINDOWS:
            mongoDir = NativeLoader.unpackNativeApp(mongoWindowsLocation);
            break;
        default:
            mongoDir = NativeLoader.unpackNativeApp(mongoOSXLocation);
        }

        // When files are unjared - they loose their executable status.
        // So find the mongod executable and set it to exe
        Collection<File> files = FileUtils.listFiles(new File(mongoDir), new RegexFileFilter(".*mongod.*"),
                TrueFileFilter.INSTANCE);

        File f;
        if (files.iterator().hasNext()) {
            f = files.iterator().next();
            f.setExecutable(true);
        } else {
            f = new File("");
            System.out.println("ERROR: Could not find mongod");
        }

        //            File f = new File(mongoDir + "/mongodb-osx-x86_64-2.0.2/bin/mongod");
        //            f.setExecutable(true);

        // Spin up a new mongo instance.
        File mongoD = new File(mongoDir);
        //            int port = findFreePort(27019);
        int port = 27019;

        // Try to shut down the server if it is already running
        try {
            mongoDriver = new Mongo("127.0.0.1", port);
            DB db = mongoDriver.getDB("admin");
            db.command(new BasicDBObject("shutdownServer", 1));
        } catch (Exception e) {
            e.printStackTrace();
        }

        mongoProcess = new ProcessBuilder(f.getAbsolutePath(), "--dbpath", mongoD.getAbsolutePath(),
                "--bind_ip", "127.0.0.1", "--port", String.valueOf(port), "--directoryperdb").start();
        //            InputStream in = mongoProcess.getInputStream();
        //            InputStreamReader isr = new InputStreamReader(in);

        System.out.println("Starting mongo driver.");
        mongoDriver = new Mongo("127.0.0.1", port);

        System.out.println("Getting DB");

        // Start with a clean DB
        mongoDB = mongoDriver.getDB("datavyu");

        DBCollection varCollection = mongoDB.getCollection("variables");
        varCollection.setObjectClass(MongoVariable.class);

        DBCollection cellCollection = mongoDB.getCollection("cells");
        cellCollection.setObjectClass(MongoCell.class);

        DBCollection matrixCollection = mongoDB.getCollection("matrix_values");
        matrixCollection.setObjectClass(MongoMatrixValue.class);

        DBCollection nominalCollection = mongoDB.getCollection("nominal_values");
        nominalCollection.setObjectClass(MongoNominalValue.class);

        DBCollection textCollection = mongoDB.getCollection("text_values");
        textCollection.setObjectClass(MongoTextValue.class);

        System.out.println("Got DB");
        running = true;

    } catch (Exception e) {
        System.err.println("Unable to fire up the mongo datastore.");
        e.printStackTrace();
    }
}

From source file:org.dice_research.topicmodeling.io.FolderReader.java

/**
 * Set the value of documentFolder/* ww w .  j a va  2s  .c o  m*/
 * 
 * @param documentFolder
 *            the new value of documentFolder
 */
public void setDocumentFolder(File documentFolder) {
    setDocumentFolder(documentFolder, TrueFileFilter.INSTANCE);
}