Java Code Examples for org.codehaus.plexus.util.DirectoryScanner#setCaseSensitive()

The following examples show how to use org.codehaus.plexus.util.DirectoryScanner#setCaseSensitive() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractImpSortMojo.java    From impsort-maven-plugin with Apache License 2.0 6 votes vote down vote up
private Stream<File> searchDir(File dir, boolean warnOnBadDir) {
  if (dir == null || !dir.exists() || !dir.isDirectory()) {
    if (warnOnBadDir && dir != null) {
      getLog().warn("Directory does not exist or is not a directory: " + dir);
    }
    return Stream.empty();
  }
  getLog().debug("Adding directory " + dir);
  DirectoryScanner ds = new DirectoryScanner();
  ds.setBasedir(dir);
  ds.setIncludes(includes != null && includes.length > 0 ? includes : DEFAULT_INCLUDES);
  ds.setExcludes(excludes);
  ds.addDefaultExcludes();
  ds.setCaseSensitive(false);
  ds.setFollowSymlinks(false);
  ds.scan();
  return Stream.of(ds.getIncludedFiles()).map(filename -> new File(dir, filename)).parallel();
}
 
Example 2
Source File: FormatterMojo.java    From formatter-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Add source files to the files list.
 *
 */
List<File> addCollectionFiles(File newBasedir) {
    final DirectoryScanner ds = new DirectoryScanner();
    ds.setBasedir(newBasedir);
    if (this.includes != null && this.includes.length > 0) {
        ds.setIncludes(this.includes);
    } else {
        ds.setIncludes(DEFAULT_INCLUDES);
    }

    ds.setExcludes(this.excludes);
    ds.addDefaultExcludes();
    ds.setCaseSensitive(false);
    ds.setFollowSymlinks(false);
    ds.scan();

    List<File> foundFiles = new ArrayList<>();
    for (String filename : ds.getIncludedFiles()) {
        foundFiles.add(new File(newBasedir, filename));
    }
    return foundFiles;
}
 
Example 3
Source File: ThemeBuilderUtils.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Retrieves a list of file names that are in the given directory, possibly filtered by the list of include
 * patterns or exclude patterns
 *
 * @param baseDirectory directory to retrieve file names from
 * @param includes list of patterns to match against for file names to include, can include Ant patterns
 * @param excludes list of patterns to match for excluded file names, can include Ant patterns
 * @return list of file names within the directory that match all given patterns
 */
public static List<String> getDirectoryFileNames(File baseDirectory, String[] includes, String[] excludes) {
    List<String> files = new ArrayList<String>();

    DirectoryScanner scanner = new DirectoryScanner();

    if (includes != null) {
        scanner.setIncludes(includes);
    }

    if (excludes != null) {
        scanner.setExcludes(excludes);
    }

    scanner.setCaseSensitive(false);
    scanner.addDefaultExcludes();
    scanner.setBasedir(baseDirectory);

    scanner.scan();

    for (String includedFilename : scanner.getIncludedFiles()) {
        files.add(includedFilename);
    }

    return files;
}
 
Example 4
Source File: FormatMojo.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private List<File> scan(File directory) {
	DirectoryScanner scanner = new DirectoryScanner();
	scanner.setBasedir(directory);
	scanner.setIncludes(hasLength(this.includes) ? this.includes : DEFAULT_INCLUDES);
	scanner.setExcludes(this.excludes);
	scanner.addDefaultExcludes();
	scanner.setCaseSensitive(false);
	scanner.setFollowSymlinks(false);
	scanner.scan();
	return Arrays.asList(scanner.getIncludedFiles()).stream().map(name -> new File(directory, name))
			.collect(Collectors.toList());
}
 
Example 5
Source File: ThemeBuilderUtils.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Retrieves a list of files and directories that are in the given directory, possibly filtered by the
 * list of include patterns or exclude patterns
 *
 * @param baseDirectory directory to retrieve files and directories from
 * @param includes list of patterns to match against for files to include, can include Ant patterns
 * @param excludes list of patterns to match for excluded files, can include Ant patterns
 * @return list of files within the directory that match all given patterns
 */
public static List<String> getDirectoryContents(File baseDirectory, String[] includes, String[] excludes) {
    List<String> contents = new ArrayList<String>();

    DirectoryScanner scanner = new DirectoryScanner();

    if (includes != null) {
        scanner.setIncludes(includes);
    }

    if (excludes != null) {
        scanner.setExcludes(excludes);
    }

    scanner.setCaseSensitive(false);
    scanner.addDefaultExcludes();
    scanner.setBasedir(baseDirectory);

    scanner.scan();

    for (String includedDirectory : scanner.getIncludedDirectories()) {
        contents.add(includedDirectory);
    }

    for (String includedFilename : scanner.getIncludedFiles()) {
        contents.add(includedFilename);
    }

    return contents;
}
 
Example 6
Source File: BasePrepareSources.java    From gradle-golang-plugin with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void run()  throws  Exception {
    final ProgressLogger progress = startProgress("Prepare sources");

    final GolangSettings settings = getGolang();
    final BuildSettings build = getBuild();
    boolean atLeastOneCopied = false;
    if (!FALSE.equals(build.getUseTemporaryGopath())) {
        final Path gopath = build.getFirstGopath();
        progress.progress("Prepare GOPATH " + gopath + "...");
        LOGGER.info("Prepare GOPATH ({})...", gopath);
        final Path projectBasedir = settings.getProjectBasedir();
        final Path packagePath = settings.packagePathFor(gopath);
        final Path dependencyCachePath = getDependencies().getDependencyCache();
        prepareDependencyCacheIfNeeded(packagePath, dependencyCachePath);

        final DirectoryScanner scanner = new DirectoryScanner();
        scanner.setBasedir(projectBasedir.toFile());
        scanner.setIncludes(build.getIncludes());
        scanner.setExcludes(build.getExcludes());
        scanner.setCaseSensitive(true);
        scanner.scan();
        for (final String file : scanner.getIncludedFiles()) {
            final Path sourceFile = projectBasedir.resolve(file);
            final Path targetFile = packagePath.resolve(file);
            if (!sourceFile.equals(dependencyCachePath)) {
                if (!exists(targetFile)
                    || size(sourceFile) != size(targetFile)
                    || !getLastModifiedTime(sourceFile).equals(getLastModifiedTime(targetFile))) {
                    atLeastOneCopied = true;
                    progress.progress("Prepare source file: " + file + "...");
                    LOGGER.debug("* {}", file);
                    ensureParentOf(targetFile);
                    try (final InputStream is = newInputStream(sourceFile)) {
                        try (final OutputStream os = newOutputStream(targetFile)) {
                            IOUtils.copy(is, os);
                        }
                    }
                    setLastModifiedTime(targetFile, getLastModifiedTime(sourceFile));
                }
            }
        }
        if (!atLeastOneCopied) {
            getState().setOutcome(UP_TO_DATE);
        }
    } else {
        getState().setOutcome(SKIPPED);
    }

    progress.completed();
}