001 package org.apache.maven.scm.provider.tfs.command.consumer;
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.io.File;
023 import java.util.ArrayList;
024 import java.util.List;
025
026 import org.apache.maven.scm.ScmFile;
027 import org.apache.maven.scm.ScmFileStatus;
028 import org.codehaus.plexus.util.cli.StreamConsumer;
029
030 public class FileListConsumer
031 implements StreamConsumer
032 {
033
034 private boolean fed = false;
035
036 protected String currentDir = "";
037
038 private List<ScmFile> files = new ArrayList<ScmFile>();
039
040 public void consumeLine( String line )
041 {
042 fed = true;
043 if ( line.endsWith( ":" ) )
044 {
045 currentDir = line.substring( 0, line.lastIndexOf( ':' ) );
046 ScmFile scmFile = new ScmFile( currentDir, ScmFileStatus.CHECKED_OUT );
047 if ( !files.contains( scmFile ) )
048 {
049 files.add( scmFile );
050 }
051 }
052 else if ( line.trim().equals( "" ) )
053 {
054 currentDir = "";
055 }
056 else if ( !currentDir.equals( "" ) && line.indexOf( ' ' ) >= 0 )
057 {
058 String filename = line.split( " " )[1];
059 files.add( getScmFile( filename ) );
060 }
061 else
062 {
063 files.add( getScmFile( line ) );
064 }
065 }
066
067 protected ScmFile getScmFile( String filename )
068 {
069 return new ScmFile( new File( currentDir, filename ).getAbsolutePath(), ScmFileStatus.CHECKED_OUT );
070 }
071
072 public List<ScmFile> getFiles()
073 {
074 return files;
075 }
076
077 public boolean hasBeenFed()
078 {
079 return fed;
080 }
081 }