001package org.apache.maven.scm.provider.integrity.command.fileinfo; 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 org.apache.maven.scm.CommandParameter; 023import org.apache.maven.scm.CommandParameters; 024import org.apache.maven.scm.ScmException; 025import org.apache.maven.scm.ScmFileSet; 026import org.apache.maven.scm.ScmResult; 027import org.apache.maven.scm.command.fileinfo.AbstractFileInfoCommand; 028import org.apache.maven.scm.provider.ScmProviderRepository; 029import org.apache.maven.scm.provider.integrity.APISession; 030import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository; 031import org.codehaus.plexus.util.cli.CommandLineException; 032import org.codehaus.plexus.util.cli.CommandLineUtils; 033import org.codehaus.plexus.util.cli.Commandline; 034 035import java.io.File; 036 037/** 038 * MKS Integrity implementation for Maven's AbstractFileInfoCommand 039 * <br>This command will run a 'si memberinfo' command. Even though this 040 * command is supported via the API, we're using the CLI to execute as 041 * its not clear what exactly this command is supposed to be returning 042 * to the Maven SCM framework. Hence the CLI output is returned to the 043 * console verbatim 044 * 045 * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a> 046 * @since 1.6 047 */ 048public class IntegrityFileInfoCommand 049 extends AbstractFileInfoCommand 050{ 051 /** 052 * Even though this command is supported via the MKS JAVA API, since at this time we really don't 053 * know what the SCM plugin is looking to get in return for this command, we're simply going to 054 * run this command via the CLI and return the output verbatim 055 */ 056 @Override 057 public ScmResult executeFileInfoCommand( ScmProviderRepository repository, File workingDirectory, String filename ) 058 throws ScmException 059 { 060 getLogger().info( "Attempting to display scm file information for file: " + filename ); 061 if ( null == filename || filename.length() == 0 ) 062 { 063 throw new ScmException( "A single filename is required to execute the fileinfo command!" ); 064 } 065 ScmResult result; 066 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository; 067 APISession api = iRepo.getAPISession(); 068 Commandline shell = new Commandline(); 069 shell.setWorkingDirectory( workingDirectory ); 070 shell.setExecutable( "si" ); 071 shell.createArg().setValue( "memberinfo" ); 072 shell.createArg().setValue( "--hostname=" + api.getHostName() ); 073 shell.createArg().setValue( "--port=" + api.getPort() ); 074 shell.createArg().setValue( "--user=" + api.getUserName() ); 075 shell.createArg().setValue( '"' + filename + '"' ); 076 IntegrityFileInfoConsumer shellConsumer = new IntegrityFileInfoConsumer( getLogger() ); 077 String commandLine = CommandLineUtils.toString( shell.getCommandline() ); 078 079 try 080 { 081 getLogger().debug( "Executing: " + commandLine ); 082 int exitCode = CommandLineUtils.executeCommandLine( shell, shellConsumer, 083 new CommandLineUtils.StringStreamConsumer() ); 084 boolean success = ( exitCode == 128 ? false : true ); 085 result = new ScmResult( commandLine, "", "Exit Code: " + exitCode, success ); 086 087 } 088 catch ( CommandLineException cle ) 089 { 090 getLogger().error( "Command Line Exception: " + cle.getMessage() ); 091 result = new ScmResult( commandLine, cle.getMessage(), "", false ); 092 } 093 094 return result; 095 } 096 097 /** 098 * {@inheritDoc} 099 */ 100 @Override 101 protected ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet, 102 CommandParameters parameters ) 103 throws ScmException 104 { 105 return executeFileInfoCommand( repository, fileSet.getBasedir(), 106 parameters.getString( CommandParameter.FILE ) ); 107 } 108 109}