001package org.apache.maven.scm.provider.jazz.command.blame;
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.ScmException;
023import org.apache.maven.scm.ScmFileSet;
024import org.apache.maven.scm.command.blame.AbstractBlameCommand;
025import org.apache.maven.scm.command.blame.BlameScmResult;
026import org.apache.maven.scm.provider.ScmProviderRepository;
027import org.apache.maven.scm.provider.jazz.command.JazzConstants;
028import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
029import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
030
031// The Maven SCM plugin "blame" goal is equivalent to the RTC "annotate" command.
032//
033// See the following links for additional information on the RTC "annotate" command:
034// RTC 2.0.0.2:
035// http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_annotate.html
036// RTC 3.0:
037// http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_annotate.html
038// RTC 3.0.1:
039// http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_annotate.html
040//
041// The RTC "history" command also provides similar information that might be needed for the "blame" goal.
042// See the following links for additional information on the RTC "history" command:
043// RTC 2.0.0.2:
044// http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_history.html
045// RTC 3.0:
046// http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_history.html
047// RTC 3.0.1:
048// http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_history.html
049//
050
051/**
052 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
053 */
054public class JazzBlameCommand
055    extends AbstractBlameCommand
056{
057    /**
058     * {@inheritDoc}
059     */
060    public BlameScmResult executeBlameCommand( ScmProviderRepository repo, ScmFileSet fileSet, String filename )
061        throws ScmException
062    {
063        if ( getLogger().isDebugEnabled() )
064        {
065            getLogger().debug( "Executing blame command..." );
066        }
067
068        JazzScmCommand blameCmd = createBlameCommand( repo, fileSet, filename );
069
070        JazzBlameConsumer blameConsumer = new JazzBlameConsumer( repo, getLogger() );
071        ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
072
073        int status = blameCmd.execute( blameConsumer, errConsumer );
074        if ( status != 0 || errConsumer.hasBeenFed() )
075        {
076            return new BlameScmResult( blameCmd.getCommandString(), "Error code for Jazz SCM blame command - " + status,
077                                       errConsumer.getOutput(), false );
078        }
079
080        return new BlameScmResult( blameCmd.getCommandString(), blameConsumer.getLines() );
081    }
082
083    public JazzScmCommand createBlameCommand( ScmProviderRepository repo, ScmFileSet fileSet, String filename )
084    {
085        JazzScmCommand command =
086            new JazzScmCommand( JazzConstants.CMD_ANNOTATE, null, repo, false, fileSet, getLogger() );
087        command.addArgument( filename );
088
089        return command;
090    }
091
092}