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

de.smartics.maven.plugin.buildmetadata.BuildReportMojo Maven / Gradle / Ivy

/*
 * Copyright 2006-2019 smartics, Kronseder & Reiner GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package de.smartics.maven.plugin.buildmetadata;

import de.smartics.maven.plugin.buildmetadata.common.Property;
import de.smartics.maven.plugin.buildmetadata.util.FilePathNormalizer;

import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.reporting.MavenReportException;

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

/**
 * Generates a report about the meta data provided to the build.
 *
 * @goal buildmetadata-report
 * @phase site
 * @description Generates a report on the build meta data.
 * @requiresProject
 * @threadSafe
 * @since 1.0
 */
public final class BuildReportMojo extends AbstractReportMojo {
  // ********************************* Fields *********************************

  // --- constants ------------------------------------------------------------

  // --- members --------------------------------------------------------------

  /**
   * The name of the properties file to write. Per default this value is
   * overridden by packaging dependent locations. Please refer to
   * 
   * activatePropertyOutputFileMapping for details.
   *
   * @parameter default-value=
   *            "${project.build.outputDirectory}/META-INF/build.properties"
   * @since 1.0
   */
  private File propertiesOutputFile;

  /**
   * Used to activate the default mapping that writes the build properties of
   * deployable units to
   * ${project.build.directory}/${project.build.finalName}/META-INF/build.properties
   * and for standard JAR files to
   * ${project.build.outputDirectory}/META-INF/build.properties.
   *
   * @parameter default-value=true
   * @since 1.1
   */
  private boolean activatePropertyOutputFileMapping;

  /**
   * Maps a packaging to a location for the build meta data properties file.
   * 

* This mapping is especially useful for multi projects. *

* * @parameter * @since 1.1 */ protected List propertyOutputFileMapping; // NOPMD /** * The list of a system properties or environment variables to be selected by * the user to include into the build meta data properties. *

* The name is the name of the property, the section is relevant for placing * the property in one of the following sections: *

*
    *
  • build.scm
  • *
  • build.dateAndVersion
  • *
  • build.runtime
  • *
  • build.java
  • *
  • build.maven
  • *
  • project
  • *
  • build.misc
  • *
*

* If no valid section is given, the property is silently rendered in the * build.misc section. *

* * @parameter * @since 1.0 */ protected List properties; // NOPMD /** * Flag to choose whether (true) or not (false) the * build.properties file should be created. *

* This will adjust the path of the propertiesOutputFile to * ${project.build.directory}/build.properties. *

*

* This flag allows the report mojo to behave accordingly to that of the build * mojo. *

* * @parameter default-value= "true" * @since 1.2 */ protected boolean createPropertiesReport; // ****************************** Initializer ******************************* // ****************************** Constructors ****************************** // ****************************** Inner Classes ***************************** // ********************************* Methods ******************************** // --- init ----------------------------------------------------------------- // --- get&set -------------------------------------------------------------- /** * {@inheritDoc} * * @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale) */ public String getName(final Locale locale) { return getBundle(locale).getString("report.name"); } /** * {@inheritDoc} * * @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale) */ public String getDescription(final Locale locale) { return getBundle(locale).getString("report.description"); } /** * {@inheritDoc} * * @see org.apache.maven.reporting.MavenReport#getOutputName() */ public String getOutputName() { return "build-report"; } // --- business ------------------------------------------------------------- @Override public void execute() throws MojoExecutionException { init(); super.execute(); } /** * Initializes the Mojo. */ protected void init() { if (propertiesOutputFile == null || !propertiesOutputFile.canRead()) { final PropertyOutputFileMapper mapper = new PropertyOutputFileMapper( project, propertyOutputFileMapping, "build.properties"); this.propertyOutputFileMapping = mapper.initOutputFileMapping(); if (createPropertiesReport) { propertiesOutputFile = mapper.getPropertiesOutputFile( activatePropertyOutputFileMapping, propertiesOutputFile); } else { propertiesOutputFile = new File(project.getBuild().getDirectory(), "build.properties"); } } } @Override protected void executeReport(final Locale locale) throws MavenReportException { final Sink sink = getSink(); final ResourceBundle messages = getBundle(locale); final String baseDir = project.getBasedir().getAbsolutePath(); final BuildReportRenderer renderer = new BuildReportRenderer(new FilePathNormalizer(baseDir), messages, sink, propertiesOutputFile, properties); renderer.renderReport(); } /** * {@inheritDoc} *

* Returns false if the properties file that contains the build * information cannot be read. *

* * @see org.apache.maven.reporting.AbstractMavenReport#canGenerateReport() */ @Override public boolean canGenerateReport() { init(); return super.canGenerateReport() && propertiesOutputFile.canRead(); } // --- object basics -------------------------------------------------------- }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy