001package org.apache.maven.scm.provider.perforce.command.status; 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.provider.perforce.command.AbstractPerforceConsumer; 023import org.codehaus.plexus.util.cli.StreamConsumer; 024 025import java.util.ArrayList; 026import java.util.List; 027 028/** 029 * @author Mike Perham 030 */ 031public class PerforceStatusConsumer 032 extends AbstractPerforceConsumer 033 implements StreamConsumer 034{ 035 static final int STATE_FILES = 1; 036 037 static final int STATE_ERROR = 2; 038 039 private int currentState = STATE_FILES; 040 041 private List<String> depotfiles = new ArrayList<String>(); 042 043 /** {@inheritDoc} */ 044 public void consumeLine( String line ) 045 { 046 if ( line.indexOf( "not opened" ) != -1 ) 047 { 048 // User has no files open at all, just return 049 return; 050 } 051 switch ( currentState ) 052 { 053 /* 054//depot/sandbox/mperham/scm-test/Foo.java#1 - add default change (text) 055//depot/sandbox/mperham/scm-test/bar/Bar.xml#1 - add default change (text) 056 */ 057 case STATE_FILES: 058 if ( line.startsWith( "//" ) ) 059 { 060 depotfiles.add( line.trim() ); 061 } 062 break; 063 default: 064 error( line ); 065 break; 066 } 067 } 068 069 private void error( String line ) 070 { 071 currentState = STATE_ERROR; 072 output.println( line ); 073 } 074 075 public boolean isSuccess() 076 { 077 return currentState != STATE_ERROR; 078 } 079 080 public List<String> getDepotfiles() 081 { 082 return depotfiles; 083 } 084}