001 package org.apache.maven.scm.provider.cvslib.command.blame; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import java.util.ArrayList; 023 import java.util.Date; 024 import java.util.List; 025 import java.util.Locale; 026 027 import org.apache.maven.scm.command.blame.BlameLine; 028 import org.apache.maven.scm.log.ScmLogger; 029 import org.apache.maven.scm.util.AbstractConsumer; 030 import org.apache.regexp.RE; 031 032 /** 033 * @author Evgeny Mandrikov 034 * @author Olivier Lamy 035 * @since 1.4 036 */ 037 public class CvsBlameConsumer 038 extends AbstractConsumer 039 { 040 private static final String CVS_TIMESTAMP_PATTERN = "dd-MMM-yy"; 041 042 /* 1.1 (tor 24-Mar-03): */ 043 044 private static final String LINE_PATTERN = "(.*)\\((.*)\\s+(.*)\\)"; 045 046 /** 047 * @see #LINE_PATTERN 048 */ 049 private RE lineRegexp; 050 051 private List<BlameLine> lines = new ArrayList<BlameLine>(); 052 053 public CvsBlameConsumer( ScmLogger logger ) 054 { 055 super( logger ); 056 057 lineRegexp = new RE( LINE_PATTERN ); 058 } 059 060 public void consumeLine( String line ) 061 { 062 if (line != null && line.indexOf( ':' ) > 0 ) 063 { 064 String annotation = line.substring( 0, line.indexOf( ':' ) ); 065 if ( lineRegexp.match( annotation ) ) 066 { 067 String revision = lineRegexp.getParen( 1 ).trim(); 068 String author = lineRegexp.getParen( 2 ).trim(); 069 String dateTimeStr = lineRegexp.getParen( 3 ).trim(); 070 071 Date dateTime = parseDate( dateTimeStr, null, CVS_TIMESTAMP_PATTERN, Locale.US ); 072 lines.add( new BlameLine( dateTime, revision, author ) ); 073 074 if ( getLogger().isDebugEnabled() ) 075 { 076 getLogger().debug( author + " " + dateTimeStr ); 077 } 078 } 079 } 080 } 081 082 public List<BlameLine> getLines() 083 { 084 return lines; 085 } 086 087 }