001 package org.apache.maven.scm.provider.jazz.command.changelog;
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
022 import org.apache.maven.scm.ChangeSet;
023 import org.apache.maven.scm.log.ScmLogger;
024 import org.apache.maven.scm.provider.ScmProviderRepository;
025 import org.apache.maven.scm.provider.jazz.command.consumer.AbstractRepositoryConsumer;
026 import org.apache.regexp.RE;
027 import org.apache.regexp.RESyntaxException;
028
029 import java.util.List;
030
031 /**
032 * Consume the output of the scm command for the "history" operation.
033 * <p/>
034 * It is passed in a List of ChangeSet entries. All we do is to parse
035 * the Jazz change set aliases, and save as the revision into the list.
036 * <p/>
037 * NOTE: We do not set the command or date or anything other than the revision
038 * here, as we pick that information up from the "scm list changeset" command.
039 *
040 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
041 */
042 public class JazzHistoryConsumer
043 extends AbstractRepositoryConsumer
044 {
045 //Change sets:
046 // (1589) ---$ Deb "[maven-release-plugin] prepare for next development itera..."
047 // (1585) ---$ Deb "[maven-release-plugin] prepare release GPDB-1.0.21"
048 // (1584) ---$ Deb "This is my first changeset (2)"
049 // (1583) ---$ Deb "This is my first changeset (1)"
050
051 private static final String CHANGESET_PATTERN = "\\((\\d+)\\) (.*)";
052
053 /**
054 * @see #CHANGESET_PATTERN
055 */
056 private RE changeSetRegExp;
057
058 private List<ChangeSet> entries;
059
060 /**
061 * Constructor for our "scm history" consumer.
062 *
063 * @param repo The JazzScmProviderRepository being used.
064 * @param logger The ScmLogger to use.
065 * @param entries The List of ChangeSet entries that we will populate.
066 */
067 public JazzHistoryConsumer( ScmProviderRepository repo, ScmLogger logger, List<ChangeSet> entries )
068 {
069 super( repo, logger );
070 this.entries = entries;
071
072 try
073 {
074 changeSetRegExp = new RE( CHANGESET_PATTERN );
075 }
076 catch ( RESyntaxException ex )
077 {
078 throw new RuntimeException(
079 "INTERNAL ERROR: Could not create regexp to parse jazz scm history output. This shouldn't happen. Something is probably wrong with the oro installation.",
080 ex );
081 }
082 }
083
084 /**
085 * Process one line of output from the execution of the "scm xxxx" command.
086 *
087 * @param line The line of output from the external command that has been pumped to us.
088 * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String)
089 */
090 public void consumeLine( String line )
091 {
092 super.consumeLine( line );
093 if ( changeSetRegExp.match( line ) )
094 {
095 String changesetAlias = changeSetRegExp.getParen( 1 );
096 ChangeSet changeSet = new ChangeSet();
097 changeSet.setRevision( changesetAlias );
098
099 entries.add( changeSet );
100 }
101 }
102 }