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

org.codehaus.mojo.license.AbstractLicenseReportMojo Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.codehaus.mojo.license;

/*
 * #%L
 * License Maven Plugin
 * %%
 * Copyright (C) 2012 CodeLutin, Codehaus, Tony Chemit
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 *
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.siterenderer.Renderer;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.mojo.license.api.DefaultThirdPartyHelper;
import org.codehaus.mojo.license.api.DependenciesTool;
import org.codehaus.mojo.license.api.ThirdPartyHelper;
import org.codehaus.mojo.license.api.ThirdPartyTool;
import org.codehaus.plexus.i18n.I18N;

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

/**
 * Base class for all license reports.
 *
 * @author tchemit 
 * @since 1.1
 */
public abstract class AbstractLicenseReportMojo
    extends AbstractMavenReport
{

    // ----------------------------------------------------------------------
    // Mojo Parameters
    // ----------------------------------------------------------------------

    /**
     * The output directory for the report. Note that this parameter is only evaluated if the goal is run directly from
     * the command line. If the goal is run indirectly as part of a site generation, the output directory configured in
     * the Maven Site Plugin is used instead.
     *
     * @since 1.1
     */
    @Parameter( defaultValue = "${project.reporting.outputDirectory}", required = true )
    private File outputDirectory;

    /**
     * Flag to activate verbose mode.
     * 

* Note: Verbose mode is always on if you starts a debug maven instance * (says via {@code -X}). * * @since 1.0 */ @Parameter( property = "license.verbose", defaultValue = "${maven.verbose}" ) private boolean verbose; /** * Skip to generate the report. * * @since 1.1 */ @Parameter( property = "license.skip" ) private Boolean skip; /** * Encoding used to read and writes files. *

* Note: If nothing is filled here, we will use the system * property {@code file.encoding}. * * @since 1.0 */ @Parameter( property = "license.encoding", defaultValue = "${project.build.sourceEncoding}" ) private String encoding; /** * Local Repository. * * @since 1.1 */ @Parameter( property = "localRepository", required = true, readonly = true ) private ArtifactRepository localRepository; /** * Remote repositories used for the project. * * @since 1.1 */ @Parameter( property = "project.remoteArtifactRepositories", required = true, readonly = true ) private List remoteRepositories; // ---------------------------------------------------------------------- // Plexus Components // ---------------------------------------------------------------------- /** * The Maven Project. * * @since 1.1 */ @Component private MavenProject project; /** * Doxia Site Renderer component. * * @component * @since 1.1 */ @Component private Renderer siteRenderer; /** * Internationalization component. * * @component * @since 1.1 */ @Component private I18N i18n; /** * dependencies tool. * * @component * @readonly * @since 1.1 */ @Component private DependenciesTool dependenciesTool; /** * third party tool. * * @component * @readonly * @since 1.1 */ @Component private ThirdPartyTool thirdPartyTool; /** * Third-party helper (high level tool with common code for mojo and report). */ private ThirdPartyHelper helper; // ---------------------------------------------------------------------- // Abstract Methods // ---------------------------------------------------------------------- /** * Generates the report. * * @param locale the locale to generate the report for. * @param sink the report formatting tool. * @throws MavenReportException when things go wrong. * @throws MojoExecutionException when things go wrong. * @throws MojoFailureException when things go wrong. */ protected abstract void doGenerateReport( Locale locale, Sink sink ) throws MavenReportException, MojoExecutionException, MojoFailureException; // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- protected ThirdPartyHelper getHelper() { if ( helper == null ) { helper = new DefaultThirdPartyHelper( project, encoding, verbose, dependenciesTool, thirdPartyTool, localRepository, remoteRepositories, getLog() ); } return helper; } // ---------------------------------------------------------------------- // AbstractMavenReport Implementaton // ---------------------------------------------------------------------- /** * {@inheritDoc} */ protected void executeReport( Locale locale ) throws MavenReportException { if ( !Boolean.TRUE.equals( skip ) ) { try { doGenerateReport( locale, getSink() ); } catch ( MojoExecutionException e ) { throw new MavenReportException( e.getMessage(), e ); } catch ( MojoFailureException e ) { throw new MavenReportException( e.getMessage(), e ); } } } /** * {@inheritDoc} */ protected MavenProject getProject() { return project; } /** * {@inheritDoc} */ protected String getOutputDirectory() { if ( !outputDirectory.isAbsolute() ) { outputDirectory = new File( project.getBasedir(), outputDirectory.getPath() ); } return outputDirectory.getAbsolutePath(); } /** * {@inheritDoc} */ protected Renderer getSiteRenderer() { return siteRenderer; } /** * {@inheritDoc} */ public String getDescription( Locale locale ) { return getText( locale, "report.description" ); } /** * {@inheritDoc} */ public String getName( Locale locale ) { return getText( locale, "report.title" ); } // ---------------------------------------------------------------------- // Public Methods // ---------------------------------------------------------------------- /** * Gets the localized message for this report. * * @param locale the locale. * @param key the message key. * @return the message. */ public String getText( Locale locale, String key ) { return i18n.getString( getOutputName(), locale, key ); } public I18N getI18n() { return i18n; } public boolean isVerbose() { return verbose; } public final String getEncoding() { return encoding; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy