001 package org.apache.maven.scm.provider.cvslib.command.list;
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 java.util.LinkedList;
023 import java.util.List;
024
025 import org.apache.maven.scm.ScmFile;
026 import org.apache.maven.scm.ScmFileStatus;
027 import org.apache.maven.scm.log.ScmLogger;
028 import org.codehaus.plexus.util.StringUtils;
029 import org.codehaus.plexus.util.cli.StreamConsumer;
030
031 /**
032 * Parses CVS/Entries format, for example, like
033 *
034 * <pre>
035 * /checkoutlist/1.9/Wed Jan 26 19:08:06 2005/-kkv/
036 * /commitinfo/1.10/Tue Jan 11 01:25:34 2005/-kkv/
037 * /config/1.15/Sun Jan 23 02:15:57 2005/-kkv/
038 * D/directory1////
039 * D/directory2////
040 * </pre>
041 *
042 * @author <a href="mailto:szakusov@emdev.ru">Sergey Zakusov</a>: implemented to fix "Unknown file status" problem
043 *
044 */
045 public class CvsListConsumer
046 implements StreamConsumer
047 {
048 private ScmLogger logger;
049
050 private List<ScmFile> entries;
051
052 /**
053 * @param logger is a logger
054 */
055 public CvsListConsumer( ScmLogger logger )
056 {
057 this.logger = logger;
058 this.entries = new LinkedList<ScmFile>();
059 }
060
061 /** {@inheritDoc} */
062 public void consumeLine( String i_line )
063 {
064 if ( logger.isDebugEnabled() )
065 {
066 logger.debug( i_line );
067 }
068
069 String[] params = i_line.split( "/" );
070 if ( params.length < 2 )
071 {
072 if ( StringUtils.isNotEmpty( i_line ) )
073 {
074 if ( logger.isWarnEnabled() )
075 {
076 logger.warn( "Unable to parse it as CVS/Entries format: " + i_line + "." );
077 }
078 }
079 }
080 else
081 {
082 entries.add( new ScmFile( params[1], ScmFileStatus.UNKNOWN ) );
083 }
084 }
085
086 /**
087 * @return Parse result
088 */
089 public List<ScmFile> getEntries()
090 {
091 return entries;
092 }
093 }