001package org.apache.maven.scm.provider.cvslib.command.tag;
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.ScmFile;
023import org.apache.maven.scm.ScmFileStatus;
024import org.apache.maven.scm.log.ScmLogger;
025import org.codehaus.plexus.util.cli.StreamConsumer;
026import org.codehaus.plexus.util.StringUtils;
027
028import java.util.ArrayList;
029import java.util.List;
030
031/**
032 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
033 * @author Olivier Lamy
034 *
035 */
036public class CvsTagConsumer
037    implements StreamConsumer
038{
039    private ScmLogger logger;
040
041    private List<ScmFile> files = new ArrayList<ScmFile>();
042
043    public CvsTagConsumer( ScmLogger logger )
044    {
045        this.logger = logger;
046    }
047
048    /** {@inheritDoc} */
049    public void consumeLine( String line )
050    {
051        if ( logger.isDebugEnabled() )
052        {
053            logger.debug( line );
054        }
055
056        if ( line.length() < 3 )
057        {
058            if ( StringUtils.isNotEmpty( line ) )
059            {
060                if ( logger.isWarnEnabled() )
061                {
062                    logger.warn( "Unable to parse output from command: line length must be bigger than 3. ("
063                        + line + ")." );
064                }
065            }
066            return;
067        }
068
069        String status = line.substring( 0, 2 );
070
071        String file = line.substring( 2 );
072
073        if ( status.equals( "T " ) )
074        {
075            files.add( new ScmFile( file, ScmFileStatus.TAGGED ) );
076        }
077        else
078        {
079            if ( logger.isWarnEnabled() )
080            {
081                logger.warn( "Unknown status: '" + status + "'." );
082            }
083        }
084    }
085
086    public List<ScmFile> getTaggedFiles()
087    {
088        return files;
089    }
090}