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  
50          super( logger );
51      }
52  
53      @Override
54      protected BlameScmResult executeAccurevCommand( AccuRevScmProviderRepository repository, ScmFileSet fileSet,
55                                                      CommandParameters parameters )
56          throws ScmException, AccuRevException
57      {
58  
59          AccuRev accuRev = repository.getAccuRev();
60  
61          File file = new File( parameters.getString( CommandParameter.FILE ) );
62  
63          List<BlameLine> lines = accuRev.annotate( fileSet.getBasedir(), file );
64  
65          if ( lines != null )
66          {
67              return new BlameScmResult( accuRev.getCommandLines(), lines );
68          }
69          else
70          {
71              return new BlameScmResult( accuRev.getCommandLines(), "AccuRev Error", accuRev.getErrorOutput(), false );
72          }
73  
74      }
75  
76      public BlameScmResult blame( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
77          throws ScmException
78      {
79  
80          return (BlameScmResult) execute( repository, fileSet, parameters );
81      }
82  }