Search in sources :

Example 1 with BuildJob

use of org.apache.maven.plugins.invoker.model.BuildJob in project maven-plugins by apache.

the class AbstractInvokerMojo method relativizeProjectPaths.

/**
 * Relativizes the project paths of the specified build jobs against the directory specified by
 * {@link #projectsDirectory} (if possible). If a project path does not denote a sub path of the projects directory,
 * it is returned as is.
 *
 * @param buildJobs The build jobs whose project paths should be relativized, must not be <code>null</code> nor
 *            contain <code>null</code> elements.
 * @throws java.io.IOException If any path could not be relativized.
 */
private void relativizeProjectPaths(BuildJob[] buildJobs) throws IOException {
    String projectsDirPath = projectsDirectory.getCanonicalPath();
    for (BuildJob buildJob : buildJobs) {
        String projectPath = buildJob.getProject();
        File file = new File(projectPath);
        if (!file.isAbsolute()) {
            file = new File(projectsDirectory, projectPath);
        }
        String relativizedPath = relativizePath(file, projectsDirPath);
        if (relativizedPath == null) {
            relativizedPath = projectPath;
        }
        buildJob.setProject(relativizedPath);
    }
}
Also used : BuildJob(org.apache.maven.plugins.invoker.model.BuildJob) File(java.io.File)

Example 2 with BuildJob

use of org.apache.maven.plugins.invoker.model.BuildJob in project maven-plugins by apache.

the class AbstractInvokerMojo method execute.

