View Javadoc

1   package org.apache.maven.scm.provider.tfs.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.command.blame.BlameLine;
23  import org.apache.maven.scm.log.ScmLogger;
24  import org.apache.maven.scm.util.AbstractConsumer;
25  import org.apache.regexp.RE;
26  
27  import java.util.ArrayList;
28  import java.util.Date;
29  import java.util.List;
30  
31  /**
32   * @author Evgeny Mandrikov
33   * @since 1.4
34   */
35  public class TfsBlameConsumer
36      extends AbstractConsumer
37  {
38      private static final String TFS_TIMESTAMP_PATTERN = "MM/dd/yyyy";
39  
40      /* 3 username 3/13/2006 line */
41      // TODO simplify
42  
43      private static final String LINE_PATTERN = "([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)";
44  
45      /**
46       * @see #LINE_PATTERN
47       */
48      private RE lineRegexp;
49  
50      private List<BlameLine> lines = new ArrayList<BlameLine>();
51  
52      public TfsBlameConsumer( ScmLogger logger )
53      {
54          super( logger );
55          lineRegexp = new RE( LINE_PATTERN );
56      }
57  
58      public void consumeLine( String line )
59      {
60          if ( lineRegexp.match( line ) )
61          {
62              String revision = lineRegexp.getParen( 1 ).trim();
63              String author = lineRegexp.getParen( 2 ).trim();
64              String dateStr = lineRegexp.getParen( 3 ).trim();
65  
66              Date date = parseDate( dateStr, null, TFS_TIMESTAMP_PATTERN );
67  
68              lines.add( new BlameLine( date, revision, author ) );
69          }
70      }
71  
72      public List<BlameLine> getLines()
73      {
74          return lines;
75      }
76  }