View Javadoc
1   package org.apache.maven.scm.provider.hg.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.ScmFileStatus;
23  import org.apache.maven.scm.command.blame.BlameLine;
24  import org.apache.maven.scm.log.ScmLogger;
25  import org.apache.maven.scm.provider.hg.command.HgConsumer;
26  
27  import java.util.ArrayList;
28  import java.util.Date;
29  import java.util.List;
30  import java.util.Locale;
31  
32  
33  /**
34   * @author Evgeny Mandrikov
35   * @author Olivier Lamy
36   * @since 1.4
37   */
38  public class HgBlameConsumer
39      extends HgConsumer
40  {
41      private List<BlameLine> lines = new ArrayList<BlameLine>();
42  
43      private static final String HG_TIMESTAMP_PATTERN = "EEE MMM dd HH:mm:ss yyyy Z";
44  
45      public HgBlameConsumer( ScmLogger logger )
46      {
47          super( logger );
48  
49      }
50  
51      public void doConsume( ScmFileStatus status, String trimmedLine )
52      {
53          /* godin 0 Sun Jan 31 03:04:54 2010 +0300 */
54          String annotation;
55          if ( trimmedLine.indexOf( ": " ) > -1 )
56          {
57              annotation = trimmedLine.substring( 0, trimmedLine.indexOf( ": " ) ).trim();
58          }
59          else
60          {
61              annotation = trimmedLine.substring( 0, trimmedLine.lastIndexOf( ":" ) ).trim();
62          }
63  
64          String author = annotation.substring( 0, annotation.indexOf( ' ' ) );
65          annotation = annotation.substring( annotation.indexOf( ' ' ) + 1 ).trim();
66  
67          String revision = annotation.substring( 0, annotation.indexOf( ' ' ) );
68          annotation = annotation.substring( annotation.indexOf( ' ' ) + 1 ).trim();
69  
70          String dateStr = annotation;
71          Date dateTime = parseDate( dateStr, null, HG_TIMESTAMP_PATTERN, Locale.ENGLISH );
72  
73          lines.add( new BlameLine( dateTime, revision, author ) );
74      }
75  
76      public List<BlameLine> getLines()
77      {
78          return lines;
79      }
80  }