001package org.apache.maven.scm.provider.jazz.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.command.blame.BlameLine; 023import org.apache.maven.scm.log.ScmLogger; 024import org.apache.maven.scm.provider.ScmProviderRepository; 025import org.apache.maven.scm.provider.jazz.command.consumer.AbstractRepositoryConsumer; 026 027import java.text.SimpleDateFormat; 028import java.util.ArrayList; 029import java.util.Date; 030import java.util.List; 031import java.util.TimeZone; 032import java.util.regex.Matcher; 033import java.util.regex.Pattern; 034 035//STATUS: NOT DONE 036 037/** 038 * Consume the output of the scm command for the "blame" operation. 039 * 040 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a> 041 */ 042public class JazzBlameConsumer 043 extends AbstractRepositoryConsumer 044{ 045 private static final String JAZZ_TIMESTAMP_PATTERN = "yyyy-MM-dd"; 046 047// 1 Deb (1008) 2011-12-14 Test.txt 048// 2 Deb (1005) 2011-12-14 59 My commit comment. 049 050 private static final Pattern LINE_PATTERN = Pattern.compile( "(\\d+) (.*) \\((\\d+)\\) (\\d+-\\d+-\\d+) (.*)" ); 051 052 private List<BlameLine> fLines = new ArrayList<BlameLine>(); 053 054 private SimpleDateFormat dateFormat; 055 056 /** 057 * Construct the JazzBlameCommand consumer. 058 * 059 * @param repository The repository we are working with. 060 * @param logger The logger to use. 061 */ 062 public JazzBlameConsumer( ScmProviderRepository repository, ScmLogger logger ) 063 { 064 super( repository, logger ); 065 066 dateFormat = new SimpleDateFormat( JAZZ_TIMESTAMP_PATTERN ); 067 dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); 068 } 069 070 /** 071 * Process one line of output from the execution of the "scm annotate" command. 072 * 073 * @param line The line of output from the external command that has been pumped to us. 074 * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String) 075 */ 076 public void consumeLine( String line ) 077 { 078 super.consumeLine( line ); 079 080 Matcher matcher = LINE_PATTERN.matcher( line ); 081 if ( matcher.matches() ) 082 { 083 String lineNumberStr = matcher.group( 1 ); 084 String owner = matcher.group( 2 ); 085 String changeSetNumberStr = matcher.group( 3 ); 086 String dateStr = matcher.group( 4 ); 087 Date date = parseDate( dateStr, JAZZ_TIMESTAMP_PATTERN, null ); 088 fLines.add( new BlameLine( date, changeSetNumberStr, owner ) ); 089 } 090 } 091 092 public List<BlameLine> getLines() 093 { 094 return fLines; 095 } 096}