View Javadoc
1   package org.apache.maven.scm.provider.accurev.cli;
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 java.util.Date;
23  import java.util.List;
24  import java.util.regex.Matcher;
25  import java.util.regex.Pattern;
26  
27  import org.apache.maven.scm.command.blame.BlameLine;
28  import org.apache.maven.scm.log.ScmLogger;
29  import org.apache.maven.scm.provider.accurev.AccuRev;
30  import org.apache.maven.scm.util.AbstractConsumer;
31  
32  /**
33   * @author Evgeny Mandrikov
34   * @author Grant Gardner
35   * @since 1.4
36   */
37  public class AnnotateConsumer
38      extends AbstractConsumer
39  {
40  
41      /* 3 godin 2009/11/18 16:26:33 */
42      private static final Pattern LINE_PATTERN = Pattern.compile( "^\\s+(\\d+)\\s+(\\w+)\\s+([0-9/]+ [0-9:]+).*" );
43  
44      private List<BlameLine> lines;
45  
46      public AnnotateConsumer( List<BlameLine> lines, ScmLogger scmLogger )
47      {
48  
49          super( scmLogger );
50          this.lines = lines;
51      }
52  
53      public void consumeLine( String line )
54      {
55  
56          final Matcher matcher = LINE_PATTERN.matcher( line );
57          if ( matcher.matches() )
58          {
59              String revision = matcher.group( 1 ).trim();
60              String author = matcher.group( 2 ).trim();
61              String dateStr = matcher.group( 3 ).trim();
62  
63              Date date = parseDate( dateStr, null, AccuRev.ACCUREV_TIME_FORMAT_STRING );
64  
65              lines.add( new BlameLine( date, revision, author ) );
66          }
67          else
68          {
69              throw new RuntimeException( "Unable to parse annotation from line: " + line );
70          }
71      }
72  
73      public List<BlameLine> getLines()
74      {
75  
76          return lines;
77      }
78  }