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