001 package org.apache.maven.scm.provider.perforce.command.unedit;
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 java.util.ArrayList;
023 import java.util.List;
024
025 import org.apache.maven.scm.ScmFile;
026 import org.apache.maven.scm.ScmFileStatus;
027 import org.apache.maven.scm.provider.perforce.command.AbstractPerforceConsumer;
028 import org.apache.regexp.RE;
029 import org.apache.regexp.RESyntaxException;
030 import org.codehaus.plexus.util.cli.StreamConsumer;
031
032 /**
033 * @author Mike Perham
034 * @author Olivier Lamy
035 * @version $Id: PerforceChangeLogConsumer.java 331276 2005-11-07 15:04:54Z
036 * evenisse $
037 */
038 public class PerforceUnEditConsumer
039 extends AbstractPerforceConsumer
040 implements StreamConsumer
041 {
042
043 private static final String PATTERN = "^([^#]+)#\\d+ - (.*)";
044
045 private static final int STATE_NORMAL = 1;
046
047 private static final int STATE_ERROR = 2;
048
049 private int currentState = STATE_NORMAL;
050
051 private List<ScmFile> edits = new ArrayList<ScmFile>();
052
053 private RE revisionRegexp;
054
055 public PerforceUnEditConsumer()
056 {
057 try
058 {
059 revisionRegexp = new RE( PATTERN );
060 }
061 catch ( RESyntaxException ignored )
062 {
063 ignored.printStackTrace();
064 }
065 }
066
067 public List<ScmFile> getEdits()
068 {
069 return edits;
070 }
071
072 /** {@inheritDoc} */
073 public void consumeLine( String line )
074 {
075 if ( currentState != STATE_ERROR && revisionRegexp.match( line ) )
076 {
077 edits.add( new ScmFile(revisionRegexp.getParen( 1 ), ScmFileStatus.UNKNOWN ) );
078 return;
079 }
080
081 error( line );
082 }
083
084 private void error( String line )
085 {
086 currentState = STATE_ERROR;
087 output.println( line );
088 }
089
090 public boolean isSuccess()
091 {
092 return currentState == STATE_NORMAL;
093 }
094 }