001 package org.apache.maven.scm.provider.hg.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 org.apache.maven.scm.ScmFileStatus;
023 import org.apache.maven.scm.command.blame.BlameLine;
024 import org.apache.maven.scm.log.ScmLogger;
025 import org.apache.maven.scm.provider.hg.command.HgConsumer;
026
027 import java.util.ArrayList;
028 import java.util.Date;
029 import java.util.List;
030 import java.util.Locale;
031
032
033 /**
034 * @author Evgeny Mandrikov
035 * @author Olivier Lamy
036 * @since 1.4
037 */
038 public class HgBlameConsumer
039 extends HgConsumer
040 {
041 private List<BlameLine> lines = new ArrayList<BlameLine>();
042
043 private static final String HG_TIMESTAMP_PATTERN = "EEE MMM dd HH:mm:ss yyyy Z";
044
045 public HgBlameConsumer( ScmLogger logger )
046 {
047 super( logger );
048
049 }
050
051 public void doConsume( ScmFileStatus status, String trimmedLine )
052 {
053 /* godin 0 Sun Jan 31 03:04:54 2010 +0300 */
054 String annotation;
055 if ( trimmedLine.indexOf( ": " ) > -1 )
056 {
057 annotation = trimmedLine.substring( 0, trimmedLine.indexOf( ": " ) ).trim();
058 }
059 else
060 {
061 annotation = trimmedLine.substring( 0, trimmedLine.lastIndexOf( ":" ) ).trim();
062 }
063
064 String author = annotation.substring( 0, annotation.indexOf( ' ' ) );
065 annotation = annotation.substring( annotation.indexOf( ' ' ) + 1 ).trim();
066
067 String revision = annotation.substring( 0, annotation.indexOf( ' ' ) );
068 annotation = annotation.substring( annotation.indexOf( ' ' ) + 1 ).trim();
069
070 String dateStr = annotation;
071 Date dateTime = parseDate( dateStr, null, HG_TIMESTAMP_PATTERN, Locale.ENGLISH );
072
073 lines.add( new BlameLine( dateTime, revision, author ) );
074 }
075
076 public List<BlameLine> getLines()
077 {
078 return lines;
079 }
080 }