001package org.apache.maven.scm.provider.integrity.command.login; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import com.mks.api.response.APIException; 023import com.mks.api.response.Response; 024import org.apache.maven.scm.CommandParameters; 025import org.apache.maven.scm.ScmException; 026import org.apache.maven.scm.ScmFileSet; 027import org.apache.maven.scm.command.login.AbstractLoginCommand; 028import org.apache.maven.scm.command.login.LoginScmResult; 029import org.apache.maven.scm.provider.ScmProviderRepository; 030import org.apache.maven.scm.provider.integrity.APISession; 031import org.apache.maven.scm.provider.integrity.ExceptionHandler; 032import org.apache.maven.scm.provider.integrity.Project; 033import org.apache.maven.scm.provider.integrity.Sandbox; 034import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository; 035 036/** 037 * MKS Integrity implementation of Maven's AbstractLoginCommand 038 * <br>This command will execute a 'si login' followed by a 'si viewproject' 039 * to prepare the subsequent commands that will be executed for a maven goal. 040 * <br>The login command uses a Local Client API Integration Point and hence the 041 * <br>MKS Integrity Client is required to be installed on the local client as a 042 * pre-requisite. 043 * 044 * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a> 045 * @since 1.6 046 */ 047public class IntegrityLoginCommand 048 extends AbstractLoginCommand 049{ 050 /** 051 * {@inheritDoc} 052 */ 053 @Override 054 public LoginScmResult executeLoginCommand( ScmProviderRepository repository, ScmFileSet fileSet, 055 CommandParameters params ) 056 throws ScmException 057 { 058 getLogger().info( "Attempting to connect with the MKS Integrity Server" ); 059 LoginScmResult result; 060 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository; 061 APISession api = iRepo.getAPISession(); 062 try 063 { 064 // First we will establish a connection to the MKS Integrity Server 065 Response res = api.connect( iRepo.getHost(), iRepo.getPort(), iRepo.getUser(), iRepo.getPassword() ); 066 int exitCode = res.getExitCode(); 067 boolean success = ( exitCode == 0 ? true : false ); 068 result = new LoginScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success ); 069 070 // Next we will prepare the Project and Sandbox for the other commands 071 Project siProject = new Project( api, iRepo.getConfigruationPath() ); 072 Sandbox siSandbox = new Sandbox( api, siProject, fileSet.getBasedir().getAbsolutePath() ); 073 iRepo.setProject( siProject ); 074 iRepo.setSandbox( siSandbox ); 075 } 076 catch ( APIException aex ) 077 { 078 ExceptionHandler eh = new ExceptionHandler( aex ); 079 getLogger().error( "MKS API Exception: " + eh.getMessage() ); 080 getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() ); 081 result = new LoginScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false ); 082 } 083 084 return result; 085 } 086 087}