View Javadoc

1   package org.apache.maven.scm.provider.jazz.command.changelog;
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.ChangeSet;
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.util.List;
30  
31  /**
32   * Consume the output of the scm command for the "history" operation.
33   * <p/>
34   * It is passed in a List of ChangeSet entries. All we do is to parse
35   * the Jazz change set aliases, and save as the revision into the list.
36   * <p/>
37   * NOTE: We do not set the command or date or anything other than the revision
38   * here, as we pick that information up from the "scm list changeset" command.
39   *
40   * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
41   */
42  public class JazzHistoryConsumer
43      extends AbstractRepositoryConsumer
44  {
45  //Change sets:
46  //  (1589)  ---$ Deb "[maven-release-plugin] prepare for next development itera..."
47  //  (1585)  ---$ Deb "[maven-release-plugin] prepare release GPDB-1.0.21"
48  //  (1584)  ---$ Deb "This is my first changeset (2)"
49  //  (1583)  ---$ Deb "This is my first changeset (1)"
50  
51      private static final String CHANGESET_PATTERN = "\\((\\d+)\\) (.*)";
52  
53      /**
54       * @see #CHANGESET_PATTERN
55       */
56      private RE changeSetRegExp;
57  
58      private List<ChangeSet> entries;
59  
60      /**
61       * Constructor for our "scm history" consumer.
62       *
63       * @param repo    The JazzScmProviderRepository being used.
64       * @param logger  The ScmLogger to use.
65       * @param entries The List of ChangeSet entries that we will populate.
66       */
67      public JazzHistoryConsumer( ScmProviderRepository repo, ScmLogger logger, List<ChangeSet> entries )
68      {
69          super( repo, logger );
70          this.entries = entries;
71  
72          try
73          {
74              changeSetRegExp = new RE( CHANGESET_PATTERN );
75          }
76          catch ( RESyntaxException ex )
77          {
78              throw new RuntimeException(
79                  "INTERNAL ERROR: Could not create regexp to parse jazz scm history output. This shouldn't happen. Something is probably wrong with the oro installation.",
80                  ex );
81          }
82      }
83  
84      /**
85       * Process one line of output from the execution of the "scm xxxx" command.
86       *
87       * @param line The line of output from the external command that has been pumped to us.
88       * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String)
89       */
90      public void consumeLine( String line )
91      {
92          super.consumeLine( line );
93          if ( changeSetRegExp.match( line ) )
94          {
95              String changesetAlias = changeSetRegExp.getParen( 1 );
96              ChangeSet changeSet = new ChangeSet();
97              changeSet.setRevision( changesetAlias );
98  
99              entries.add( changeSet );
100         }
101     }
102 }