1 package org.apache.maven.scm.provider.jazz.command.blame;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.maven.scm.command.blame.BlameLine;
23 import org.apache.maven.scm.log.ScmLogger;
24 import org.apache.maven.scm.provider.ScmProviderRepository;
25 import org.apache.maven.scm.provider.jazz.command.consumer.AbstractRepositoryConsumer;
26
27 import java.text.SimpleDateFormat;
28 import java.util.ArrayList;
29 import java.util.Date;
30 import java.util.List;
31 import java.util.TimeZone;
32 import java.util.regex.Matcher;
33 import java.util.regex.Pattern;
34
35 //STATUS: NOT DONE
36
37 /**
38 * Consume the output of the scm command for the "blame" operation.
39 *
40 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
41 */
42 public class JazzBlameConsumer
43 extends AbstractRepositoryConsumer
44 {
45 private static final String JAZZ_TIMESTAMP_PATTERN = "yyyy-MM-dd";
46
47 // 1 Deb (1008) 2011-12-14 Test.txt
48 // 2 Deb (1005) 2011-12-14 59 My commit comment.
49
50 private static final Pattern LINE_PATTERN = Pattern.compile( "(\\d+) (.*) \\((\\d+)\\) (\\d+-\\d+-\\d+) (.*)" );
51
52 private List<BlameLine> fLines = new ArrayList<BlameLine>();
53
54 private SimpleDateFormat dateFormat;
55
56 /**
57 * Construct the JazzBlameCommand consumer.
58 *
59 * @param repository The repository we are working with.
60 * @param logger The logger to use.
61 */
62 public JazzBlameConsumer( ScmProviderRepository repository, ScmLogger logger )
63 {
64 super( repository, logger );
65
66 dateFormat = new SimpleDateFormat( JAZZ_TIMESTAMP_PATTERN );
67 dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
68 }
69
70 /**
71 * Process one line of output from the execution of the "scm annotate" command.
72 *
73 * @param line The line of output from the external command that has been pumped to us.
74 * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String)
75 */
76 public void consumeLine( String line )
77 {
78 super.consumeLine( line );
79
80 Matcher matcher = LINE_PATTERN.matcher( line );
81 if ( matcher.matches() )
82 {
83 String lineNumberStr = matcher.group( 1 );
84 String owner = matcher.group( 2 );
85 String changeSetNumberStr = matcher.group( 3 );
86 String dateStr = matcher.group( 4 );
87 Date date = parseDate( dateStr, JAZZ_TIMESTAMP_PATTERN, null );
88 fLines.add( new BlameLine( date, changeSetNumberStr, owner ) );
89 }
90 }
91
92 public List<BlameLine> getLines()
93 {
94 return fLines;
95 }
96 }