001 package org.apache.maven.scm.provider.accurev.cli;
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.Date;
023 import java.util.List;
024 import java.util.regex.Matcher;
025 import java.util.regex.Pattern;
026
027 import org.apache.maven.scm.command.blame.BlameLine;
028 import org.apache.maven.scm.log.ScmLogger;
029 import org.apache.maven.scm.provider.accurev.AccuRev;
030 import org.apache.maven.scm.util.AbstractConsumer;
031
032 /**
033 * @author Evgeny Mandrikov
034 * @author Grant Gardner
035 * @since 1.4
036 */
037 public class AnnotateConsumer
038 extends AbstractConsumer
039 {
040
041 /* 3 godin 2009/11/18 16:26:33 */
042 private static final Pattern LINE_PATTERN = Pattern.compile( "^\\s+(\\d+)\\s+(\\w+)\\s+([0-9/]+ [0-9:]+).*" );
043
044 private List<BlameLine> lines;
045
046 public AnnotateConsumer( List<BlameLine> lines, ScmLogger scmLogger )
047 {
048
049 super( scmLogger );
050 this.lines = lines;
051 }
052
053 public void consumeLine( String line )
054 {
055
056 final Matcher matcher = LINE_PATTERN.matcher( line );
057 if ( matcher.matches() )
058 {
059 String revision = matcher.group( 1 ).trim();
060 String author = matcher.group( 2 ).trim();
061 String dateStr = matcher.group( 3 ).trim();
062
063 Date date = parseDate( dateStr, null, AccuRev.ACCUREV_TIME_FORMAT_STRING );
064
065 lines.add( new BlameLine( date, revision, author ) );
066 }
067 else
068 {
069 throw new RuntimeException( "Unable to parse annotation from line: " + line );
070 }
071 }
072
073 public List<BlameLine> getLines()
074 {
075
076 return lines;
077 }
078 }