001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.provider.hg.command.blame; 020 021import java.util.ArrayList; 022import java.util.Date; 023import java.util.List; 024import java.util.Locale; 025 026import org.apache.maven.scm.ScmFileStatus; 027import org.apache.maven.scm.command.blame.BlameLine; 028import org.apache.maven.scm.provider.hg.command.HgConsumer; 029 030/** 031 * @author Evgeny Mandrikov 032 * @author Olivier Lamy 033 * @since 1.4 034 */ 035public class HgBlameConsumer extends HgConsumer { 036 private final List<BlameLine> lines = new ArrayList<>(); 037 038 private static final String HG_TIMESTAMP_PATTERN = "EEE MMM dd HH:mm:ss yyyy Z"; 039 040 public void doConsume(ScmFileStatus status, String trimmedLine) { 041 /* godin 0 Sun Jan 31 03:04:54 2010 +0300 */ 042 String annotation; 043 if (trimmedLine.indexOf(": ") > -1) { 044 annotation = trimmedLine.substring(0, trimmedLine.indexOf(": ")).trim(); 045 } else { 046 annotation = trimmedLine.substring(0, trimmedLine.lastIndexOf(":")).trim(); 047 } 048 049 String author = annotation.substring(0, annotation.indexOf(' ')); 050 annotation = annotation.substring(annotation.indexOf(' ') + 1).trim(); 051 052 String revision = annotation.substring(0, annotation.indexOf(' ')); 053 annotation = annotation.substring(annotation.indexOf(' ') + 1).trim(); 054 055 String dateStr = annotation; 056 Date dateTime = parseDate(dateStr, null, HG_TIMESTAMP_PATTERN, Locale.ENGLISH); 057 058 lines.add(new BlameLine(dateTime, revision, author)); 059 } 060 061 public List<BlameLine> getLines() { 062 return lines; 063 } 064}