Search in sources :

Example 6 with BuildJob

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);
}
Also used : BuildJob(org.apache.maven.plugins.invoker.model.BuildJob) File(java.io.File)

Example 7 with BuildJob

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);
}
Also used : BuildJob(org.apache.maven.plugins.invoker.model.BuildJob) File(java.io.File)

Example 8 with BuildJob

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();
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ExecutorService(java.util.concurrent.ExecutorService) BuildJob(org.apache.maven.plugins.invoker.model.BuildJob) File(java.io.File)

Example 9 with BuildJob

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileWriter(java.io.FileWriter) BuildJob(org.apache.maven.plugins.invoker.model.BuildJob) IOException(java.io.IOException) File(java.io.File) Writer(java.io.Writer) BuildJobXpp3Writer(org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Writer) SettingsXpp3Writer(org.apache.maven.settings.io.xpp3.SettingsXpp3Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter)

Example 10 with BuildJob

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()]);
}
Also used : DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) BuildJob(org.apache.maven.plugins.invoker.model.BuildJob) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

BuildJob (org.apache.maven.plugins.invoker.model.BuildJob)13 File (java.io.File)9 IOException (java.io.IOException)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Sink (org.apache.maven.doxia.sink.Sink)2 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 LinkedHashSet (java.util.LinkedHashSet)1 ExecutorService (java.util.concurrent.ExecutorService)1 BuildJobXpp3Reader (org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Reader)1 BuildJobXpp3Writer (org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Writer)1 MavenReportException (org.apache.maven.reporting.MavenReportException)1 SettingsXpp3Writer (org.apache.maven.settings.io.xpp3.SettingsXpp3Writer)1 DirectoryScanner (org.codehaus.plexus.util.DirectoryScanner)1