Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2006-2013 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 com.redhat.rcm.maven.plugin.buildmetadata;
 
 import java.io.File;
 import java.util.Date;
 
 
Provides the build properties. This information is also written to a build.properties file.

Since:
1.0
Goal:
provide-buildmetadata
Phase:
initialize
RequiresProject:
ThreadSafe:
Description:
Provides a build meta data to the build process.
 
 public final class BuildMetaDataMojo extends AbstractBuildMojo // NOPMD
 { // NOPMD
   // ********************************* Fields *********************************
 
   // --- constants ------------------------------------------------------------
 
   // --- members --------------------------------------------------------------
 
   // ... Mojo infrastructure ..................................................
 
  
The user's settings.

Since:
1.0
Parameter:
expression="${settings}"
Required:
Readonly:
 
   private Settings settings;

  
If set to true, build properties will be generate even if they already exist in the target folder.

Since:
1.0
Parameter:
default-value="false"
 
   private boolean forceNewProperties;

  
In offline mode the plugin will not generate revision information.

Since:
1.0
Parameter:
default-value="${settings.offline}"
Required:
Readonly:
 
   private boolean offline;

  
Add SCM information if set to true, skip it, if set to false. If you are not interested in SCM information, set this to false.

For security reasons you may want to remove the properties file from the META-INF folder. Please refer to propertiesOutputFile property.

Since:
1.0
Parameter:
expression="${buildMetaData.addScmInfo}" default-value="true"
  private boolean addScmInfo;

  
Fail if revision is requested to be retrieved, access to SCM is provided, system is online, nothing should prevent the build from fetching the information.

If set to true the build will fail, if revision cannot be fetched under the conditions mentioned above. If set to false the build will continue silently so that the meta data do not contain the revision.

Since:
1.0
Parameter:
expression="${buildMetaData.failOnMissingRevision}" default-value="false"
  private boolean failOnMissingRevision;

  
Add host information if set to true, skip it, if set to false. If you are not interested in host information (e.g. for security reasons), set this to false.

For security reasons you may want to remove the properties file from the META-INF folder. Please refer to propertiesOutputFile property.

Since:
1.0
Parameter:
expression="${buildMetaData.addHostInfo}" default-value="true"
  private boolean addHostInfo;

  
Add environment variables if set to true, skip it, if set to false. If you are not interested in the environment variables of the host (e.g. for security reasons), set this to false.

For security reasons you may want to remove the properties file from the META-INF folder. Please refer to propertiesOutputFile property.

Since:
1.0
Parameter:
expression="${buildMetaData.addEnvInfo}" default-value="false"
  private boolean addEnvInfo;

  
Add information about the Java runtime running the build if set to true, skip it, if set to false.

Since:
1.0
Parameter:
expression="${buildMetaData.addJavaRuntimeInfo}" default-value="true"
  private boolean addJavaRuntimeInfo;

  
Add information about the operating system the build is run in if set to true, skip it, if set to false.

Since:
1.0
Parameter:
expression="${buildMetaData.addOsInfo}" default-value="true"
  private boolean addOsInfo;

  
Add Maven execution information (all properties starting with build.maven.execution, like command line, goals, profiles, etc.) if set to true, skip it, if set to false. If you are not interested in execution information, set this to false.

For security reasons you may want to remove the properties file from the META-INF folder. Please refer to propertiesOutputFile property.

Since:
1.0
Parameter:
expression="${buildMetaData.addMavenExecutionInfo}" default-value="true"
  private boolean addMavenExecutionInfo;

  
Add project information (homepage URL, categories, tags, etc.) if set to true, skip it, if set to false. If you are not interested in execution information, set this to false.

Since:
1.1
Parameter:
expression="${buildMetaData.addProjectInfo}" default-value="false"
  private boolean addProjectInfo;

  
While the command line may be useful to refer to for a couple of reasons, displaying it with the build properties is a security issue. Some plugins allow to read passwords as properties from the command line and this sensible data will be shown.

Therefore the command line is hidden by default (true). If you want to include this information, use a value of false.

Since:
1.0
Parameter:
expression="${buildMetaData.hideCommandLineInfo}" default-value="true"
  private boolean hideCommandLineInfo;

  
While the MAVEN_OPTS may be useful to refer to for a couple of reasons, displaying them with the build properties is a security issue. Some plugins allow to read passwords as properties from the command line and this sensible data will be shown.

Therefore the MAVEN_OPTS are hidden by default ( true). If you want to include this information, use a value of false.

This exclusion does not prevent the property from being written as part of addEnvInfo!

Since:
1.0
Parameter:
expression="${buildMetaData.hideMavenOptsInfo}" default-value="true"
  private boolean hideMavenOptsInfo;

  
While the JAVA_OPTS may be useful to refer to for a couple of reasons, displaying them with the build properties is a security issue. Some plugins allow to read passwords as properties from the command line and this sensible data will be shown.

Therefore the JAVA_OPTS are hidden by default ( true). If you want to include this information, use a value of false.

This exclusion does not prevent the property from being written as part of addEnvInfo!

Since:
1.0
Parameter:
expression="${buildMetaData.hideJavaOptsInfo}" default-value="true"
  private boolean hideJavaOptsInfo;

  
A simple flag to skip the generation of the build information. If set on the command line use -DbuildMetaData.skip.

Since:
1.0
Parameter:
expression="${buildMetaData.skip}" default-value="false"
  private boolean skip;

  
If it should be checked if the local files are up-to-date with the remote files in the SCM repository. If the value is true the result of the check, including the list of changed files, is added to the build meta data.

Since:
1.0
Parameter:
expression="${buildMetaData.validateCheckout}" default-value="true"
  private boolean validateCheckout;

  
Specifies the log level used for this plugin.

Allowed values are SEVERE, WARNING, INFO and FINEST.

Since:
1.0
Parameter:
expression="${buildMetaData.logLevel}"
  private String logLevel;

  
The manager instance to access the SCM system. Provides access to the repository and the provider information.

Since:
1.0
Component:
  private ScmManager scmManager;

  
Allows the user to choose which scm connection to use when connecting to the scm. Can either be "connection" or "developerConnection".

Since:
1.0
Parameter:
default-value="connection"
Required:
  private String connectionType;
  // ... core information .....................................................

  
The date pattern to use to format the build and revision dates. Please refer to the SimpleDateFormat class for valid patterns.

Since:
1.0
Parameter:
expression="${buildMetaData.buildDate.pattern}" default-value="dd.MM.yyyy"

  
The property to query for the build user.

Since:
1.0
Parameter:
default-value="username"
  // ... build information related ............................................

  
Flag to add the build date to the full version separated by a '-'. If true the build date is added, if false it is not.

Since:
1.0
Parameter:
expression="${buildMetaData.addBuildDateToFullVersion}" default-value="true"
  private boolean addBuildDateToFullVersion;
  // ... svn related ..........................................................

  
Used to specify the date format of the log entries that are retrieved from your SCM system.

Since:
1.0
Parameter:
expression="${changelog.dateFormat}" default-value="yyyy-MM-dd HH:mm:ss"
Required:
  private String scmDateFormat;

  
Input dir. Directory where the files under SCM control are located.

Since:
1.0
Parameter:
expression="${basedir}"
Required:
  private File basedir;

  
The user name (used by svn and starteam protocol).

Since:
1.0
Parameter:
expression="${username}"
  private String userName;

  
The user password (used by svn and starteam protocol).

Since:
1.0
Parameter:
expression="${password}"
  private String password;

  
The private key (used by java svn).

Since:
1.0
Parameter:
expression="${privateKey}"
  private String privateKey;

  
The passphrase (used by java svn).

Since:
1.0
Parameter:
expression="${passphrase}"
  private String passphrase;

  
The url of tags base directory (used by svn protocol).

Since:
1.0
Parameter:
expression="${tagBase}"
  private String tagBase;

  
Flag to add the revision number to the full version separated by an 'r'. If true the revision number is added, if false it is not.

Since:
1.0
Parameter:
expression="${buildMetaData.addReleaseNumberToFullVersion}" default-value="true"
  private boolean addReleaseNumberToFullVersion;

  
Flag to add the tag -locally-modified to the full version string to make visible that this artifact has been created with locally modified sources. This is often the case while the artifact is built while still working on an issue before it is committed to the SCM repository.

Since:
1.0
Parameter:
expression="${buildMetaData.addLocallyModifiedTagToFullVersion}" default-value="true"
  private boolean addLocallyModifiedTagToFullVersion;

  
The range of the query in days to fetch change log entries from the SCM. If no change logs have been found, the range is incremented up to com.redhat.rcm.maven.plugin.buildmetadata.scm.maven.ScmAccessInfo;. DEFAULT_RETRY_COUNT (5) times. If no change log has been found after these com.redhat.rcm.maven.plugin.buildmetadata.scm.maven.ScmAccessInfo;. DEFAULT_RETRY_COUNT (5) additional queries, the revision number will not be set with a valid value.

Since:
1.0
Parameter:
expression="${buildMetaData.queryRangeInDays}" default-value="30"
  private int queryRangeInDays;

  
Flag to fail if local modifications have been found. The value is true if the build should fail if there are modifications (any files not in-sync with the remote repository), false if the fact is only to be noted in the build properties.

Since:
1.0
Parameter:
default-value="false"
  private boolean failOnLocalModifications;

  
The flag to ignore files and directories starting with a dot for checking modified files. This implicates that any files or directories, starting with a dot, are ignored when the check on changed files is run. If the value is true, dot files are ignored, if it is set to false, dot files are respected.

Since:
1.0
Parameter:
default-value="true"
  private boolean ignoreDotFilesInBaseDir;
  // ****************************** Initializer *******************************
  // ****************************** Constructors ******************************
  // ****************************** Inner Classes *****************************
  // ********************************* Methods ********************************
  // --- init -----------------------------------------------------------------
  // --- get&set --------------------------------------------------------------
  // --- business -------------------------------------------------------------
  {
    if (!)
    {
      super.execute();
      final String baseDir = .getBasedir().getAbsolutePath();
      final FilePathNormalizer filePathNormalizer =
          new FilePathNormalizer(baseDir);
      final BuildPropertiesFileHelper helper =
              filePathNormalizer);
      final Properties projectProperties = helper.getProjectProperties();
      if (!isBuildPropertiesAlreadySet(projectProperties))
      {
        LoggingUtils.configureLogger(getLog(), );
        final Properties buildMetaDataProperties = new Properties();
        if (isBuildPropertiesToBeRebuild())
        {
          createBuildProperties(helperprojectProperties,
              buildMetaDataProperties);
        }
        else
        {
          getLog().info("Reusing previously built metadata file.");
          helper.readBuildPropertiesFile(buildMetaDataProperties);
        }
        updateMavenEnvironment(buildMetaDataPropertieshelper);
      }
    }
    else
    {
      getLog().info("Skipping buildmetadata collection since skip=true.");
    }
  }
  private void createBuildProperties(final BuildPropertiesFileHelper helper,
      final Properties projectProperties,
      final Properties buildMetaDataPropertiesthrows MojoExecutionException,
  {
    final Date buildDate = .getStartTime();
    provideBuildUser(projectPropertiesbuildMetaDataProperties);
    provideMavenMetaData(buildMetaDataProperties);
    provideHostMetaData(buildMetaDataProperties);
    final ScmInfo scmInfo = provideScmMetaData(buildMetaDataProperties);
    provideBuildDateMetaData(buildMetaDataPropertiesbuildDate);
    // The custom providers are required to be run at the end.
    // This allows these providers to access the information generated
    // by the built-in providers.
    provideBuildMetaData(buildMetaDataPropertiesscmInfo,
        false);
    writeBuildMetaData(helperbuildMetaDataProperties);
  }
  private void writeBuildMetaData(final BuildPropertiesFileHelper helper,
      final Properties buildMetaDataPropertiesthrows MojoExecutionException
  {
    helper.writePropertiesFile(buildMetaDataProperties);
    if ()
    {
      final String projectRootPath = .getBasedir().getAbsolutePath();
      final BuildXmlFileHelper xmlHelper =
          new BuildXmlFileHelper(projectRootPathgetLog(), ,
              );
      xmlHelper.writeXmlFile(buildMetaDataProperties);
    }
  }
  private void provideMavenMetaData(final Properties buildMetaDataProperties)
  {
    final MavenMetaDataSelection selection = new MavenMetaDataSelection();
    selection.setAddEnvInfo();
    selection.setAddOsInfo();
    final MavenMetaDataProvider mavenMetaDataProvider =
        new MavenMetaDataProvider(selection);
    mavenMetaDataProvider.provideBuildMetaData(buildMetaDataProperties);
  }
  private ScmInfo provideScmMetaData(final Properties buildMetaDataProperties)
    throws MojoFailureException
  {
    try
    {
      final ScmInfo scmInfo = createScmInfo();
      final ScmMetaDataProvider scmMetaDataProvider =
          new ScmMetaDataProvider(scmInfo);
      scmMetaDataProvider.provideBuildMetaData(buildMetaDataProperties);
      return scmInfo;
    }
    catch (final ScmNoRevisionException e)
    {
      throw new MojoFailureException(e.getMessage()); // NOPMD
    }
  }
  private void provideHostMetaData(final Properties buildMetaDataProperties)
  {
    if ()
    {
      final HostMetaDataProvider hostMetaData = new HostMetaDataProvider();
      hostMetaData.provideBuildMetaData(buildMetaDataProperties);
    }
  }
  private void provideBuildDateMetaData(
      final Properties buildMetaDataPropertiesfinal Date buildDate)
  {
    final String buildDateString =
        createBuildDate(buildMetaDataPropertiesbuildDate);
    createYears(buildMetaDataPropertiesbuildDate);
    createBuildVersion(buildMetaDataPropertiesbuildDatebuildDateString);
  }
  private ScmInfo createScmInfo()
  {
    final ScmCredentials scmCredentials =
    final ScmControl scmControl =
    final ScmInfo scmInfo =
            scmCredentials,
            scmControl);
    return scmInfo;
  }
  private boolean isBuildPropertiesToBeRebuild()
  {
  }
  private boolean isBuildPropertiesAlreadySet(final Properties projectProperties)
  {
    return projectProperties.getProperty(.) != null;
  }

  
Provides the name of the user running the build. The value is either specified in the project properties or is taken from the Java system properties (user.name).

Parameters:
projectProperties the project properties.
buildMetaDataProperties the build meta data properties.
  private void provideBuildUser(final Properties projectProperties,
      final Properties buildMetaDataProperties)
  {
    String userNameValue = System.getProperty("user.name");
    if (( != null))
    {
      final String value = projectProperties.getProperty();
      if (!StringUtils.isBlank(value))
      {
        userNameValue = value;
      }
    }
    if (userNameValue != null)
    {
      buildMetaDataProperties.setProperty(.,
          userNameValue);
    }
  }

  
Creates and adds the build date information.

Parameters:
buildMetaDataProperties the build meta data properties.
buildDate the date of the build.
Returns:
the formatted build date.
  private String createBuildDate(final Properties buildMetaDataProperties,
      final Date buildDate)
  {
    final DateFormat format =
    final String buildDateString = format.format(buildDate);
    final String timestamp = String.valueOf(buildDate.getTime());
    buildMetaDataProperties.setProperty(.,
        buildDateString);
    buildMetaDataProperties.setProperty(.,
        this.);
    buildMetaDataProperties.setProperty(.,
        timestamp);
    return buildDateString;
  }

  
Adds the build and copyright year information.

Parameters:
buildMetaDataProperties the build meta data properties.
buildDate the build date to create the build year information.
  private void createYears(final Properties buildMetaDataProperties,
      final Date buildDate)
  {
    final DateFormat yearFormat = new SimpleDateFormat("yyyy".);
    final String buildYearString = yearFormat.format(buildDate);
    buildMetaDataProperties.setProperty(.,
        buildYearString);
    final String inceptionYearString = .getInceptionYear();
    final String copyrightYearString =
        (buildYearString.equals(inceptionYearString) ? inceptionYearString
            : inceptionYearString + '-' + buildYearString);
    buildMetaDataProperties.setProperty(.,
        copyrightYearString);
  }

  
Adds the version information of the artifact.

Parameters:
buildMetaDataProperties the build meta data properties.
buildDate the date of the build.
buildDateString the formatted date string.
  private void createBuildVersion(final Properties buildMetaDataProperties,
      final Date buildDatefinal String buildDateString)
  {
    final String version = .getVersion();
    buildMetaDataProperties.setProperty(.version);
    buildMetaDataProperties.setProperty(.,
        .getGroupId());
    buildMetaDataProperties.setProperty(.,
        .getArtifactId());
    buildMetaDataProperties.setProperty(.,
        buildDateString);
    final String fullVersion =
        createFullVersion(buildMetaDataPropertiesbuildDate);
    buildMetaDataProperties.setProperty(.,
        fullVersion);
  }

  
Creates the full version string which may include the date, the build, and the revision.

Parameters:
buildMetaDataProperties the generated build meta data properties.
buildDate the date of the current build.
Returns:
the full version string.
  private String createFullVersion(final Properties buildMetaDataProperties,
      final Date buildDate)
  {
    final String version = .getVersion();
    final DateFormat format = new SimpleDateFormat("yyyyMMdd".);
    final String datePart = format.format(buildDate);
    final String revisionId =
        buildMetaDataProperties.getProperty(.);
    final String versionPrefixversionSuffix;
    if (version.endsWith("-SNAPSHOT"))
    {
      versionPrefix = version.substring(0, version.lastIndexOf('-'));
      versionSuffix = "-SNAPSHOT";
    }
    else
    {
      versionPrefix = version;
      versionSuffix = "";
    }
    final String modified;
        && "true".equals(buildMetaDataProperties
    {
      modified = "-locally-modified";
    }
    else
    {
      modified = "";
    }
    final String fullVersion =
        versionPrefix
            + ( ? '-' + datePart : "")
            + (
               && StringUtils.isNotBlank(revisionId) ? "r" + revisionId : "")
            + modified + versionSuffix;
    return fullVersion;
  }
  // --- object basics --------------------------------------------------------
New to GrepCode? Check out our FAQ X