Java Code Examples for org.codehaus.plexus.util.Scanner#setExcludes()

The following examples show how to use org.codehaus.plexus.util.Scanner#setExcludes() . 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: AsciidoctorFileScanner.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the Scanner with the default values.
 * <br>
 * By default:
 * <ul>
 *     <li>includes adds extension .adoc, .ad, .asc and .asciidoc
 *     <li>excludes adds filters to avoid hidden files and directoris beginning with undersore
 * </ul>
 *
 * NOTE: Patterns both in inclusions and exclusions are automatically excluded.
 */
private void setupScanner(Scanner scanner, Resource resource) {

    if (resource.getIncludes() == null || resource.getIncludes().isEmpty()) {
        scanner.setIncludes(DEFAULT_FILE_EXTENSIONS);
    } else {
        scanner.setIncludes(resource.getIncludes().toArray(new String[] {}));
    }

    if (resource.getExcludes() == null || resource.getExcludes().isEmpty()) {
        scanner.setExcludes(IGNORED_FOLDERS_AND_FILES);
    } else {
        scanner.setExcludes(mergeAndConvert(resource.getExcludes(), IGNORED_FOLDERS_AND_FILES));
    }
    // adds exclusions like SVN or GIT files
    scanner.addDefaultExcludes();
}
 
Example 2
Source File: JarMojo.java    From helidon-build-tools with Apache License 2.0 5 votes vote down vote up
/**
 * Scan for project resources and produce a comma separated list of include resources.
 *
 * @return list of resources
 */
private Map<String, List<String>> scanResources() {
    getLog().debug("Scanning project resources");
    Map<String, List<String>> allResources = new HashMap<>();
    for (Resource resource : project.getResources()) {
        List<String> resources = new ArrayList<>();
        allResources.put(resource.getDirectory(), resources);
        File resourcesDir = new File(resource.getDirectory());
        Scanner scanner = buildContext.newScanner(resourcesDir);
        String[] includes = null;
        if (resource.getIncludes() != null
                && !resource.getIncludes().isEmpty()) {
            includes = (String[]) resource.getIncludes()
                    .toArray(new String[resource.getIncludes().size()]);
        }
        scanner.setIncludes(includes);
        String[] excludes = null;
        if (resource.getExcludes() != null
                && !resource.getExcludes().isEmpty()) {
            excludes = (String[]) resource.getExcludes()
                    .toArray(new String[resource.getExcludes().size()]);
        }
        scanner.setExcludes(excludes);
        scanner.scan();
        for (String included : scanner.getIncludedFiles()) {
            getLog().debug("Found resource: " + included);
            resources.add(included);
        }
    }
    return allResources;
}
 
