Example usage for org.apache.commons.io.filefilter NotFileFilter NotFileFilter

List of usage examples for org.apache.commons.io.filefilter NotFileFilter NotFileFilter

Introduction

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

Prototype

public NotFileFilter(IOFileFilter filter) 

Source Link

Document

Constructs a new file filter that NOTs the result of another filters.

Usage

From source file:org.jenkinsci.plugins.django.ProjectRequirementsFinder.java

@Override
public final String invoke(final File dir, final VirtualChannel channel)
        throws IOException, InterruptedException {
    File found = null;/*from   w  ww .j  ava  2  s. c  om*/
    DjangoJenkinsBuilder.LOGGER.info("Finding requirement files in " + dir.getPath());
    String foundCandidate = null;
    final NotFileFilter excludeJenkins = new NotFileFilter(
            new NameFileFilter(PythonVirtualenv.DJANGO_JENKINS_MODULE));

    searchCandidate: for (final String candidate : REQUIREMENTS_CANDIDATE) {
        DjangoJenkinsBuilder.LOGGER.info("Trying to find some " + candidate);
        DjangoJenkinsBuilder.LOGGER.info("Probing " + candidate);
        final Iterator<File> iter = FileUtils.iterateFiles(dir, new NameFileFilter(candidate), excludeJenkins);
        while (iter.hasNext()) {
            found = iter.next();
            foundCandidate = candidate;
            DjangoJenkinsBuilder.LOGGER.info("Found settings in " + found.getPath());
            break searchCandidate;
        }
    }

    if (found == null) {
        DjangoJenkinsBuilder.LOGGER.info("No requirements modules found!!!");
        DjangoJenkinsBuilder.LOGGER.info("No settings module!");
        throw (new IOException("No settings module found"));
    }
    final String pkgPath = dir.toURI().relativize(found.getParentFile().toURI()).toString();
    DjangoJenkinsBuilder.LOGGER.info("Pakage found: " + pkgPath);
    final String module = pkgPath + foundCandidate;
    DjangoJenkinsBuilder.LOGGER.info("Settings module is: " + module);
    return module;
}

From source file:org.jumpmind.symmetric.model.FileTrigger.java

public IOFileFilter createIOFileFilter() {
    String[] includes = StringUtils.isNotBlank(includesFiles) ? includesFiles.split(",") : new String[] { "*" };
    String[] excludes = StringUtils.isNotBlank(excludesFiles) ? excludesFiles.split(",") : null;
    IOFileFilter filter = new WildcardFileFilter(includes);
    if (excludes != null && excludes.length > 0) {
        List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
        fileFilters.add(filter);/*  w w w . ja  v  a2  s .  co m*/
        fileFilters.add(new NotFileFilter(new WildcardFileFilter(excludes)));
        filter = new AndFileFilter(fileFilters);
    }
    if (!recurse) {
        List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
        fileFilters.add(filter);
        fileFilters.add(new NotFileFilter(FileFilterUtils.directoryFileFilter()));
        filter = new AndFileFilter(fileFilters);
    } else {
        List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
        fileFilters.add(filter);
        fileFilters.add(FileFilterUtils.directoryFileFilter());
        filter = new OrFileFilter(fileFilters);
    }
    return filter;
}

From source file:org.lamport.tla.toolbox.tool.tlc.model.Model.java

