View Javadoc

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  import org.apache.regexp.RE;
27  import org.apache.regexp.RESyntaxException;
28  
29  import java.text.SimpleDateFormat;
30  import java.util.ArrayList;
31  import java.util.Date;
32  import java.util.List;
33  import java.util.TimeZone;
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 String LINE_PATTERN = "(\\d+) (.*) \\((\\d+)\\) (\\d+-\\d+-\\d+) (.*)";
51  
52      /**
53       * @see #LINE_PATTERN
54       */
55      private RE lineRegexp;
56  
57      private List<BlameLine> fLines = new ArrayList<BlameLine>();
58  
59      private SimpleDateFormat dateFormat;
60  
61      /**
62       * Construct the JazzBlameCommand consumer.
63       *
64       * @param repository The repository we are working with.
65       * @param logger     The logger to use.
66       */
67      public JazzBlameConsumer( ScmProviderRepository repository, ScmLogger logger )
68      {
69          super( repository, logger );
70  
71          dateFormat = new SimpleDateFormat( JAZZ_TIMESTAMP_PATTERN );
72          dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
73  
74          try
75          {
76              lineRegexp = new RE( LINE_PATTERN );
77          }
78          catch ( RESyntaxException ex )
79          {
80              throw new RuntimeException(
81                  "INTERNAL ERROR: Could not create regexp to parse jazz scm blame output. This shouldn't happen. Something is probably wrong with the oro installation.",
82                  ex );
83          }
84      }
85  
86      /**
87       * Process one line of output from the execution of the "scm annotate" command.
88       *
89       * @param line The line of output from the external command that has been pumped to us.
90       * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String)
91       */
92      public void consumeLine( String line )
93      {
94          super.consumeLine( line );
95  
96          if ( lineRegexp.match( line ) )
97          {
98              String lineNumberStr = lineRegexp.getParen( 1 );
99              String owner = lineRegexp.getParen( 2 );
100             String changeSetNumberStr = lineRegexp.getParen( 3 );
101             String dateStr = lineRegexp.getParen( 4 );
102             Date date = parseDate( dateStr, JAZZ_TIMESTAMP_PATTERN, null );
103             fLines.add( new BlameLine( date, changeSetNumberStr, owner ) );
104         }
105     }
106 
107     public List<BlameLine> getLines()
108     {
109         return fLines;
110     }
111 }