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.common;
 
 import java.util.Date;
 
 
Helper to access the revision information.

Author(s):
Robert Reiner
Version:
$Revision:591 $
 
 public final class RevisionHelper
 {
   // ********************************* Fields *********************************
 
   // --- constants ------------------------------------------------------------
 
  
Reference to the logger for this class.
 
   private static final Log LOG = LogFactory.getLog(RevisionHelper.class);
 
   // --- members --------------------------------------------------------------
 
  
The manager instance to access the SCM system. Provides access to the repository and the provider information.
 
   private final ScmManager scmManager;

  
The information to connect to the SCM.
 
   private final ScmConnectionInfo scmConnectionInfo;

  
The information to query the SCM.
 
   private final ScmAccessInfo scmAccessInfo;

  
The date pattern to use to format revision dates.
 
   private final String buildDatePattern;
 
   // ****************************** Initializer *******************************
 
   // ****************************** Constructors ******************************
 
  
Default constructor.

Parameters:
scmManager the manager instance to access the SCM system.
scmConnectionInfo the information to connect to the SCM.
scmAccessInfo the information to query the SCM.
buildDatePattern the date pattern to use to format revision dates.
 
   public RevisionHelper(final ScmManager scmManager,
       final ScmConnectionInfo scmConnectionInfo,
       final ScmAccessInfo scmAccessInfofinal String buildDatePattern)
   {
     this. = scmManager;
     this. = scmConnectionInfo;
     this. = scmAccessInfo;
     this. = buildDatePattern;
   }
 
  // ****************************** Inner Classes *****************************
  // ********************************* Methods ********************************
  // --- init -----------------------------------------------------------------
  // --- get&set --------------------------------------------------------------
  // --- business -------------------------------------------------------------

  
Fetches the revision information and adds it to the property sets.

Parameters:
buildMetaDataProperties the build meta data properties.
scmControl the properties to control the gathering of SCM info.
Throws:
com.redhat.rcm.maven.plugin.buildmetadata.scm.ScmException if the creation of the SCM information failed.
  public void provideScmBuildInfo(final Properties buildMetaDataProperties,
      final ScmControl scmControlthrows ScmException
  {
    final boolean failOnMissingRevision = scmControl.isFailOnMissingRevision();
    final RevisionNumberFetcher revisionFetcher =
            );
    final Revision revision = revisionFetcher.fetchLatestRevisionNumber();
    if (revision != null)
    {
      buildMetaDataProperties.setProperty(.,
          .getConnectionUrl());
      final String revisionId = revision.getId();
      buildMetaDataProperties.setProperty(.,
          revisionId);
      final Date revisionDate = revision.getDate();
      final DateFormat format =
          new SimpleDateFormat(.);
      final String revisionDateString = format.format(revisionDate);
      buildMetaDataProperties.setProperty(.,
          revisionDateString);
      final boolean validateCheckout = scmControl.isValidateCheckout();
      if (validateCheckout)
      {
        provideLocallyModifiedInfo(buildMetaDataPropertiesrevisionFetcher);
      }
    }
    else if (failOnMissingRevision)
    {
      throw new ScmNoRevisionException("Cannot fetch SCM revision. "
                                       + );
    }
  }
  // --- object basics --------------------------------------------------------

  
Provides the information of locally modified files to the build properties.

Parameters:
buildMetaDataProperties the build meta data properties.
revisionFetcher the fetcher to use.
Throws:
com.redhat.rcm.maven.plugin.buildmetadata.scm.ScmException if the creation of the modification information failed.
  private void provideLocallyModifiedInfo(
      final Properties buildMetaDataProperties,
      final RevisionNumberFetcher revisionFetcherthrows ScmException
  {
    try
    {
      final ScmFileSet fileSet =
          new ScmFileSet(.getRootDirectory(), "**/*"null);
      final LocallyModifiedInfo info =
          revisionFetcher.containsModifications(fileSet);
      buildMetaDataProperties.setProperty(
          String.valueOf(info.isLocallyModified()));
      if (info.isLocallyModified())
      {
        buildMetaDataProperties.setProperty(
            .info.getFiles());
        if (.isFailIndicated())
        {
          throw new ScmException("Local Modifications detected ("
                                 + info.getFiles() + ").");
        }
      }
    }
    catch (final Exception e)
    {
      if (.isFailIndicated())
      {
        throw new ScmException(e);
      }
      else
      {
        buildMetaDataProperties.setProperty(
            ."unknown");
        if (.isInfoEnabled())
        {
          .info("Failed to check modification status.");
        }
      }
    }
  }
New to GrepCode? Check out our FAQ X