public Model snapshot() throws CoreException {
    // Create a copy of the underlying launch configuration.
    final Model snapshot = copy(getName() + SNAP_SHOT + System.currentTimeMillis());

    // Snapshot the model's markers as well (e.g. the information about errors, see hasErrors()).
    final IMarker[] markers = getMarkers();
    for (IMarker iMarker : markers) {
        snapshot.setMarker(iMarker.getAttributes(), iMarker.getType());
    }//from w w  w.  j  a  v a2s.  com

    // Set the snapshot to be locked? Do we want the user to be able to run it again?
    //       snapshot.setLocked(true);

    /*
     * Snapshot (copy) the model folder which include the TLC output as well as the version
     * of the spec and module overwrites with which TLC ran.
     */
    final IPath snapshotPath = getSpec().getProject().getFolder(snapshot.getName()).getLocation();
    final IPath modelFolder = getSpec().getProject().getFolder(this.getName()).getLocation();
    // Use non-Eclipse API instead of modelFolder.copy(snapshotFolder, false,
    // monitor which supports a non-recursive copy. A recursive copy includes the
    // states/ directory leftover from TLC which waste quite some space and might
    // take some time to copy.
    try {
        FileUtils.copyDirectory(modelFolder.toFile(), snapshotPath.toFile(),
                new NotFileFilter(DirectoryFileFilter.DIRECTORY));

        // Rename .dot file name because hasStateGraphDump checks if a .dot file exists
        // that matches the name of the model.
        if (hasStateGraphDump()) {
            final IPath oldDotFile = getSpec().getProject()
                    .getFolder(snapshot.getName() + File.separator + this.getName() + ".dot").getLocation();
            final IPath newDotFile = getSpec().getProject()
                    .getFolder(snapshot.getName() + File.separator + snapshot.getName() + ".dot").getLocation();
            FileUtils.moveFile(oldDotFile.toFile(), newDotFile.toFile());
        }

        // Now that we've had a successful save, prune any snapshots, starting with the oldest, in order to assure the
        // cardinality no greater than snapshotKeepCount.
        pruneOldestSnapshots();

        // Refresh the snapshot folder after having copied files without using the
        // Eclipse resource API. Otherwise, the resource API does not see the files
        // which e.g. results in an incomplete model deletion or hasStateGraphDump
        // incorrectly returning false.
        snapshot.getFolder().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    } catch (IOException e) {
        throw new CoreException(new Status(Status.ERROR, TLCActivator.PLUGIN_ID, e.getMessage(), e));
    }

    return snapshot;
}

From source file:org.wisdom.asciidoc.AsciidocMojo.java

/**
 * Compiles Asciidoc files from the internal and external assets to HTML.
 *
 * @throws MojoExecutionException if the processing failed
 *//*ww  w. j a va  2s.c o  m*/
