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