/**
 * Invokes Maven on the configured test projects.
 *
 * @throws org.apache.maven.plugin.MojoExecutionException If the goal encountered severe errors.
 * @throws org.apache.maven.plugin.MojoFailureException If any of the Maven builds failed.
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skipInvocation) {
        getLog().info("Skipping invocation per configuration." + " If this is incorrect, ensure the skipInvocation parameter is not set to true.");
        return;
    }
    if (StringUtils.isEmpty(encoding)) {
        getLog().warn("File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!");
    }
    // done it here to prevent issues with concurrent access in case of parallel run
    if (!disableReports) {
        setupReportsFolder();
    }
    BuildJob[] buildJobs;
    if (pom == null) {
        try {
            buildJobs = getBuildJobs();
        } catch (final IOException e) {
            throw new MojoExecutionException("Error retrieving POM list from includes, " + "excludes, and projects directory. Reason: " + e.getMessage(), e);
        }
    } else {
        try {
            projectsDirectory = pom.getCanonicalFile().getParentFile();
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to discover projectsDirectory from " + "pom File parameter. Reason: " + e.getMessage(), e);
        }
        buildJobs = new BuildJob[] { new BuildJob(pom.getName(), BuildJob.Type.NORMAL) };
    }
    if ((buildJobs == null) || (buildJobs.length < 1)) {
        doFailIfNoProjects();
        getLog().info("No projects were selected for execution.");
        return;
    }
    handleScriptRunnerWithScriptClassPath();
    Collection<String> collectedProjects = new LinkedHashSet<String>();
    for (BuildJob buildJob : buildJobs) {
        collectProjects(projectsDirectory, buildJob.getProject(), collectedProjects, true);
    }
    File projectsDir = projectsDirectory;
    if (cloneProjectsTo != null) {
        cloneProjects(collectedProjects);
        projectsDir = cloneProjectsTo;
    } else {
        getLog().warn("Filtering of parent/child POMs is not supported without cloning the projects");
    }
    // First run setup jobs.
    BuildJob[] setupBuildJobs = null;
    try {
        setupBuildJobs = getSetupBuildJobsFromFolders();
    } catch (IOException e) {
        getLog().error("Failure during scanning of folders.", e);
    // TODO: Check shouldn't we fail in case of problems?
    }
    if (setupBuildJobs != null) {
        // Run setup jobs in single thread
        // mode.
        // 
        // Some Idea about ordering?
        getLog().info("Running Setup Jobs");
        runBuilds(projectsDir, setupBuildJobs, 1);
    }
    // Afterwards run all other jobs.
    BuildJob[] nonSetupBuildJobs = getNonSetupJobs(buildJobs);
    // We will run the non setup jobs with the configured
    // parallelThreads number.
    runBuilds(projectsDir, nonSetupBuildJobs, parallelThreads);
    writeSummaryFile(nonSetupBuildJobs);
    processResults(new InvokerSession(nonSetupBuildJobs));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BuildJob(org.apache.maven.plugins.invoker.model.BuildJob) IOException(java.io.IOException) File(java.io.File)

Example 3 with BuildJob

use of org.apache.maven.plugins.invoker.model.BuildJob in project maven-plugins by apache.

the class InvokerReport method executeReport.

protected void executeReport(Locale locale) throws MavenReportException {
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
    percentFormat = new DecimalFormat(getText(locale, "report.invoker.format.percent"), symbols);
    secondsFormat = new DecimalFormat(getText(locale, "report.invoker.format.seconds"), symbols);
    Sink sink = getSink();
    sink.head();
    sink.title();
    sink.text(getText(locale, "report.invoker.result.title"));
    sink.title_();
    sink.head_();
    sink.body();
    sink.section1();
    sink.sectionTitle1();
    sink.text(getText(locale, "report.invoker.result.title"));
    sink.sectionTitle1_();
    sink.paragraph();
    sink.text(getText(locale, "report.invoker.result.description"));
    sink.paragraph_();
    sink.section1_();
    // ----------------------------------
    // build buildJob beans
    // ----------------------------------
    File[] reportFiles = ReportUtils.getReportFiles(reportsDirectory);
    if (reportFiles.length <= 0) {
        getLog().info("no invoker report files found, skip report generation");
        return;
    }
    List<BuildJob> buildJobs = new ArrayList<BuildJob>(reportFiles.length);
    for (File reportFile : reportFiles) {
        try {
            BuildJobXpp3Reader reader = new BuildJobXpp3Reader();
            buildJobs.add(reader.read(ReaderFactory.newXmlReader(reportFile)));
        } catch (XmlPullParserException e) {
            throw new MavenReportException("Failed to parse report file: " + reportFile, e);
        } catch (IOException e) {
            throw new MavenReportException("Failed to read report file: " + reportFile, e);
        }
    }
    // ----------------------------------
    // summary
    // ----------------------------------
    constructSummarySection(buildJobs, locale);
    // ----------------------------------
    // per file/it detail
    // ----------------------------------
    sink.section2();
    sink.sectionTitle2();
    sink.text(getText(locale, "report.invoker.detail.title"));
    sink.sectionTitle2_();
    sink.section2_();
    // detail tests table header
    sink.table();
    sink.tableRow();
    // -------------------------------------------
    // name | Result | time | message
    // -------------------------------------------
    sinkTableHeader(sink, getText(locale, "report.invoker.detail.name"));
    sinkTableHeader(sink, getText(locale, "report.invoker.detail.result"));
    sinkTableHeader(sink, getText(locale, "report.invoker.detail.time"));
    sinkTableHeader(sink, getText(locale, "report.invoker.detail.message"));
    sink.tableRow_();
    for (BuildJob buildJob : buildJobs) {
        renderBuildJob(buildJob, locale);
    }
    sink.table_();
    sink.body_();
    sink.flush();
    sink.close();
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) Sink(org.apache.maven.doxia.sink.Sink) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) BuildJobXpp3Reader(org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) BuildJob(org.apache.maven.plugins.invoker.model.BuildJob) IOException(java.io.IOException) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 4 with BuildJob

use of org.apache.maven.plugins.invoker.model.BuildJob in project maven-plugins by apache.

the class InvokerReport method constructSummarySection.

private void constructSummarySection(List<? extends BuildJob> buildJobs, Locale locale) {
    Sink sink = getSink();
    sink.section2();
    sink.sectionTitle2();
    sink.text(getText(locale, "report.invoker.summary.title"));
    sink.sectionTitle2_();
    sink.section2_();
    // ------------------------------------------------------------------------
    // Building a table with
    // it number | succes nb | failed nb | Success rate | total time | avg time
    // ------------------------------------------------------------------------
    sink.table();
    sink.tableRow();
    sinkTableHeader(sink, getText(locale, "report.invoker.summary.number"));
    sinkTableHeader(sink, getText(locale, "report.invoker.summary.success"));
    sinkTableHeader(sink, getText(locale, "report.invoker.summary.failed"));
    sinkTableHeader(sink, getText(locale, "report.invoker.summary.skipped"));
    sinkTableHeader(sink, getText(locale, "report.invoker.summary.success.rate"));
    sinkTableHeader(sink, getText(locale, "report.invoker.summary.time.total"));
    sinkTableHeader(sink, getText(locale, "report.invoker.summary.time.avg"));
    int number = buildJobs.size();
    int success = 0;
    int failed = 0;
    int skipped = 0;
    double totalTime = 0;
    for (BuildJob buildJob : buildJobs) {
        if (BuildJob.Result.SUCCESS.equals(buildJob.getResult())) {
            success++;
        } else if (BuildJob.Result.SKIPPED.equals(buildJob.getResult())) {
            skipped++;
        } else {
            failed++;
        }
        totalTime += buildJob.getTime();
    }
    sink.tableRow_();
    sink.tableRow();
    sinkCell(sink, Integer.toString(number));
    sinkCell(sink, Integer.toString(success));
    sinkCell(sink, Integer.toString(failed));
    sinkCell(sink, Integer.toString(skipped));
    if (success + failed > 0) {
        sinkCell(sink, percentFormat.format((double) success / (success + failed)));
    } else {
        sinkCell(sink, "");
    }
    sinkCell(sink, secondsFormat.format(totalTime));
    sinkCell(sink, secondsFormat.format(totalTime / number));
    sink.tableRow_();
    sink.table_();
}
Also used : Sink(org.apache.maven.doxia.sink.Sink) BuildJob(org.apache.maven.plugins.invoker.model.BuildJob)

Example 5 with BuildJob

use of org.apache.maven.plugins.invoker.model.BuildJob in project maven-plugins by apache.

the class AbstractInvokerMojo method getBuildJobs.

/**
 * Gets the build jobs that should be processed. Note that the order of the returned build jobs is significant.
 *
 * @return The build jobs to process, may be empty but never <code>null</code>.
 * @throws java.io.IOException If the projects directory could not be scanned.
 */