Example 3
Source File: IOUtils.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Scans given directory for files satisfying given inclusion/exclusion
 * patterns.
 * 
 * @param buildContext
 *            Build context provided by the environment, used to scan for files.
 * @param directory
 *            Directory to scan.
 * @param includes
 *            inclusion pattern.
 * @param excludes
 *            exclusion pattern.
 * @param defaultExcludes
 *            default exclusion flag.
 * @return Files from the given directory which satisfy given patterns. The
 *         files are {@link File#getCanonicalFile() canonical}.
 * @throws IOException
 *             If an I/O error occurs, which is possible because the
 *             construction of the canonical pathname may require filesystem
 *             queries.
 */
public static List<File> scanDirectoryForFiles(BuildContext buildContext, final File directory,
		final String[] includes, final String[] excludes, boolean defaultExcludes) throws IOException {
	if (!directory.exists()) {
		return Collections.emptyList();
	}
	final Scanner scanner;

	if (buildContext != null) {
		scanner = buildContext.newScanner(directory, true);
	} else {
		final DirectoryScanner directoryScanner = new DirectoryScanner();
		directoryScanner.setBasedir(directory.getAbsoluteFile());
		scanner = directoryScanner;
	}
	scanner.setIncludes(includes);
	scanner.setExcludes(excludes);
	if (defaultExcludes) {
		scanner.addDefaultExcludes();
	}

	scanner.scan();

	final List<File> files = new ArrayList<File>();
	for (final String name : scanner.getIncludedFiles()) {
		files.add(new File(directory, name).getCanonicalFile());
	}

	return files;
}
 
Example 4
Source File: GraalNativeMojo.java    From helidon-build-tools with Apache License 2.0 4 votes vote down vote up
/**
 * Scan for project resources and produce a comma separated list of include
 * resources.
 * @return String as comma separated list
 */
private String getResources() {
    // scan all resources
    getLog().debug("Building resources string");
    List<String> resources = new ArrayList<>();

    if (addProjectResources) {
        getLog().debug("Scanning project resources");
        for (Resource resource : project.getResources()) {
            File resourcesDir = new File(resource.getDirectory());
            Scanner scanner = buildContext.newScanner(resourcesDir);
            String[] includes = null;
            if (resource.getIncludes() != null
                    && !resource.getIncludes().isEmpty()) {
                includes = (String[]) resource.getIncludes()
                        .toArray(new String[resource.getIncludes().size()]);
            }
            scanner.setIncludes(includes);
            String[] excludes = null;
            if (resource.getExcludes() != null
                    && !resource.getExcludes().isEmpty()) {
                excludes = (String[]) resource.getExcludes()
                        .toArray(new String[resource.getExcludes().size()]);
            }
            scanner.setExcludes(excludes);
            scanner.scan();
            for (String included : scanner.getIncludedFiles()) {
                getLog().debug("Found resource: " + included);
                resources.add(included);
            }
        }
    }

    // add additional resources
    if (includeResources != null) {
        getLog().debug("Adding provided resources: " + includeResources);
        resources.addAll(includeResources);
    }

    // comma separated list
    StringBuilder sb = new StringBuilder();
    Iterator<String> it = resources.iterator();
    while (it.hasNext()) {
        sb.append(it.next());
        if (it.hasNext()) {
            sb.append("|");
        }
    }
    String resourcesStr = sb.toString();
    getLog().debug("Built resources string: " + resourcesStr);
    return resourcesStr;
}
 
Example 5
Source File: SignCodeMojo.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public void execute() throws MojoExecutionException {
	
	List<File> filesToSign = new ArrayList<>();
	
	if ( includeProjectArtifact )
		filesToSign.add(project.getArtifact().getFile());
	
	if ( artifactSets != null ) {
		for ( FileSet artifactSet : artifactSets ) {
  	File base = new File(project.getBasedir(), artifactSet.getDirectory());
  	Scanner scanner = buildContext.newScanner(base);
  	scanner.setIncludes(artifactSet.getIncludes().toArray(new String[0]));
  	scanner.setExcludes(artifactSet.getExcludes().toArray(new String[0]));
  	scanner.scan();
  	for ( String file : scanner.getIncludedFiles() ) {
  		filesToSign.add(new File(base, file));
  	}
		}
	}
	
	if ( filesToSign.isEmpty() ) { 
		getLog().info("No files to sign, skipping");
		return;
	}
	
	for ( File toSign : filesToSign )
		getLog().info("Would sign " + toSign);

    // Set up the TLS client
    System.setProperty("javax.net.ssl.keyStore", keyStore);
    System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
    String oldSslDebug = null;
	if ( sslDebug ) {
	    oldSslDebug = System.setProperty("javax.net.debug","all");
	}
	
    SignedFiles signedFiles = new SignedFiles(filesToSign);
	
    try {
        String signingSetID = makeSigningRequest(signedFiles);
        downloadSignedFiles(signedFiles, signingSetID);
    } catch (SOAPException | IOException e) {
        throw new MojoExecutionException("Signing failed : " + e.getMessage(), e);
    } finally {
        if ( sslDebug ) {
            if ( oldSslDebug != null ) {
                System.setProperty("javax.net.debug", oldSslDebug);
            } else {
                System.clearProperty("javax.net.debug");
            }
        }
    }
}