001package org.apache.maven.scm.provider.bazaar.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
022import org.apache.maven.scm.ScmFileStatus;
023import org.apache.maven.scm.command.blame.BlameLine;
024import org.apache.maven.scm.log.ScmLogger;
025import org.apache.maven.scm.provider.bazaar.command.BazaarConsumer;
026
027import java.util.ArrayList;
028import java.util.Date;
029import java.util.List;
030
031/**
032 * @author Evgeny Mandrikov
033 * @author Olivier Lamy
034 * @since 1.4
035 */
036public class BazaarBlameConsumer
037    extends BazaarConsumer
038{
039    private static final String BAZAAR_TIMESTAMP_PATTERN = "yyyyMMdd";
040
041    private List<BlameLine> lines = new ArrayList<BlameLine>();
042
043    public BazaarBlameConsumer( ScmLogger logger )
044    {
045        super( logger );
046    }
047
048    public void doConsume( ScmFileStatus status, String trimmedLine )
049    {
050        /*1   godin@godin 20100131*/
051        String annotation = trimmedLine.substring( 0, trimmedLine.indexOf( '|' ) ).trim();
052
053        String dateStr = annotation.substring( annotation.lastIndexOf( ' ' ) + 1 );
054        annotation = annotation.substring( 0, annotation.lastIndexOf( ' ' ) );
055
056        String author = annotation.substring( annotation.lastIndexOf( ' ' ) + 1 );
057        annotation = annotation.substring( 0, annotation.lastIndexOf( ' ' ) );
058
059        String revision = annotation.trim();
060
061        Date date = parseDate( dateStr, null, BAZAAR_TIMESTAMP_PATTERN );
062
063        lines.add( new BlameLine( date, revision, author ) );
064    }
065
066    public List<BlameLine> getLines()
067    {
068        return lines;
069    }
070}