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 * @version $Id: IntegrityLoginCommand.java 1.2 2011/08/22 13:06:33EDT Cletus D'Souza (dsouza) Exp $ 046 * @since 1.6 047 */ 048public class IntegrityLoginCommand 049 extends AbstractLoginCommand 050{ 051 /** 052 * {@inheritDoc} 053 */ 054 @Override 055 public LoginScmResult executeLoginCommand( ScmProviderRepository repository, ScmFileSet fileSet, 056 CommandParameters params ) 057 throws ScmException 058 { 059 getLogger().info( "Attempting to connect with the MKS Integrity Server" ); 060 LoginScmResult result; 061 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository; 062 APISession api = iRepo.getAPISession(); 063 try 064 { 065 // First we will establish a connection to the MKS Integrity Server 066 Response res = api.connect( iRepo.getHost(), iRepo.getPort(), iRepo.getUser(), iRepo.getPassword() ); 067 int exitCode = res.getExitCode(); 068 boolean success = ( exitCode == 0 ? true : false ); 069 result = new LoginScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success ); 070 071 // Next we will prepare the Project and Sandbox for the other commands 072 Project siProject = new Project( api, iRepo.getConfigruationPath() ); 073 Sandbox siSandbox = new Sandbox( api, siProject, fileSet.getBasedir().getAbsolutePath() ); 074 iRepo.setProject( siProject ); 075 iRepo.setSandbox( siSandbox ); 076 } 077 catch ( APIException aex ) 078 { 079 ExceptionHandler eh = new ExceptionHandler( aex ); 080 getLogger().error( "MKS API Exception: " + eh.getMessage() ); 081 getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() ); 082 result = new LoginScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false ); 083 } 084 085 return result; 086 } 087 088}