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