public void execute() throws MojoExecutionException {

    if (!watch) {
        removeFromWatching();
    }

    if (extensions == null || extensions.isEmpty()) {
        extensions = ImmutableList.of("ad", "asciidoc", "adoc");
    }

    if (instance == null) {
        instance = getAsciidoctorInstance();
    }

    final OptionsBuilder optionsBuilderExternals = OptionsBuilder.options().compact(compact)
            .safe(SafeMode.UNSAFE).eruby(eruby).backend(backend).docType(doctype).headerFooter(headerFooter)
            .inPlace(true);

    final OptionsBuilder optionsBuilderInternals = OptionsBuilder.options().compact(compact)
            .safe(SafeMode.UNSAFE).eruby(eruby).backend(backend).docType(doctype).headerFooter(headerFooter)
            .inPlace(true);

    if (templateEngine != null) {
        optionsBuilderExternals.templateEngine(templateEngine);
        optionsBuilderInternals.templateEngine(templateEngine);
    }

    if (templateDir != null) {
        optionsBuilderExternals.templateDir(templateDir);
        optionsBuilderInternals.templateDir(templateDir);
    }

    if (sourceHighlighter != null) {
        attributes.put("source-highlighter", sourceHighlighter);
    }

    if (embedAssets) {
        attributes.put("linkcss!", true);
        attributes.put("data-uri", true);
    }

    if (imagesDir != null) {
        attributes.put("imagesdir", imagesDir);
    }

    if (stylesheet != null) {
        attributes.put(Attributes.STYLESHEET_NAME, stylesheet);
        attributes.put(Attributes.LINK_CSS, true);
    }

    if (stylesheetDir != null) {
        attributes.put(Attributes.STYLES_DIR, stylesheetDir);
    }

    optionsBuilderExternals.attributes(attributes);
    optionsBuilderInternals.attributes(attributes);

    IOFileFilter filter = null;
    if (includes != null && includes.length != 0) {
        filter = new WildcardFileFilter(includes);
        if (excludes != null && excludes.length != 0) {
            filter = new AndFileFilter(filter, new NotFileFilter(new WildcardFileFilter(excludes)));
        }
    }
    try {
        for (File file : getResources(extensions)) {
            if (filter == null || filter.accept(file)) {
                renderFile(optionsBuilderExternals.asMap(), file);
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Error while compiling AsciiDoc file", e);
    }

}

From source file:org.xenei.classpathutils.ClassPathUtils.java

/**
 * Handle the files in a given package. The directory is already known to be
 * at or under the directory specified by the package name. So we just have
 * to find matches.//from  w w  w . j  a  v  a 2s. c  o  m
 * 
 * @param classes
 * @param packageName
 * @param dir
 * @param cFilter
 */
private static void handleDir(Set<String> classes, String packageName, File dir, ClassPathFilter cFilter) {
    if (!dir.exists()) {
        return;
    }
    if (dir.isDirectory()) {
        // handle all the classes in the directory
        for (File file : dir.listFiles()) {
            handleDir(classes, packageName, file, cFilter);
        }
        // handle all the sub-directories
        for (File file : dir.listFiles((FileFilter) new AndFileFilter(DirectoryFileFilter.DIRECTORY,
                new NotFileFilter(new PrefixFileFilter("."))))) {
            final String newPkgName = String.format("%s%s%s", packageName,
                    (packageName.length() > 0 ? "/" : ""), file.getName());
            handleDir(classes, newPkgName, file, cFilter);
        }
    } else {
        // just in case
        // if (dir.getName().endsWith(".class")) {
        // process the file name.
        String className = String.format("%s%s%s", packageName, (packageName.length() > 0 ? "/" : ""),
                dir.getName());
        // create class name
        // className = className.substring(0, className.length()
        // - ".class".length());
        if (cFilter.accept(className)) {
            classes.add(className);
        }
        // }
    }
}

From source file:org.xenei.classpathutils.ClassPathUtils.java

/**
 * 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.//from w  w  w  . j a v a2  s. com
 * 
 * @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.
}

From source file:pl.net.ptak.PrqPrePackageMojo.java

private void prepareBuildOutputForPackaging() throws MojoFailureException {
    File folderToCopy = null;/*from  www  .  j  a  v  a  2 s.c o  m*/
    boolean folderCopied = false;

    try {
        String folderName = "DiskImages";
        Iterator<File> iterator = FileUtils.iterateFilesAndDirs(installshieldOutputDirectory,
                new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.INSTANCE);

        while (iterator.hasNext()) {
            folderToCopy = iterator.next();
            if (folderToCopy.getName().equalsIgnoreCase(folderName)) {
                getLog().info(String.format("Preparing %s for packaging", folderToCopy.getCanonicalPath()));

                File diskImagesTarget = new File(prePackageInstallerSubFolder, folderName);

                diskImagesTarget.mkdirs();

                org.codehaus.plexus.util.FileUtils.copyDirectoryStructure(folderToCopy, diskImagesTarget);
                folderCopied = true;
                packagedDiskImagesFolder = folderToCopy;
                break;
            }
        }

        if (!folderCopied && failWhenNoInstallshieldFile) {
            String message = String.format("%s folder not found within the InstallShieldOutput", folderName);
            getLog().error(message);
            throw new MojoFailureException(message);
        }

        while (iterator.hasNext()) {
            folderToCopy = iterator.next();
            if (folderToCopy.getName().equalsIgnoreCase(folderName)) {
                String message = String.format("More than one %s folder found within the InstallShieldOutput, "
                        + "the first one will be used and the rest ignored", folderName);
                getLog().warn(message);
                break;
            }
        }
    } catch (IOException e) {
        String message = String.format("Failed to copy %s to %s", folderToCopy, prePackageInstallerSubFolder);
        String shortMessage = "Failed to copy resources";
        getLog().debug(message, e);
        throw new MojoFailureException(e, shortMessage, message);
    }
}

From source file:uniol.apt.tasks.ParsableTask.java

/**
 * Program entry point. Arguments are output directory and directory to scan.
 * @param args Program arguments.// w w  w  .ja v a 2s  .c  o m
 */
public static void main(String[] args) {
    if (args.length < 2)
        throw new IllegalArgumentException("Need at least two arguments: Output directory, directory to scan");

    File outputdir = new File(args[0]);
    File baseFile = new File(args[1]);

    if (!outputdir.exists())
        outputdir.mkdirs();
    if (!outputdir.isDirectory()) {
        System.err.println("Output directory is not a directory: " + outputdir);
        System.exit(1);
    }

    // Parse patterns given on the argument. A leading ! negates the pattern.
    AndFileFilter filter = new AndFileFilter();
    IOFileFilter negatedFilter = new NotFileFilter(filter);
    for (int i = 2; i < args.length; i++) {
        String arg = args[i];
        String wildcard = arg;
        boolean negate = wildcard.startsWith("!");

        if (negate)
            wildcard = arg.substring(1);
        IOFileFilter newFilter = new WildcardFileFilter(wildcard);
        if (negate)
            newFilter = new NotFileFilter(newFilter);
        filter.addFileFilter(newFilter);
    }

    // Get all excluded files
    Collection<File> excludedFiles = FileUtils.listFiles(baseFile, negatedFilter, TrueFileFilter.INSTANCE);

    // Now do the job
    boolean fail = false;
    List<AbstractParserTester> testers = new ArrayList<>();
    try {
        try {
            testers.add(new ParserTester<>(new RegexParser(), outputdir));
            testers.addAll(constructParserTesters(outputdir, PNParsers.INSTANCE, "genet"));
            testers.addAll(constructParserTesters(outputdir, LTSParsers.INSTANCE));
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

        for (File file : FileUtils.listFiles(baseFile, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {
            String relativePath = baseFile.toURI().relativize(file.toURI()).getPath();
            boolean excluded = excludedFiles.contains(file);
            if (!parseFile(testers, file, relativePath, excluded))
                fail = true;
        }
    } finally {
        if (testers != null)
            for (AbstractParserTester tester : testers)
                tester.close();
    }

    if (!fail)
        return;
    System.err.println("Errors found; see above messages.");
    System.exit(1);
}

From source file:xmlconverter.controller.logic.SiteToDir.java

/**
 * This method consists of some nested loops and tries to build correct path
 * for file creation. Each crafted path will be saved to <code>Set<String>
 * pathName</code>. This will avoid duplication if any. The path is crafted
 * manually with given root path and added String values to it
 *
 * After the end of this method <code>createDir()</code> method is called.
 *
 * @param site/*from w  ww  .  j  a  va  2 s  .  c o m*/
 * @throws java.io.IOException
 */
//Flag 0 - Default 1 - Override 2 - Update
public void writeDir(Site site) throws IOException {
    ArrayList<String> detectList = site.getSiteAsArrayList();
    ArrayList<File> tempArray = new ArrayList<>();
    ArrayList<String> allowOverrideList = new ArrayList<>();
    int flag = bean.getUserInputBean().getFlag();
    String siteDesc = bean.getEnvBean().getSiteDir().getName();
    allowOverrideList.add(siteDesc);

    for (Panel s : site.getPanelList()) {
        String panel = s.getDescription();
        tempArray.add(new File(format(home.getAbsolutePath() + slash + siteDesc.trim() + slash + panel)));
        int indexHardware = panel.indexOf("_");
        int stationIdHardware = Character.getNumericValue(panel.charAt(indexHardware - 1));
        for (String detectionList : detectList) {
            int index = detectionList.indexOf("_");
            int stationId = Character.getNumericValue(detectionList.charAt(index + 1));
            if (detectionList.contains("Detektions-Objekt") && stationId == stationIdHardware) {
                detection = siteDesc.trim() + slash + panel + slash + detectionList.trim();
                pathName.add(new File(home, format(detection).replace("!", "")));
            } else if (detectionList.contains("Abschnitt") && stationId == stationIdHardware) {
                build = detection.trim() + slash + detectionList.trim();
                pathName.add(new File(home, format(build.trim()).replace("!", "")));
            } else if (detectionList.contains("Automatische") && stationId == stationIdHardware) {
                pathName.add(
                        new File(home, format(build.trim() + slash + detectionList.trim()).replace("!", "")));
            } else if (detectionList.contains("Manuelle") && stationId == stationIdHardware) {
                pathName.add(new File(home, format(build.trim() + slash + detectionList).replace("!", "")));
            } else if (detectionList.contains("Stations-Objekt") && stationId == stationIdHardware) {
                pathName.add(new File(home,
                        format(siteDesc.trim() + slash + panel.trim() + slash + detectionList.trim())
                                .replace("!", "")));
            }
        }
    }
    File[] sortedFiles = pathName.toArray(new File[pathName.size()]);
    Arrays.sort(sortedFiles);

    //deletes everything and afterwards revrites as it suppost to.
    if (flag == 1) {
        File check = new File(home.getAbsolutePath() + slash + allowOverrideList.get(0));
        if (check.exists() && check.isDirectory()) {
            FileUtils.deleteDirectory(check);
        }
        /*  This method makes update posible.
         It findes files that already exist and subtracts them from 
         files that has been created. GG.
         All already existing file are added to <code>tempArray</code>.
         */
    } else if (flag == 2) {
        //Somewhat cleaned
        File beginnDir = new File(home.getAbsolutePath() + slash + allowOverrideList.get(0));
        for (File f : sortedFiles) {
            tempArray.add(f);
        }
        tempArray.add(beginnDir);
        Collection<File> collection = FileUtils.listFilesAndDirs(beginnDir,
                new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.DIRECTORY);

        collection.removeAll(tempArray);
        for (File f : collection) {
            FileUtils.deleteDirectory(f);
        }
    }
    createDir(sortedFiles);
}