View Javadoc

1   package org.apache.maven.scm.provider.jazz.command.blame;
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 org.apache.maven.scm.ScmException;
23  import org.apache.maven.scm.ScmFileSet;
24  import org.apache.maven.scm.command.blame.AbstractBlameCommand;
25  import org.apache.maven.scm.command.blame.BlameScmResult;
26  import org.apache.maven.scm.provider.ScmProviderRepository;
27  import org.apache.maven.scm.provider.jazz.command.JazzConstants;
28  import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
29  import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
30  
31  // The Maven SCM plugin "blame" goal is equivalent to the RTC "annotate" command.
32  //
33  // See the following links for additional information on the RTC "annotate" command:
34  // RTC 2.0.0.2:
35  // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_annotate.html
36  // RTC 3.0:
37  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_annotate.html
38  // RTC 3.0.1:
39  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_annotate.html
40  //
41  // The RTC "history" command also provides similar information that might be needed for the "blame" goal.
42  // See the following links for additional information on the RTC "history" command:
43  // RTC 2.0.0.2:
44  // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_history.html
45  // RTC 3.0:
46  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_history.html
47  // RTC 3.0.1:
48  // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_history.html
49  //
50  
51  /**
52   * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
53   */
54  public class JazzBlameCommand
55      extends AbstractBlameCommand
56  {
57      /**
58       * {@inheritDoc}
59       */
60      public BlameScmResult executeBlameCommand( ScmProviderRepository repo, ScmFileSet fileSet, String filename )
61          throws ScmException
62      {
63          if ( getLogger().isDebugEnabled() )
64          {
65              getLogger().debug( "Executing blame command..." );
66          }
67  
68          JazzScmCommand blameCmd = createBlameCommand( repo, fileSet, filename );
69  
70          JazzBlameConsumer blameConsumer = new JazzBlameConsumer( repo, getLogger() );
71          ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
72  
73          int status = blameCmd.execute( blameConsumer, errConsumer );
74          if ( status != 0 || errConsumer.hasBeenFed() )
75          {
76              return new BlameScmResult( blameCmd.getCommandString(), "Error code for Jazz SCM blame command - " + status,
77                                         errConsumer.getOutput(), false );
78          }
79  
80          return new BlameScmResult( blameCmd.getCommandString(), blameConsumer.getLines() );
81      }
82  
83      public JazzScmCommand createBlameCommand( ScmProviderRepository repo, ScmFileSet fileSet, String filename )
84      {
85          JazzScmCommand command =
86              new JazzScmCommand( JazzConstants.CMD_ANNOTATE, null, repo, false, fileSet, getLogger() );
87          command.addArgument( filename );
88  
89          return command;
90      }
91  
92  }