1 package org.apache.maven.scm.provider.perforce.command.status;
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 org.apache.maven.scm.provider.perforce.command.AbstractPerforceConsumer;
23 import org.codehaus.plexus.util.cli.StreamConsumer;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 /**
29 * @author Mike Perham
30 * @version $Id: PerforceChangeLogConsumer.java 331276 2005-11-07 15:04:54Z
31 * evenisse $
32 */
33 public class PerforceStatusConsumer
34 extends AbstractPerforceConsumer
35 implements StreamConsumer
36 {
37 static final int STATE_FILES = 1;
38
39 static final int STATE_ERROR = 2;
40
41 private int currentState = STATE_FILES;
42
43 private List<String> depotfiles = new ArrayList<String>();
44
45 /** {@inheritDoc} */
46 public void consumeLine( String line )
47 {
48 if ( line.indexOf( "not opened" ) != -1 )
49 {
50 // User has no files open at all, just return
51 return;
52 }
53 switch ( currentState )
54 {
55 /*
56 //depot/sandbox/mperham/scm-test/Foo.java#1 - add default change (text)
57 //depot/sandbox/mperham/scm-test/bar/Bar.xml#1 - add default change (text)
58 */
59 case STATE_FILES:
60 if ( line.startsWith( "//" ) )
61 {
62 depotfiles.add( line.trim() );
63 }
64 break;
65 default:
66 error( line );
67 break;
68 }
69 }
70
71 private void error( String line )
72 {
73 currentState = STATE_ERROR;
74 output.println( line );
75 }
76
77 public boolean isSuccess()
78 {
79 return currentState != STATE_ERROR;
80 }
81
82 public List<String> getDepotfiles()
83 {
84 return depotfiles;
85 }
86 }