Java Code Examples for org.apache.maven.model.FileSet#getIncludes()

The following examples show how to use org.apache.maven.model.FileSet#getIncludes() . 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: CheckFormatMojo.java    From xml-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * A {@link DirectoryScanner} boiler plate.
 *
 * @param fileSet {@link FileSet} to scan
 * @return the included paths
 */
private String[] scan( FileSet fileSet )
{
    File basedir = new File( fileSet.getDirectory() );
    if ( !basedir.exists() || !basedir.isDirectory() )
    {
        return null;
    }

    DirectoryScanner scanner = new DirectoryScanner();

    List<String> includes = fileSet.getIncludes();
    List<String> excludes = fileSet.getExcludes();

    if ( includes != null && includes.size() > 0 )
    {
        scanner.setIncludes( includes.toArray( new String[0] ) );
    }

    if ( excludes != null && excludes.size() > 0 )
    {
        scanner.setExcludes( excludes.toArray( new String[0] ) );
    }

    scanner.setBasedir( basedir );

    scanner.scan();
    return scanner.getIncludedFiles();
}
 
Example 2
Source File: AbstractXJC2Mojo.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private List<URI> createFileSetUris(final FileSet fileset,
		String defaultDirectory, String[] defaultIncludes,
		String defaultExcludes[]) throws MojoExecutionException {
	final String draftDirectory = fileset.getDirectory();
	final String directory = draftDirectory == null ? defaultDirectory
			: draftDirectory;
	final List<String> includes;
	@SuppressWarnings("unchecked")
	final List<String> draftIncludes = (List<String>) fileset.getIncludes();
	if (draftIncludes == null || draftIncludes.isEmpty()) {
		includes = defaultIncludes == null ? Collections
				.<String> emptyList() : Arrays.asList(defaultIncludes);
	} else {
		includes = draftIncludes;
	}

	final List<String> excludes;
	@SuppressWarnings("unchecked")
	final List<String> draftExcludes = (List<String>) fileset.getExcludes();
	if (draftExcludes == null || draftExcludes.isEmpty()) {
		excludes = defaultExcludes == null ? Collections
				.<String> emptyList() : Arrays.asList(defaultExcludes);
	} else {
		excludes = draftExcludes;
	}
	String[] includesArray = includes.toArray(new String[includes.size()]);
	String[] excludesArray = excludes.toArray(new String[excludes.size()]);
	try {
		final List<File> files = IOUtils.scanDirectoryForFiles(
				getBuildContext(), new File(directory), includesArray,
				excludesArray, !getDisableDefaultExcludes());

		final List<URI> uris = new ArrayList<URI>(files.size());

		for (final File file : files) {
			// try {
			final URI uri = file.toURI();
			uris.add(uri);
			// } catch (MalformedURLException murlex) {
			// throw new MojoExecutionException(
			// MessageFormat.format(
			// "Could not create an URL for the file [{0}].",
			// file), murlex);
			// }
		}
		return uris;
	} catch (IOException ioex) {
		throw new MojoExecutionException(
				MessageFormat
						.format("Could not scan directory [{0}] for files with inclusion [{1}]  and exclusion [{2}].",
								directory, includes, excludes));
	}
}