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  
27  import java.util.List;
28  import java.util.regex.Matcher;
29  import java.util.regex.Pattern;
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 Pattern CHANGESET_PATTERN = Pattern.compile( "\\((\\d+)\\) (.*)" );
52  
53      private List<ChangeSet> entries;
54  
55      /**
56       * Constructor for our "scm history" consumer.
57       *
58       * @param repo    The JazzScmProviderRepository being used.
59       * @param logger  The ScmLogger to use.
60       * @param entries The List of ChangeSet entries that we will populate.
61       */
62      public JazzHistoryConsumer( ScmProviderRepository repo, ScmLogger logger, List<ChangeSet> entries )
63      {
64          super( repo, logger );
65          this.entries = entries;
66      }
67  
68      /**
69       * Process one line of output from the execution of the "scm xxxx" command.
70       *
71       * @param line The line of output from the external command that has been pumped to us.
72       * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String)
73       */
74      public void consumeLine( String line )
75      {
76          super.consumeLine( line );
77          Matcher matcher = CHANGESET_PATTERN.matcher( line );
78          if ( matcher.find() )
79          {
80              String changesetAlias = matcher.group( 1 );
81              ChangeSet changeSet = new ChangeSet();
82              changeSet.setRevision( changesetAlias );
83  
84              entries.add( changeSet );
85          }
86      }
87  }