org.apache.maven.shared.utils.io.DirectoryScanner Java Examples

The following examples show how to use org.apache.maven.shared.utils.io.DirectoryScanner. 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: ChangeDetector.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
static boolean inputFilesChangeDetected(File contractsDirectory,
		MojoExecution mojoExecution, MavenSession session)
		throws MojoExecutionException {

	IncrementalBuildHelper incrementalBuildHelper = new IncrementalBuildHelper(
			mojoExecution, session);

	DirectoryScanner scanner = incrementalBuildHelper.getDirectoryScanner();
	scanner.setBasedir(contractsDirectory);
	scanner.scan();
	boolean changeDetected = incrementalBuildHelper.inputFileTreeChanged(scanner);
	if (scanner.getIncludedFiles().length == 0) {
		// at least one input file must exist to consider changed/unchanged
		// return true to skip incremental build and make visible no input file at all
		return true;
	}
	return changeDetected;
}
 
Example #2
Source File: AbstractDocumentationMojo.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static String scanBootclasspath(String javaHome, String[] includes, String[] excludes) {
	final DirectoryScanner scanner = new DirectoryScanner();
	scanner.setBasedir(new File(javaHome));
	scanner.setIncludes(includes);
	scanner.setExcludes(excludes);
	scanner.scan();

	final StringBuilder bootClassPath = new StringBuilder();
	final String[] includedFiles = scanner.getIncludedFiles();
	for (int i = 0; i < includedFiles.length; i++) {
		if (i > 0) {
			bootClassPath.append(File.pathSeparator);
		}
		bootClassPath.append(new File(javaHome, includedFiles[i]).getAbsolutePath());
	}
	return bootClassPath.toString();
}
 
Example #3
Source File: AbstractSarlBatchCompilerMojo.java    From sarl with Apache License 2.0 6 votes vote down vote up
private String scanBootclasspath(String javaHome, String[] includes, String[] excludes) {
	getLog().debug(MessageFormat.format(Messages.AbstractSarlBatchCompilerMojo_6,
			javaHome, Arrays.toString(includes), Arrays.toString(excludes)));
	final DirectoryScanner scanner = new DirectoryScanner();
	scanner.setBasedir(new File(javaHome));
	scanner.setIncludes(includes);
	scanner.setExcludes(excludes);
	scanner.scan();

	final StringBuilder bootClassPath = new StringBuilder();
	final String[] includedFiles = scanner.getIncludedFiles();
	for (int i = 0; i < includedFiles.length; i++) {
		if (i > 0) {
			bootClassPath.append(File.pathSeparator);
		}
		bootClassPath.append(new File(javaHome, includedFiles[i]).getAbsolutePath());
	}
	return bootClassPath.toString();
}
 
Example #4
Source File: ServiceFileCombinationImpl.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static Map<String, List<String>> findLocalDescriptors(MavenProject project, List<String> patterns) {
    Map<String, List<String>> map = new LinkedHashMap<>();

    File classes = new File(project.getBuild().getOutputDirectory());
    if (!classes.isDirectory()) {
        return map;
    }

    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir(classes);
    scanner.setIncludes(patterns.toArray(new String[0]));
    scanner.scan();

    String[] paths = scanner.getIncludedFiles();
    for (String p : paths) {
        File file = new File(classes, p);
        if (file.isFile()) {
            try {
                // Compute the descriptor path in the archive - linux style.
                String relative = classes.toURI().relativize(file.toURI()).getPath().replace("\\", "/");
                map.put("/" + relative, org.apache.commons.io.FileUtils.readLines(file, "UTF-8"));
            } catch (IOException e) {
                throw new RuntimeException("Cannot read " + file.getAbsolutePath(), e);
            }
        }
    }
    return map;
}
 
