View Javadoc
1   package org.apache.maven.scm.provider.integrity.command.login;
2   
3   /**
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import com.mks.api.response.APIException;
23  import com.mks.api.response.Response;
24  import org.apache.maven.scm.CommandParameters;
25  import org.apache.maven.scm.ScmException;
26  import org.apache.maven.scm.ScmFileSet;
27  import org.apache.maven.scm.command.login.AbstractLoginCommand;
28  import org.apache.maven.scm.command.login.LoginScmResult;
29  import org.apache.maven.scm.provider.ScmProviderRepository;
30  import org.apache.maven.scm.provider.integrity.APISession;
31  import org.apache.maven.scm.provider.integrity.ExceptionHandler;
32  import org.apache.maven.scm.provider.integrity.Project;
33  import org.apache.maven.scm.provider.integrity.Sandbox;
34  import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
35  
36  /**
37   * MKS Integrity implementation of Maven's AbstractLoginCommand
38   * <br>This command will execute a 'si login' followed by a 'si viewproject'
39   * to prepare the subsequent commands that will be executed for a maven goal.
40   * <br>The login command uses a Local Client API Integration Point and hence the
41   * <br>MKS Integrity Client is required to be installed on the local client as a
42   * pre-requisite.
43   *
44   * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
45   * @version $Id: IntegrityLoginCommand.java 1.2 2011/08/22 13:06:33EDT Cletus D'Souza (dsouza) Exp  $
46   * @since 1.6
47   */
48  public class IntegrityLoginCommand
49      extends AbstractLoginCommand
50  {
51      /**
52       * {@inheritDoc}
53       */
54      @Override
55      public LoginScmResult executeLoginCommand( ScmProviderRepository repository, ScmFileSet fileSet,
56                                                 CommandParameters params )
57          throws ScmException
58      {
59          getLogger().info( "Attempting to connect with the MKS Integrity Server" );
60          LoginScmResult result;
61          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
62          APISession api = iRepo.getAPISession();
63          try
64          {
65              // First we will establish a connection to the MKS Integrity Server
66              Response res = api.connect( iRepo.getHost(), iRepo.getPort(), iRepo.getUser(), iRepo.getPassword() );
67              int exitCode = res.getExitCode();
68              boolean success = ( exitCode == 0 ? true : false );
69              result = new LoginScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success );
70  
71              // Next we will prepare the Project and Sandbox for the other commands
72              Project siProject = new Project( api, iRepo.getConfigruationPath() );
73              Sandbox siSandbox = new Sandbox( api, siProject, fileSet.getBasedir().getAbsolutePath() );
74              iRepo.setProject( siProject );
75              iRepo.setSandbox( siSandbox );
76          }
77          catch ( APIException aex )
78          {
79              ExceptionHandler eh = new ExceptionHandler( aex );
80              getLogger().error( "MKS API Exception: " + eh.getMessage() );
81              getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
82              result = new LoginScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
83          }
84  
85          return result;
86      }
87  
88  }