View Javadoc

1   package org.apache.maven.scm.provider.perforce.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.log.ScmLogger;
23  import org.apache.maven.scm.util.AbstractConsumer;
24  import org.apache.regexp.RE;
25  
26  import java.util.Date;
27  import java.util.HashMap;
28  import java.util.Map;
29  
30  /**
31   * @author Evgeny Mandrikov
32   * @since 1.4
33   */
34  public class PerforceFilelogConsumer
35      extends AbstractConsumer
36  {
37      private static final String PERFORCE_TIMESTAMP_PATTERN = "yyyy/MM/dd";
38  
39      private static final String LINE_PATTERN = "#(\\d+).*on (.*) by (.*)@";
40  
41      private RE lineRegexp;
42  
43      private Map<String, Date> dates = new HashMap<String,Date>();
44  
45      private Map<String,String> authors = new HashMap<String,String>();
46  
47      public PerforceFilelogConsumer( ScmLogger logger )
48      {
49          super( logger );
50          lineRegexp = new RE( LINE_PATTERN );
51      }
52  
53      /** {@inheritDoc} */
54      public void consumeLine( String line )
55      {
56          if ( lineRegexp.match( line ) )
57          {
58              String revision = lineRegexp.getParen( 1 );
59              String dateTimeStr = lineRegexp.getParen( 2 );
60              String author = lineRegexp.getParen( 3 );
61  
62              Date dateTime = parseDate( dateTimeStr, null, PERFORCE_TIMESTAMP_PATTERN );
63  
64              dates.put( revision, dateTime );
65              authors.put( revision, author );
66          }
67      }
68  
69      public String getAuthor( String revision )
70      {
71          return (String) authors.get( revision );
72      }
73  
74      public Date getDate( String revision )
75      {
76          return (Date) dates.get( revision );
77      }
78  }