use of org.apache.maven.plugins.invoker.model.BuildJob in project maven-plugins by apache.
the class InvokerMojoTest method testFullPatternInvokerTest.
public void testFullPatternInvokerTest() throws Exception {
InvokerMojo invokerMojo = new InvokerMojo();
String dirPath = getBasedir() + "/src/test/resources/unit";
List<String> goals = invokerMojo.getGoals(new File(dirPath));
assertEquals(1, goals.size());
setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath));
setVariableValueToObject(invokerMojo, "invokerTest", "*");
BuildJob[] poms = invokerMojo.getBuildJobs();
assertEquals(4, poms.length);
}
use of org.apache.maven.plugins.invoker.model.BuildJob in project maven-plugins by apache.
the class InvokerMojoTest method testMultiInvokerTest.
public void testMultiInvokerTest() throws Exception {
InvokerMojo invokerMojo = new InvokerMojo();
String dirPath = getBasedir() + "/src/test/resources/unit";
List<String> goals = invokerMojo.getGoals(new File(dirPath));
assertEquals(1, goals.size());
setVariableValueToObject(invokerMojo, "projectsDirectory", new File(dirPath));
setVariableValueToObject(invokerMojo, "invokerTest", "*dummy*,*terpolatio*");
BuildJob[] poms = invokerMojo.getBuildJobs();
assertEquals(2, poms.length);
}
use of org.apache.maven.plugins.invoker.model.BuildJob in project maven-plugins by apache.
the class AbstractInvokerMojo method runBuilds.
/**
* Runs the specified build jobs.
*
* @param projectsDir The base directory of all projects, must not be <code>null</code>.
* @param buildJobs The build jobs to run must not be <code>null</code> nor contain <code>null</code> elements.
* @throws org.apache.maven.plugin.MojoExecutionException If any build could not be launched.
*/
private void runBuilds(final File projectsDir, BuildJob[] buildJobs, int runWithParallelThreads) throws MojoExecutionException {
if (!localRepositoryPath.exists()) {
localRepositoryPath.mkdirs();
}
// -----------------------------------------------
// interpolate settings file
// -----------------------------------------------
File interpolatedSettingsFile = interpolateSettings();
final File mergedSettingsFile = mergeSettings(interpolatedSettingsFile);
if (mavenHome != null) {
actualMavenVersion = SelectorUtils.getMavenVersion(mavenHome);
} else {
actualMavenVersion = SelectorUtils.getMavenVersion();
}
scriptRunner.setGlobalVariable("mavenVersion", actualMavenVersion);
final CharSequence actualJreVersion;
// @todo if ( javaVersions ) ... to be picked up from toolchains
if (javaHome != null) {
actualJreVersion = resolveExternalJreVersion();
} else {
actualJreVersion = SelectorUtils.getJreVersion();
}
try {
if (runWithParallelThreads > 1) {
getLog().info("use parallelThreads " + runWithParallelThreads);
ExecutorService executorService = Executors.newFixedThreadPool(runWithParallelThreads);
for (final BuildJob job : buildJobs) {
executorService.execute(new Runnable() {
public void run() {
try {
runBuild(projectsDir, job, mergedSettingsFile, javaHome, actualJreVersion);
} catch (MojoExecutionException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
});
}
try {
executorService.shutdown();
// TODO add a configurable time out
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
} else {
for (BuildJob job : buildJobs) {
runBuild(projectsDir, job, mergedSettingsFile, javaHome, actualJreVersion);
}
}
} finally {
if (interpolatedSettingsFile != null && cloneProjectsTo == null) {
interpolatedSettingsFile.delete();
}
if (mergedSettingsFile != null && mergedSettingsFile.exists()) {
mergedSettingsFile.delete();
}
}
}
use of org.apache.maven.plugins.invoker.model.BuildJob in project maven-plugins by apache.
the class AbstractInvokerMojo method writeSummaryFile.
private void writeSummaryFile(BuildJob[] buildJobs) throws MojoExecutionException {
File summaryReportFile = new File(reportsDirectory, "invoker-summary.txt");
try {
Writer writer = new BufferedWriter(new FileWriter(summaryReportFile));
for (int i = 0; i < buildJobs.length; i++) {
BuildJob buildJob = buildJobs[i];
if (!buildJob.getResult().equals(BuildJob.Result.SUCCESS)) {
writer.append(buildJob.getResult());
writer.append(" [");
writer.append(buildJob.getProject());
writer.append("] ");
if (buildJob.getFailureMessage() != null) {
writer.append(" ");
writer.append(buildJob.getFailureMessage());
}
writer.append("\n");
}
}
writer.close();
} catch (IOException e) {
throw new MojoExecutionException("Failed to write summary report " + summaryReportFile, e);
}
}
use of org.apache.maven.plugins.invoker.model.BuildJob 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