001package 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
022import org.apache.maven.scm.ChangeSet;
023import org.apache.maven.scm.log.ScmLogger;
024import org.apache.maven.scm.provider.ScmProviderRepository;
025import org.apache.maven.scm.provider.jazz.command.consumer.AbstractRepositoryConsumer;
026
027import java.util.List;
028import java.util.regex.Matcher;
029import java.util.regex.Pattern;
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 */
042public 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 Pattern CHANGESET_PATTERN = Pattern.compile( "\\((\\d+)\\) (.*)" );
052
053    private List<ChangeSet> entries;
054
055    /**
056     * Constructor for our "scm history" consumer.
057     *
058     * @param repo    The JazzScmProviderRepository being used.
059     * @param logger  The ScmLogger to use.
060     * @param entries The List of ChangeSet entries that we will populate.
061     */
062    public JazzHistoryConsumer( ScmProviderRepository repo, ScmLogger logger, List<ChangeSet> entries )
063    {
064        super( repo, logger );
065        this.entries = entries;
066    }
067
068    /**
069     * Process one line of output from the execution of the "scm xxxx" command.
070     *
071     * @param line The line of output from the external command that has been pumped to us.
072     * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String)
073     */
074    public void consumeLine( String line )
075    {
076        super.consumeLine( line );
077        Matcher matcher = CHANGESET_PATTERN.matcher( line );
078        if ( matcher.find() )
079        {
080            String changesetAlias = matcher.group( 1 );
081            ChangeSet changeSet = new ChangeSet();
082            changeSet.setRevision( changesetAlias );
083
084            entries.add( changeSet );
085        }
086    }
087}