Example #5
Source File: ShrinkWrapFatJarPackageService.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private void embedFileSet(Log log, MavenProject project, FileSet fs, JavaArchive jar) {
    File directory = new File(fs.getDirectory());
    if (!directory.isAbsolute()) {
        directory = new File(project.getBasedir(), fs.getDirectory());
    }

    if (!directory.isDirectory()) {
        log.warn("File set root directory (" + directory.getAbsolutePath() + ") does not exist " +
            "- skipping");
        return;
    }

    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir(directory);
    if (fs.getOutputDirectory() == null) {
        fs.setOutputDirectory("/");
    } else if (!fs.getOutputDirectory().startsWith("/")) {
        fs.setOutputDirectory("/" + fs.getOutputDirectory());
    }
    List<String> excludes = fs.getExcludes();
    if (fs.isUseDefaultExcludes()) {
        excludes.addAll(FileUtils.getDefaultExcludesAsList());
    }
    if (!excludes.isEmpty()) {
        scanner.setExcludes(excludes.toArray(new String[0]));
    }
    if (!fs.getIncludes().isEmpty()) {
        scanner.setIncludes(fs.getIncludes().toArray(new String[0]));
    }
    scanner.scan();
    String[] files = scanner.getIncludedFiles();
    for (String path : files) {
        File file = new File(directory, path);
        log.debug("Adding " + fs.getOutputDirectory() + path + " to the archive");
        jar.addAsResource(file, fs.getOutputDirectory() + path);
    }
}
 
Example #6
Source File: ServiceFileCombinationImpl.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private Map<String, List<String>> findLocalDescriptors(MavenProject project, List<String> patterns) {
    Map<String, List<String>> map = new LinkedHashMap<>();

    File classes = new File(project.getBuild().getOutputDirectory());
    if (!classes.isDirectory()) {
        return map;
    }

    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir(classes);
    scanner.setIncludes(patterns.toArray(new String[0]));
    scanner.scan();

    String[] paths = scanner.getIncludedFiles();
    for (String p : paths) {
        File file = new File(classes, p);
        if (file.isFile()) {
            try {
                // Compute the descriptor path in the archive - linux style.
                String relative = classes.toURI().relativize(file.toURI()).getPath().replace("\\", "/");
                map.put("/" + relative, org.apache.commons.io.FileUtils.readLines(file, "UTF-8"));
            } catch (IOException e) {
                throw new RuntimeException("Cannot read " + file.getAbsolutePath(), e);
            }
        }
    }
    return map;
}
 
Example #7
Source File: ChromeBrowser.java    From CookieMonster with MIT License 5 votes vote down vote up
/**
 * In come case, people could set profile for browsers, would create custom cookie files
 * @param baseDir
 * @author <a href="mailto:[email protected]">Albert Yu</a> 5/26/2017 1:40 PM
 */
private String[] getCookieDbFiles(String baseDir) {
    String[] files = null;
    File filePath = new File(baseDir);
    if (filePath.exists() && filePath.isDirectory()) {
        DirectoryScanner ds = new DirectoryScanner();
        String[] includes = {"*/Cookies"};
        ds.setIncludes(includes);
        ds.setBasedir(new File(baseDir));
        ds.setCaseSensitive(true);
        ds.scan();
        files = ds.getIncludedFiles();
    }
    return files;
}
 
Example #8
Source File: MappingTrackArchiver.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Get all files depicted by this assembly.
 *
 * @return assembled files
 */
public AssemblyFiles getAssemblyFiles(MavenSession session) {
    AssemblyFiles ret = new AssemblyFiles(new File(getDestFile().getParentFile(), assemblyName));
    // Where the 'real' files are copied to
    for (Addition addition : added) {
        Object resource = addition.resource;
        File target = new File(ret.getAssemblyDirectory(), addition.destination);
        if (resource instanceof File && addition.destination != null) {
            addFileEntry(ret, session, (File) resource, target);
        } else if (resource instanceof PlexusIoFileResource) {
            addFileEntry(ret, session, ((PlexusIoFileResource) resource).getFile(), target);
        } else if (resource instanceof FileSet) {
            FileSet fs = (FileSet) resource;
            DirectoryScanner ds = new DirectoryScanner();
            File base = addition.directory;
            ds.setBasedir(base);
            ds.setIncludes(fs.getIncludes());
            ds.setExcludes(fs.getExcludes());
            ds.setCaseSensitive(fs.isCaseSensitive());
            ds.scan();
            for (String f : ds.getIncludedFiles()) {
                File source = new File(base, f);
                File subTarget = new File(target, f);
                addFileEntry(ret, session, source, subTarget);
            }
        } else {
            throw new IllegalStateException("Unknown resource type " + resource.getClass() + ": " + resource);
        }
    }
    return ret;
}
 
Example #9
Source File: Aggregation.java    From wisdom with Apache License 2.0 5 votes vote down vote up
private DirectoryScanner newScanner(File base, FileSet fileSet) {
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir(base);
    if ((fileSet.getExcludes() != null) && (fileSet.getExcludes().size() != 0)) {
        scanner.setExcludes(fileSet.getExcludesArray());
    }
    scanner.addDefaultExcludes();
    return scanner;
}