All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.linuxstuff.mojo.licensing.AggregateReportMojo Maven / Gradle / Ivy

package org.linuxstuff.mojo.licensing;

import java.io.File;
import java.util.List;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.linuxstuff.mojo.licensing.model.LicensingReport;

/**
 * Aggregate mojo. Will walk your reactor building in memory licensing reports
 * making them into one giant report. This mojo does not check for
 * missing or disliked artifacts (use {@code CheckMojo} for that).
 * 
 * @goal aggregate
 * @requiresDependencyResolution test
 * @requiresProject true
 * @aggregator
 * @threadSafe
 */
public class AggregateReportMojo extends CheckMojo {

    /**
     * Maven ProjectHelper.
     * 
     * @component
     * @readonly
     */
    private MavenProjectHelper projectHelper;

    /**
     * The projects in the reactor for aggregation report.
     * 
     * @parameter property="reactorProjects"
     * @readonly
     * @required
     */
    private List reactorProjects;

    /**
     * Should the generated report be attached to the reactor.
     *
     * @parameter property="attach" default-value="true"
     */
    private boolean attach;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {

        if (!project.isExecutionRoot()) {
            getLog().debug(project.getId() + " is not execution root, not making aggregated licensing report.");
            return;
        }

        readLicensingRequirements();

        LicensingReport bigReport = new LicensingReport();

        for (MavenProject project : reactorProjects) {

            if (shouldReportOn(project)) {
                LicensingReport report = generateReport(project);

                bigReport.combineWith(report);
            }
        }

        File file = new File(project.getBuild().getDirectory(), aggregatedThirdPartyLicensingFilename);

        bigReport.writeReport(file);

        if (attach) {
            projectHelper.attachArtifact(project, "xml", "license-report", file);
        }
    }

    private boolean shouldReportOn(MavenProject project) {
        String licensingSkip = (String) project.getProperties().get("licensing.skip");
        if (licensingSkip != null && Boolean.parseBoolean(licensingSkip)) {
            getLog().info("Licensing: Skipping project " + project);
            return false;
        }
        return true;

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy