001package org.apache.maven.scm.provider.git.gitexe.command.remove; 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.ScmFile; 023import org.apache.maven.scm.ScmFileStatus; 024import org.apache.maven.scm.log.ScmLogger; 025import org.codehaus.plexus.util.cli.StreamConsumer; 026 027import java.util.ArrayList; 028import java.util.List; 029import java.util.regex.Matcher; 030import java.util.regex.Pattern; 031 032/** 033 * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a> 034 * @author Olivier Lamy 035 * 036 */ 037public class GitRemoveConsumer 038 implements StreamConsumer 039{ 040 /** 041 * The pattern used to match deleted file lines 042 */ 043 private static final Pattern REMOVED_PATTERN = Pattern.compile( "^rm\\s'(.*)'" ); 044 045 private ScmLogger logger; 046 047 private List<ScmFile> removedFiles = new ArrayList<ScmFile>(); 048 049 // ---------------------------------------------------------------------- 050 // 051 // ---------------------------------------------------------------------- 052 053 public GitRemoveConsumer( ScmLogger logger ) 054 { 055 this.logger = logger; 056 } 057 058 // ---------------------------------------------------------------------- 059 // StreamConsumer Implementation 060 // ---------------------------------------------------------------------- 061 062 /** 063 * {@inheritDoc} 064 */ 065 public void consumeLine( String line ) 066 { 067 if ( line.length() <= 2 ) 068 { 069 return; 070 } 071 072 Matcher matcher = REMOVED_PATTERN.matcher( line ); 073 if ( matcher.matches() ) 074 { 075 String file = matcher.group( 1 ); 076 removedFiles.add( new ScmFile( file, ScmFileStatus.DELETED ) ); 077 } 078 else 079 { 080 if ( logger.isInfoEnabled() ) 081 { 082 logger.info( "could not parse line: " + line ); 083 } 084 085 return; 086 } 087 } 088 089 public List<ScmFile> getRemovedFiles() 090 { 091 return removedFiles; 092 } 093 094}