use of org.codehaus.plexus.util.DirectoryScanner in project providence by morimekta.
the class ProvidenceInput method getInputFiles.
/**
* Get the set of input files.
* @param project The maven project
* @param inputSelector The input-exclude selector.
* @param defaultInputInclude The default input include (if not specified).
* @param print_debug Print debug info to maven log.
* @param log Maven logger instance.
* @throws MojoExecutionException If parsing or checking input files failed.
* @return The set of input files.
*/
public static Set<File> getInputFiles(@Nonnull MavenProject project, IncludeExcludeFileSelector inputSelector, @Nonnull String defaultInputInclude, boolean print_debug, @Nonnull Log log) throws MojoExecutionException {
try {
TreeSet<File> inputs = new TreeSet<>();
DirectoryScanner inputScanner = new DirectoryScanner();
if (inputSelector != null) {
if (inputSelector.getIncludes() != null && inputSelector.getIncludes().length > 0) {
if (print_debug) {
log.info("Specified includes:");
for (String include : inputSelector.getIncludes()) {
log.info(" -I " + include);
}
}
inputScanner.setIncludes(inputSelector.getIncludes());
} else {
if (print_debug) {
log.info("Default includes: " + defaultInputInclude);
}
inputScanner.setIncludes(new String[] { defaultInputInclude });
}
if (inputSelector.getExcludes() != null && inputSelector.getExcludes().length > 0) {
if (print_debug) {
log.info("Specified excludes:");
for (String exclude : inputSelector.getExcludes()) {
log.info(" -E " + exclude);
}
}
inputScanner.setExcludes(inputSelector.getExcludes());
}
} else {
if (print_debug) {
log.info("Default input: " + defaultInputInclude);
}
inputScanner.setIncludes(new String[] { defaultInputInclude });
}
inputScanner.setBasedir(project.getBasedir());
inputScanner.scan();
// Include all files included specifically.
for (String file : inputScanner.getIncludedFiles()) {
inputs.add(new File(project.getBasedir(), file).getCanonicalFile());
}
// Include all thrift files in included directories.
for (String dir : inputScanner.getIncludedDirectories()) {
File[] ls = new File(project.getBasedir(), dir).listFiles();
if (ls != null) {
for (File file : ls) {
if (isThriftFile(file.toString())) {
inputs.add(file.getCanonicalFile());
}
}
}
}
// exclude all files excluded specifically.
for (String file : inputScanner.getExcludedFiles()) {
inputs.remove(new File(project.getBasedir(), file).getCanonicalFile());
}
// Exclude all files in excluded directories (and subdirectories).
for (String dir : inputScanner.getExcludedDirectories()) {
String path = new File(project.getBasedir(), dir).getCanonicalPath();
inputs.removeIf(f -> f.toString().startsWith(path + File.separator));
}
return inputs.stream().filter(ReflectionUtils::isThriftFile).collect(Collectors.toSet());
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.codehaus.plexus.util.DirectoryScanner in project aries by apache.
the class EbaMojo method execute.
public void execute() throws MojoExecutionException {
getLog().debug(" ======= EbaMojo settings =======");
getLog().debug("ebaSourceDirectory[" + ebaSourceDirectory + "]");
getLog().debug("manifestFile[" + manifestFile + "]");
getLog().debug("applicationManifestFile[" + applicationManifestFile + "]");
getLog().debug("workDirectory[" + workDirectory + "]");
getLog().debug("outputDirectory[" + outputDirectory + "]");
getLog().debug("finalName[" + finalName + "]");
getLog().debug("generateManifest[" + generateManifest + "]");
if (archiveContent == null) {
archiveContent = new String("applicationContent");
}
getLog().debug("archiveContent[" + archiveContent + "]");
getLog().info("archiveContent[" + archiveContent + "]");
zipArchiver.setIncludeEmptyDirs(includeEmptyDirs);
zipArchiver.setCompress(true);
zipArchiver.setForced(forceCreation);
// Check if jar file is there and if requested, copy it
try {
if (includeJar.booleanValue()) {
File generatedJarFile = new File(outputDirectory, finalName + ".jar");
if (generatedJarFile.exists()) {
getLog().info("Including generated jar file[" + generatedJarFile.getName() + "]");
zipArchiver.addFile(generatedJarFile, finalName + ".jar");
}
}
} catch (ArchiverException e) {
throw new MojoExecutionException("Error adding generated Jar file", e);
}
// Copy dependencies
try {
Set<Artifact> artifacts = null;
if (useTransitiveDependencies || "all".equals(archiveContent)) {
// to the same compatible value or is the default).
if ("none".equals(archiveContent)) {
throw new MojoExecutionException("<useTransitiveDependencies/> and <archiveContent/> incompatibly configured. <useTransitiveDependencies/> is deprecated in favor of <archiveContent/>.");
} else {
artifacts = project.getArtifacts();
}
} else {
// check that archiveContent is compatible
if ("applicationContent".equals(archiveContent)) {
artifacts = project.getDependencyArtifacts();
} else {
// the only remaining options should be applicationContent="none"
getLog().info("archiveContent=none: application arvhive will not contain any bundles.");
}
}
if (artifacts != null) {
for (Artifact artifact : artifacts) {
ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
if (!artifact.isOptional() && filter.include(artifact)) {
getLog().info("Copying artifact[" + artifact.getGroupId() + ", " + artifact.getId() + ", " + artifact.getScope() + "]");
zipArchiver.addFile(artifact.getFile(), artifact.getArtifactId() + "-" + artifact.getVersion() + "." + (artifact.getType() == null ? "jar" : artifact.getType()));
}
}
}
} catch (ArchiverException e) {
throw new MojoExecutionException("Error copying EBA dependencies", e);
}
// Copy source files
try {
File ebaSourceDir = ebaSourceDirectory;
if (ebaSourceDir.exists()) {
getLog().info("Copy eba resources to " + getBuildDir().getAbsolutePath());
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(ebaSourceDir.getAbsolutePath());
scanner.setIncludes(DEFAULT_INCLUDES);
scanner.addDefaultExcludes();
scanner.scan();
String[] dirs = scanner.getIncludedDirectories();
for (int j = 0; j < dirs.length; j++) {
new File(getBuildDir(), dirs[j]).mkdirs();
}
String[] files = scanner.getIncludedFiles();
for (int j = 0; j < files.length; j++) {
File targetFile = new File(getBuildDir(), files[j]);
targetFile.getParentFile().mkdirs();
File file = new File(ebaSourceDir, files[j]);
FileUtils.copyFileToDirectory(file, targetFile.getParentFile());
}
}
} catch (Exception e) {
throw new MojoExecutionException("Error copying EBA resources", e);
}
// Include custom manifest if necessary
try {
if (!generateManifest) {
includeCustomApplicationManifestFile();
}
} catch (IOException e) {
throw new MojoExecutionException("Error copying APPLICATION.MF file", e);
}
// Generate application manifest if requested
if (generateManifest) {
String fileName = new String(getBuildDir() + "/" + APPLICATION_MF_URI);
File appMfFile = new File(fileName);
try {
// Delete any old manifest
if (appMfFile.exists()) {
FileUtils.fileDelete(fileName);
}
appMfFile.getParentFile().mkdirs();
if (appMfFile.createNewFile()) {
writeApplicationManifest(fileName);
}
} catch (java.io.IOException e) {
throw new MojoExecutionException("Error generating APPLICATION.MF file: " + fileName, e);
}
}
// Check if connector deployment descriptor is there
File ddFile = new File(getBuildDir(), APPLICATION_MF_URI);
if (!ddFile.exists()) {
getLog().warn("Application manifest: " + ddFile.getAbsolutePath() + " does not exist.");
}
try {
if (addMavenDescriptor) {
if (project.getArtifact().isSnapshot()) {
project.setVersion(project.getArtifact().getVersion());
}
String groupId = project.getGroupId();
String artifactId = project.getArtifactId();
zipArchiver.addFile(project.getFile(), "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml");
PomPropertiesUtil pomPropertiesUtil = new PomPropertiesUtil();
File dir = new File(project.getBuild().getDirectory(), "maven-zip-plugin");
File pomPropertiesFile = new File(dir, "pom.properties");
pomPropertiesUtil.createPomProperties(project, zipArchiver, pomPropertiesFile, forceCreation);
}
File ebaFile = new File(outputDirectory, finalName + ".eba");
zipArchiver.setDestFile(ebaFile);
File buildDir = getBuildDir();
if (buildDir.isDirectory()) {
zipArchiver.addDirectory(buildDir);
}
// include legal files if any
File sharedResourcesDir = new File(sharedResources);
if (sharedResourcesDir.isDirectory()) {
zipArchiver.addDirectory(sharedResourcesDir);
}
zipArchiver.createArchive();
project.getArtifact().setFile(ebaFile);
} catch (Exception e) {
throw new MojoExecutionException("Error assembling eba", e);
}
}
use of org.codehaus.plexus.util.DirectoryScanner in project maven-plugins by apache.
the class EarMojo method getEarFiles.
/**
* Returns a list of filenames that should be copied over to the destination directory.
*
* @param sourceDir the directory to be scanned
* @return the array of filenames, relative to the sourceDir
*/
private String[] getEarFiles(File sourceDir) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(sourceDir);
scanner.setExcludes(getExcludes());
scanner.addDefaultExcludes();
scanner.setIncludes(getIncludes());
scanner.scan();
return scanner.getIncludedFiles();
}
use of org.codehaus.plexus.util.DirectoryScanner in project maven-plugins by apache.
the class AbstractInvokerMojo method copyDirectoryStructure.
/**
* Copied a directory structure with default exclusions (.svn, CVS, etc)
*
* @param sourceDir The source directory to copy, must not be <code>null</code>.
* @param destDir The target directory to copy to, must not be <code>null</code>.
* @throws java.io.IOException If the directory structure could not be copied.
*/
private void copyDirectoryStructure(File sourceDir, File destDir) throws IOException {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(sourceDir);
if (!cloneAllFiles) {
scanner.addDefaultExcludes();
}
scanner.scan();
/*
* NOTE: Make sure the destination directory is always there (even if empty) to support POM-less ITs.
*/
destDir.mkdirs();
// Create all the directories, including any symlinks present in source
FileUtils.mkDirs(sourceDir, scanner.getIncludedDirectories(), destDir);
for (String includedFile : scanner.getIncludedFiles()) {
File sourceFile = new File(sourceDir, includedFile);
File destFile = new File(destDir, includedFile);
FileUtils.copyFile(sourceFile, destFile);
// ensure clone project must be writable for additional changes
destFile.setWritable(true);
}
}
use of org.codehaus.plexus.util.DirectoryScanner in project maven-plugins by apache.
the class AbstractInvokerMojo method scanProjectsDirectory.
/**
* Scans the projects directory for projects to build. Both (POM) files and mere directories will be matched by the
* scanner patterns. If the patterns match a directory which contains a file named "pom.xml", the results will
* include the path to this file rather than the directory path in order to avoid duplicate invocations of the same
* project.
*
* @param includes The include patterns for the scanner, may be <code>null</code>.
* @param excludes The exclude patterns for the scanner, may be <code>null</code> to exclude nothing.
* @param type The type to assign to the resulting build jobs, must not be <code>null</code>.
* @return The build jobs matching the patterns, never <code>null</code>.
* @throws java.io.IOException If the project directory could not be scanned.
*/
private BuildJob[] scanProjectsDirectory(List<String> includes, List<String> excludes, String type) throws IOException {
if (!projectsDirectory.isDirectory()) {
return new BuildJob[0];
}
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(projectsDirectory.getCanonicalFile());
scanner.setFollowSymlinks(false);
if (includes != null) {
scanner.setIncludes(includes.toArray(new String[includes.size()]));
}
if (excludes != null) {
scanner.setExcludes(excludes.toArray(new String[excludes.size()]));
}
scanner.addDefaultExcludes();
scanner.scan();
Map<String, BuildJob> matches = new LinkedHashMap<String, BuildJob>();
for (String includedFile : scanner.getIncludedFiles()) {
matches.put(includedFile, new BuildJob(includedFile, type));
}
for (String includedDir : scanner.getIncludedDirectories()) {
String includedFile = includedDir + File.separatorChar + "pom.xml";
if (new File(scanner.getBasedir(), includedFile).isFile()) {
matches.put(includedFile, new BuildJob(includedFile, type));
} else {
matches.put(includedDir, new BuildJob(includedDir, type));
}
}
return matches.values().toArray(new BuildJob[matches.size()]);
}
Aggregations