BuildJob[] getBuildJobs() throws IOException {
    BuildJob[] buildJobs;
    if (invokerTest == null) {
        List<String> excludes = calculateExcludes();
        BuildJob[] setupPoms = scanProjectsDirectory(setupIncludes, excludes, BuildJob.Type.SETUP);
        if (getLog().isDebugEnabled()) {
            getLog().debug("Setup projects: " + Arrays.asList(setupPoms));
        }
        BuildJob[] normalPoms = scanProjectsDirectory(pomIncludes, excludes, BuildJob.Type.NORMAL);
        Map<String, BuildJob> uniquePoms = new LinkedHashMap<String, BuildJob>();
        for (BuildJob setupPom : setupPoms) {
            uniquePoms.put(setupPom.getProject(), setupPom);
        }
        for (BuildJob normalPom : normalPoms) {
            if (!uniquePoms.containsKey(normalPom.getProject())) {
                uniquePoms.put(normalPom.getProject(), normalPom);
            }
        }
        buildJobs = uniquePoms.values().toArray(new BuildJob[uniquePoms.size()]);
    } else {
        String[] testRegexes = StringUtils.split(invokerTest, ",");
        List<String> includes = new ArrayList<String>(testRegexes.length);
        List<String> excludes = new ArrayList<String>();
        for (String regex : testRegexes) {
            // user just use -Dinvoker.test=MWAR191,MNG111 to use a directory thats the end is not pom.xml
            if (regex.startsWith("!")) {
                excludes.add(regex.substring(1));
            } else {
                includes.add(regex);
            }
        }
        // it would be nice if we could figure out what types these are... but perhaps
        // not necessary for the -Dinvoker.test=xxx t
        buildJobs = scanProjectsDirectory(includes, excludes, BuildJob.Type.DIRECT);
    }
    relativizeProjectPaths(buildJobs);
    return buildJobs;
}
Also used : ArrayList(java.util.ArrayList) BuildJob(org.apache.maven.plugins.invoker.model.BuildJob) 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