Example usage for org.apache.commons.io FilenameUtils wildcardMatchOnSystem

List of usage examples for org.apache.commons.io FilenameUtils wildcardMatchOnSystem

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils wildcardMatchOnSystem.

Prototype

public static boolean wildcardMatchOnSystem(String filename, String wildcardMatcher) 

Source Link

Document

Checks a filename to see if it matches the specified wildcard matcher using the case rules of the system.

Usage

From source file:com.blackducksoftware.integration.hub.detect.workflow.search.DetectorExclusionSearchFilter.java

@Override
public boolean shouldExclude(File file) {
    for (final String excludedDirectory : excludedDirectories) {
        if (FilenameUtils.wildcardMatchOnSystem(file.getName(), excludedDirectory)) {
            return true;
        }/*from ww w .j  a  v  a2 s.  c  o  m*/
    }

    return fileFilter.accept(file); //returns TRUE if it matches one of the file filters.
}

From source file:com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput.java

private Optional<File> getResultFile(String resultDirectoryName) {
    File resultDirectory = new File(scanCommand.getOutputDirectory(), resultDirectoryName);
    if (null != resultDirectory && resultDirectory.exists()) {
        File[] resultFiles = resultDirectory
                .listFiles((dir, name) -> FilenameUtils.wildcardMatchOnSystem(name, "*.json"));
        if (null != resultFiles && resultFiles.length == 1) {
            return Optional.of(resultFiles[0]);
        }// w  w w .  j av  a2 s  . c  o m
    }
    logger.error(String.format("Exactly 1 result file was not found in the result directory: %s",
            resultDirectory.getAbsolutePath()));
    return Optional.empty();
}

From source file:com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder.java

public List<File> findFiles(final File sourceDirectory, final String filenamePattern) {
    if (!sourceDirectory.isDirectory()) {
        return null;
    }//from  w  ww  . j a v  a  2s  .c om
    final File[] foundFiles = sourceDirectory.listFiles((FilenameFilter) (directoryContainingTheFile,
            filename) -> FilenameUtils.wildcardMatchOnSystem(filename, filenamePattern));
    if (foundFiles == null || foundFiles.length == 0) {
        return null;
    }
    return Arrays.asList(foundFiles);
}

From source file:net.andydvorak.intellij.lessc.fs.LessFile.java

public boolean matches(final String pattern) {
    return FilenameUtils.wildcardMatchOnSystem(getCanonicalPathSafe(), makePatternAbsolute(pattern));
}

From source file:com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder.java

private List<File> findFilesRecursive(final File sourceDirectory, final int currentDepth, final int maxDepth,
        StringBuilder maxDepthHitMsgPattern, final Boolean recurseIntoDirectoryMatch,
        final String... filenamePatterns) {
    final List<File> files = new ArrayList<>();
    if (currentDepth >= maxDepth) {
        if (StringUtils.isNotBlank(maxDepthHitMsgPattern)) {
            logger.warn(String.format(maxDepthHitMsgPattern.toString(), sourceDirectory.getAbsolutePath()));
            // Ensure msg only shown once
            maxDepthHitMsgPattern.setLength(0);
        }//from w w  w .  jav a2  s  .c  om
    } else if (sourceDirectory.isDirectory()) {
        File[] children = sourceDirectory.listFiles();
        if (children != null && children.length > 0 && null != filenamePatterns
                && filenamePatterns.length >= 1) {
            for (final File file : children) {
                final boolean fileMatchesPatterns = Arrays.stream(filenamePatterns)
                        .anyMatch(pattern -> FilenameUtils.wildcardMatchOnSystem(file.getName(), pattern));

                if (fileMatchesPatterns) {
                    files.add(file);
                }

                if (file.isDirectory() && (!fileMatchesPatterns || recurseIntoDirectoryMatch)) {
                    // only go into the directory if it is not a match OR it is a match and the flag is set to go into matching directories
                    files.addAll(findFilesRecursive(file, currentDepth + 1, maxDepth, maxDepthHitMsgPattern,
                            recurseIntoDirectoryMatch, filenamePatterns));
                }
            }
        } else if (children == null) {
            logger.warn("Directory contents could not be accessed: " + sourceDirectory.getAbsolutePath());
        }
    }
    return files;
}

From source file:com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder.java

private List<File> findDirectoriesContainingDirectoriesToDepthRecursive(final File sourceDirectory,
        final String directoryPattern, final int currentDepth, final int maxDepth) {
    final List<File> files = new ArrayList<>();
    if (currentDepth > maxDepth || !sourceDirectory.isDirectory()) {
        return files;
    }/*from ww w.  j  a v  a2 s.co m*/
    for (final File file : sourceDirectory.listFiles()) {
        if (file.isDirectory()) {
            if (FilenameUtils.wildcardMatchOnSystem(file.getName(), directoryPattern)) {
                files.add(file);
            } else {
                files.addAll(findDirectoriesContainingDirectoriesToDepthRecursive(file, directoryPattern,
                        currentDepth + 1, maxDepth));
            }
        }
    }
    return files;
}

From source file:com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder.java

private List<File> findDirectoriesContainingFilesRecursive(final File sourceDirectory,
        final String filenamePattern, final int currentDepth, final int maxDepth) {
    final Set<File> files = new HashSet<>();
    if (currentDepth > maxDepth || !sourceDirectory.isDirectory()) {
        return new ArrayList<>(files);
    }/*from   w  ww  .j  a  v  a2 s .  c o  m*/
    for (final File file : sourceDirectory.listFiles()) {
        if (file.isDirectory()) {
            files.addAll(
                    findDirectoriesContainingFilesRecursive(file, filenamePattern, currentDepth + 1, maxDepth));
        } else if (FilenameUtils.wildcardMatchOnSystem(file.getName(), filenamePattern)) {
            files.add(sourceDirectory);
        }
    }
    return new ArrayList<>(files);
}

From source file:org.datavyu.views.DatavyuView.java

public void checkForAutosavedFile() {
    // Check for autosaved file (crash condition)
    try {/*  www  .j  av a  2  s. c  o m*/
        File tempfile = File.createTempFile("test", "");
        String path = FilenameUtils.getFullPath(tempfile.getPath());
        tempfile.delete();
        File folder = new File(path);
        File[] listOfFiles = folder.listFiles();
        for (File f : listOfFiles) {
            if ((f.isFile()) && ((FilenameUtils.wildcardMatchOnSystem(f.getName(), "~*.opf"))
                    || (FilenameUtils.wildcardMatchOnSystem(f.getName(), "~*.csv")))) { // the last time datavyu crashed

                // Show the Dialog
                if (JOptionPane.showConfirmDialog(null,
                        "Openshapa has detected an unsaved file. Would you like recover this file ?",
                        "OpenShapa", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                    openRecoveredFile(f);
                    this.saveAs();
                }
                // delete the recovered file
                f.delete();
            }
        }
    } catch (IOException ex) {
        java.util.logging.Logger.getLogger(DatavyuView.class.getName()).log(Level.SEVERE, null, ex);
    }

    // initialize autosave feature
    AutosaveC.setInterval(1); // five minutes
}