Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2006-2014 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.data;
 
 
 
Extracts information from the Maven project, session, and runtime information.

Author(s):
Robert Reiner
Version:
$Revision:591 $
 
 {
   // ********************************* Fields *********************************
 
   // --- constants ------------------------------------------------------------
 
   // --- members --------------------------------------------------------------
 
   // ****************************** Initializer *******************************
 
   // ****************************** Constructors ******************************
 
  
Constructor.

Parameters:
project the Maven project.
scmInfo the value for scmInfo.
See also:
com.redhat.rcm.maven.plugin.buildmetadata.data.AbstractMetaDataProvider.AbstractMetaDataProvider.()
 
   public ScmMetaDataProvider(final MavenProject projectfinal ScmInfo scmInfo)
   {
     this. = project;
     this. = scmInfo;
   }
 
   // ****************************** Inner Classes *****************************
 
   // ********************************* Methods ********************************
 
   // --- init -----------------------------------------------------------------
 
   // --- get&set --------------------------------------------------------------
 
   // --- business -------------------------------------------------------------
 
  
Provides the SCM build information to the property sets if the URL to the SCM is provided.

Parameters:
buildMetaDataProperties the build meta data properties.
 
   public final void provideBuildMetaData(final Properties buildMetaDataProperties)
   {
     final ScmControl scmControl = .getScmControl();
     if (scmControl.isAddScmInfo() && !scmControl.isOffline()
         && .getScm() != null)
     {
       try
       {
         final ScmConnectionInfo scmConnectionInfo = loadConnectionInfo();
         final ScmAccessInfo scmAccessInfo = createScmAccessInfo();
         final RevisionHelper helper =
             new RevisionHelper(.getScmManager(), scmConnectionInfo,
                 scmAccessInfo.getBuildDatePattern());
         helper.provideScmBuildInfo(buildMetaDataPropertiesscmControl);
       }
      catch (final IllegalArgumentException e)
      {
        throw new ScmNoRevisionException(
 "Unable to determine SCM revision information."e );
      }
      catch (final ScmRepositoryException e)
      {
        throw new ScmNoRevisionException(
 "Unable to determine SCM revision information."e );
      }
      catch (final NoSuchScmProviderException e)
      {
        throw new ScmNoRevisionException(
 "Unable to determine SCM revision information."e );
      }
    }
    else
    {
      getLog().debug("Skipping SCM data since addScmInfo="
                + scmControl.isAddScmInfo() + ", offline="
                + scmControl.isOffline() + ", scmInfoProvided="
                + (.getScm() != null) + ".");
    }
  }

  
Load user name password from settings if user has not set them via JVM properties.

Returns:
the connection information to connect to the SCM system.
Throws:
java.lang.IllegalStateException if the connection string to the SCM cannot be fetched.
org.apache.maven.scm.repository.ScmRepositoryException if the repository information is not sufficient to build the repository instance.
org.apache.maven.scm.manager.NoSuchScmProviderException if there is no provider for the SCM connection URL.
  {
    final String scmConnection = getConnection();
    final ScmCredentials credentials = .getScmCrendentials();
    if (credentials.getUserName() == null || credentials.getPassword() == null)
    {
      final ScmRepository repository =
          .getScmManager().makeScmRepository(scmConnection);
      if (repository.getProviderRepository() instanceof ScmProviderRepositoryWithHost)
      {
        final ScmProviderRepositoryWithHost repositoryWithHost =
            (ScmProviderRepositoryWithHostrepository.getProviderRepository();
        final String host = createHostName(repositoryWithHost);
        credentials.configureByServer(host);
      }
    }
    final ScmConnectionInfo info = new ScmConnectionInfo();
    info.setUserName(credentials.getUserName());
    info.setPassword(credentials.getPassword());
    info.setPrivateKey(credentials.getPrivateKey());
    info.setScmConnectionUrl(scmConnection);
    return info;
  }

  
Delegates call to org.apache.maven.model.Scm.getConnection().

Returns:
the result of the call to org.apache.maven.model.Scm.getConnection().
Throws:
java.lang.IllegalStateException when there is insufficient information to return the SCM connection string.
See also:
org.apache.maven.model.Scm.getConnection()
  protected final String getConnection() throws IllegalStateException
  {
    if (.getScm() == null)
    {
      throw new IllegalStateException("SCM Connection is not set.");
    }
    final String scmConnection = .getScm().getConnection();
    final String connectionType = .getConnectionType();
    if (StringUtils.isNotEmpty(scmConnection)
        && "connection".equals(connectionType.toLowerCase(.)))
    {
      return scmConnection;
    }
    final String scmDeveloper = .getScm().getDeveloperConnection();
    if (StringUtils.isNotEmpty(scmDeveloper)
        && "developerconnection".equals(connectionType
            .toLowerCase(.)))
    {
      return scmDeveloper;
    }
    throw new IllegalStateException("SCM Connection is not set.");
  }

  
Creates the host name by adding the port if present.

Parameters:
repositoryWithHost the host information.
Returns:
the host with port if present.
  private String createHostName(
      final ScmProviderRepositoryWithHost repositoryWithHost)
  {
    final String host = repositoryWithHost.getHost();
    final int port = repositoryWithHost.getPort();
    if (port > 0)
    {
      return host + ":" + port;
    }
    return host;
  }

  
Creates the access information instance to retrieve the change logs from the SCM.

Returns:
the SCM access instance.
  {
    final ScmAccessInfo accessInfo = new ScmAccessInfo();
    accessInfo.setRootDirectory(.getBasedir());
        .isFailOnLocalModifications());
        .isIgnoreDotFilesInBaseDir());
    return accessInfo;
  }
  // --- object basics --------------------------------------------------------
New to GrepCode? Check out our FAQ X