1 package org.apache.maven.scm.provider.cvslib.command.list;
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 java.util.LinkedList;
23 import java.util.List;
24
25 import org.apache.maven.scm.ScmFile;
26 import org.apache.maven.scm.ScmFileStatus;
27 import org.apache.maven.scm.log.ScmLogger;
28 import org.codehaus.plexus.util.StringUtils;
29 import org.codehaus.plexus.util.cli.StreamConsumer;
30
31 /**
32 * Parses CVS/Entries format, for example, like
33 *
34 * <pre>
35 * /checkoutlist/1.9/Wed Jan 26 19:08:06 2005/-kkv/
36 * /commitinfo/1.10/Tue Jan 11 01:25:34 2005/-kkv/
37 * /config/1.15/Sun Jan 23 02:15:57 2005/-kkv/
38 * D/directory1////
39 * D/directory2////
40 * </pre>
41 *
42 * @author <a href="mailto:szakusov@emdev.ru">Sergey Zakusov</a>: implemented to fix "Unknown file status" problem
43 *
44 */
45 public class CvsListConsumer
46 implements StreamConsumer
47 {
48 private ScmLogger logger;
49
50 private List<ScmFile> entries;
51
52 /**
53 * @param logger is a logger
54 */
55 public CvsListConsumer( ScmLogger logger )
56 {
57 this.logger = logger;
58 this.entries = new LinkedList<ScmFile>();
59 }
60
61 /** {@inheritDoc} */
62 public void consumeLine( String i_line )
63 {
64 if ( logger.isDebugEnabled() )
65 {
66 logger.debug( i_line );
67 }
68
69 String[] params = i_line.split( "/" );
70 if ( params.length < 2 )
71 {
72 if ( StringUtils.isNotEmpty( i_line ) )
73 {
74 if ( logger.isWarnEnabled() )
75 {
76 logger.warn( "Unable to parse it as CVS/Entries format: " + i_line + "." );
77 }
78 }
79 }
80 else
81 {
82 entries.add( new ScmFile( params[1], ScmFileStatus.UNKNOWN ) );
83 }
84 }
85
86 /**
87 * @return Parse result
88 */
89 public List<ScmFile> getEntries()
90 {
91 return entries;
92 }
93 }