View Javadoc
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   */
31  public class PerforceStatusConsumer
32      extends AbstractPerforceConsumer
33      implements StreamConsumer
34  {
35      static final int STATE_FILES = 1;
36  
37      static final int STATE_ERROR = 2;
38  
39      private int currentState = STATE_FILES;
40  
41      private List<String> depotfiles = new ArrayList<String>();
42  
43      /** {@inheritDoc} */
44      public void consumeLine( String line )
45      {
46          if ( line.indexOf( "not opened" ) != -1 )
47          {
48              // User has no files open at all, just return
49              return;
50          }
51          switch ( currentState )
52          {
53              /*
54  //depot/sandbox/mperham/scm-test/Foo.java#1 - add default change (text)
55  //depot/sandbox/mperham/scm-test/bar/Bar.xml#1 - add default change (text)
56               */
57              case STATE_FILES:
58                  if ( line.startsWith( "//" ) )
59                  {
60                      depotfiles.add( line.trim() );
61                  }
62                  break;
63              default:
64                  error( line );
65                  break;
66          }
67      }
68  
69      private void error( String line )
70      {
71          currentState = STATE_ERROR;
72          output.println( line );
73      }
74  
75      public boolean isSuccess()
76      {
77          return currentState != STATE_ERROR;
78      }
79  
80      public List<String> getDepotfiles()
81      {
82          return depotfiles;
83      }
84  }