Coverage Report - org.apache.maven.scm.provider.perforce.command.blame.PerforceFilelogConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
PerforceFilelogConsumer
93 %
14/15
100 %
2/2
1,25
 
 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  1
     private Map<String, Date> dates = new HashMap<String,Date>();
 44  
 
 45  1
     private Map<String,String> authors = new HashMap<String,String>();
 46  
 
 47  
     public PerforceFilelogConsumer( ScmLogger logger )
 48  
     {
 49  1
         super( logger );
 50  1
         lineRegexp = new RE( LINE_PATTERN );
 51  1
     }
 52  
 
 53  
     /** {@inheritDoc} */
 54  
     public void consumeLine( String line )
 55  
     {
 56  4
         if ( lineRegexp.match( line ) )
 57  
         {
 58  3
             String revision = lineRegexp.getParen( 1 );
 59  3
             String dateTimeStr = lineRegexp.getParen( 2 );
 60  3
             String author = lineRegexp.getParen( 3 );
 61  
 
 62  3
             Date dateTime = parseDate( dateTimeStr, null, PERFORCE_TIMESTAMP_PATTERN );
 63  
 
 64  3
             dates.put( revision, dateTime );
 65  3
             authors.put( revision, author );
 66  
         }
 67  4
     }
 68  
 
 69  
     public String getAuthor( String revision )
 70  
     {
 71  2
         return (String) authors.get( revision );
 72  
     }
 73  
 
 74  
     public Date getDate( String revision )
 75  
     {
 76  0
         return (Date) dates.get( revision );
 77  
     }
 78  
 }