use of org.codehaus.plexus.util.DirectoryScanner in project maven-plugins by apache.
the class BundleRemoteResourcesMojo method execute.
public void execute() throws MojoExecutionException {
if (!resourcesDirectory.exists()) {
getLog().info("skip non existing resourceDirectory " + resourcesDirectory.getAbsolutePath());
return;
}
if (StringUtils.isEmpty(sourceEncoding)) {
getLog().warn("sourceEncoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!");
sourceEncoding = ReaderFactory.FILE_ENCODING;
}
// Look at the content of the resourcesDirectory and create a manifest of the files
// so that velocity can easily process any resources inside the JAR that need to be processed.
RemoteResourcesBundle remoteResourcesBundle = new RemoteResourcesBundle();
remoteResourcesBundle.setSourceEncoding(sourceEncoding);
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(resourcesDirectory);
if (includes != null && includes.length != 0) {
scanner.setIncludes(includes);
} else {
scanner.setIncludes(DEFAULT_INCLUDES);
}
if (excludes != null && excludes.length != 0) {
scanner.setExcludes(excludes);
}
scanner.addDefaultExcludes();
scanner.scan();
List<String> includedFiles = Arrays.asList(scanner.getIncludedFiles());
for (String resource : includedFiles) {
remoteResourcesBundle.addRemoteResource(StringUtils.replace(resource, '\\', '/'));
}
RemoteResourcesBundleXpp3Writer w = new RemoteResourcesBundleXpp3Writer();
Writer writer = null;
try {
File f = new File(outputDirectory, RESOURCES_MANIFEST);
FileUtils.mkdir(f.getParentFile().getAbsolutePath());
writer = new FileWriter(f);
w.write(writer, remoteResourcesBundle);
writer.close();
writer = null;
} catch (IOException e) {
throw new MojoExecutionException("Error creating remote resources manifest.", e);
} finally {
IOUtil.close(writer);
}
}
use of org.codehaus.plexus.util.DirectoryScanner in project maven-plugins by apache.
the class AbstractWarPackagingTask method getFilesToIncludes.
/**
* Returns the file to copy. If the includes are <tt>null</tt> or empty, the default includes are used.
*
* @param baseDir the base directory to start from
* @param includes the includes
* @param excludes the excludes
* @param includeDirectories include directories yes or not.
* @return the files to copy
*/
// CHECKSTYLE_OFF: LineLength
protected PathSet getFilesToIncludes(File baseDir, String[] includes, String[] excludes, boolean includeDirectories) // CHECKSTYLE_ON: LineLength
{
final DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(baseDir);
if (excludes != null) {
scanner.setExcludes(excludes);
}
scanner.addDefaultExcludes();
if (includes != null && includes.length > 0) {
scanner.setIncludes(includes);
} else {
scanner.setIncludes(DEFAULT_INCLUDES);
}
scanner.scan();
PathSet pathSet = new PathSet(scanner.getIncludedFiles());
if (includeDirectories) {
pathSet.addAll(scanner.getIncludedDirectories());
}
return pathSet;
}
use of org.codehaus.plexus.util.DirectoryScanner in project maven-plugins by apache.
the class AbstractJavadocMojo method fixFrameInjectionBug.
/**
* Patches the given Javadoc output directory to work around CVE-2013-1571
* (see http://www.kb.cert.org/vuls/id/225657).
*
* @param javadocOutputDirectory directory to scan for vulnerabilities
* @param outputEncoding encoding used by the javadoc tool (-docencoding parameter).
* If {@code null}, the platform's default encoding is used (like javadoc does).
* @return the number of patched files
*/
private int fixFrameInjectionBug(File javadocOutputDirectory, String outputEncoding) throws IOException {
final String fixData;
InputStream in = null;
try {
in = this.getClass().getResourceAsStream("frame-injection-fix.txt");
if (in == null) {
throw new FileNotFoundException("Missing resource 'frame-injection-fix.txt' in classpath.");
}
fixData = StringUtils.unifyLineSeparators(IOUtil.toString(in, "US-ASCII")).trim();
in.close();
in = null;
} finally {
IOUtil.close(in);
}
final DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(javadocOutputDirectory);
ds.setCaseSensitive(false);
ds.setIncludes(new String[] { "**/index.html", "**/index.htm", "**/toc.html", "**/toc.htm" });
ds.addDefaultExcludes();
ds.scan();
int patched = 0;
for (String f : ds.getIncludedFiles()) {
final File file = new File(javadocOutputDirectory, f);
// we load the whole file as one String (toc/index files are
// generally small, because they only contain frameset declaration):
final String fileContents = FileUtils.fileRead(file, outputEncoding);
// check if file may be vulnerable because it was not patched with "validURL(url)":
if (!StringUtils.contains(fileContents, "function validURL(url) {")) {
// we need to patch the file!
final String patchedFileContents = StringUtils.replaceOnce(fileContents, "function loadFrames() {", fixData);
if (!patchedFileContents.equals(fileContents)) {
FileUtils.fileWrite(file, outputEncoding, patchedFileContents);
patched++;
}
}
}
return patched;
}
use of org.codehaus.plexus.util.DirectoryScanner in project maven-archetype by apache.
the class FilesetArchetypeCreator method createArchetypeFiles.
private void createArchetypeFiles(Properties reverseProperties, List<FileSet> fileSets, String packageName, File basedir, File archetypeFilesDirectory, String defaultEncoding, List<String> excludePatterns) throws IOException {
getLogger().debug("Creating Archetype/Module files from " + basedir + " to " + archetypeFilesDirectory);
for (FileSet fileSet : fileSets) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(basedir);
scanner.setIncludes((String[]) concatenateToList(fileSet.getIncludes(), fileSet.getDirectory()).toArray(new String[fileSet.getIncludes().size()]));
scanner.setExcludes((String[]) addLists(fileSet.getExcludes(), excludePatterns).toArray(new String[fileSet.getExcludes().size()]));
scanner.addDefaultExcludes();
getLogger().debug("Using fileset " + fileSet);
scanner.scan();
List<String> fileSetResources = Arrays.asList(scanner.getIncludedFiles());
getLogger().debug("Scanned " + fileSetResources.size() + " resources");
if (fileSet.isFiltered()) {
processFileSet(basedir, archetypeFilesDirectory, fileSet.getDirectory(), fileSetResources, fileSet.isPackaged(), packageName, reverseProperties, defaultEncoding);
getLogger().debug("Processed " + fileSet.getDirectory() + " files");
} else {
copyFiles(basedir, archetypeFilesDirectory, fileSet.getDirectory(), fileSetResources, fileSet.isPackaged(), packageName, reverseProperties);
getLogger().debug("Copied " + fileSet.getDirectory() + " files");
}
}
}
use of org.codehaus.plexus.util.DirectoryScanner in project tycho by eclipse.
the class AbstractOsgiCompilerMojo method scanBootclasspath.
private String scanBootclasspath(String javaHome, Xpp3Dom[] includes, Xpp3Dom excludeParent) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(javaHome);
scanner.setIncludes(getValues(includes));
if (excludeParent != null) {
Xpp3Dom[] excludes = excludeParent.getChildren("exclude");
if (excludes.length > 0) {
scanner.setExcludes(getValues(excludes));
}
}
scanner.scan();
StringBuilder bootClassPath = new StringBuilder();
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();
}
Aggregations