View Javadoc
1   package org.apache.maven.scm.provider.accurev.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.CommandParameter;
23  import org.apache.maven.scm.CommandParameters;
24  import org.apache.maven.scm.ScmException;
25  import org.apache.maven.scm.ScmFileSet;
26  import org.apache.maven.scm.command.blame.BlameLine;
27  import org.apache.maven.scm.command.blame.BlameScmResult;
28  import org.apache.maven.scm.log.ScmLogger;
29  import org.apache.maven.scm.provider.ScmProviderRepository;
30  import org.apache.maven.scm.provider.accurev.AccuRev;
31  import org.apache.maven.scm.provider.accurev.AccuRevException;
32  import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository;
33  import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommand;
34  
35  import java.io.File;
36  import java.util.List;
37  
38  /**
39   * @author Evgeny Mandrikov
40   * @author Grant Gardner
41   * @since 1.4
42   */
43  public class AccuRevBlameCommand
44      extends AbstractAccuRevCommand
45  {
46  
47      public AccuRevBlameCommand( ScmLogger logger )
48      {
49          super( logger );
50      }
51  
52      @Override
53      protected BlameScmResult executeAccurevCommand( AccuRevScmProviderRepository repository, ScmFileSet fileSet,
54                                                      CommandParameters parameters )
55          throws ScmException, AccuRevException
56      {
57  
58          AccuRev accuRev = repository.getAccuRev();
59  
60          File file = new File( parameters.getString( CommandParameter.FILE ) );
61  
62          List<BlameLine> lines = accuRev.annotate( fileSet.getBasedir(), file );
63  
64          if ( lines != null )
65          {
66              return new BlameScmResult( accuRev.getCommandLines(), lines );
67          }
68          else
69          {
70              return new BlameScmResult( accuRev.getCommandLines(), "AccuRev Error", accuRev.getErrorOutput(), false );
71          }
72  
73      }
74  
75      public BlameScmResult blame( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
76          throws ScmException
77      {
78          return (BlameScmResult) execute( repository, fileSet, parameters );
79      }
80  }