001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.provider.svn.svnexe.command; 020 021import java.io.File; 022import java.util.ArrayList; 023import java.util.Iterator; 024import java.util.List; 025 026import org.apache.maven.scm.ScmFile; 027import org.apache.maven.scm.ScmFileStatus; 028import org.apache.maven.scm.util.AbstractConsumer; 029 030/** 031 * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a> 032 * 033 */ 034public abstract class AbstractFileCheckingConsumer extends AbstractConsumer { 035 protected File workingDirectory; 036 037 private final List<ScmFile> files = new ArrayList<>(); 038 039 protected int revision; 040 041 private boolean filtered; 042 043 public AbstractFileCheckingConsumer(File workingDirectory) { 044 this.workingDirectory = workingDirectory; 045 } 046 047 /** {@inheritDoc} */ 048 public final void consumeLine(String line) { 049 if (line.length() <= 3) { 050 return; 051 } 052 053 if (logger.isDebugEnabled()) { 054 logger.debug(line); 055 } 056 057 try { 058 parseLine(line); 059 } catch (RuntimeException re) { 060 logger.warn("RuntimeException while parsing: " + line, re); 061 throw re; 062 } 063 } 064 065 protected abstract void parseLine(String line); 066 067 protected List<ScmFile> getFiles() { 068 069 if (!filtered) { 070 for (Iterator<ScmFile> ite = files.iterator(); ite.hasNext(); ) { 071 ScmFile file = ite.next(); 072 if (!file.getStatus().equals(ScmFileStatus.DELETED) 073 && !new File(workingDirectory, file.getPath()).isFile()) { 074 ite.remove(); 075 } 076 } 077 078 filtered = true; 079 } 080 081 return files; 082 } 083 084 protected final int parseInt(String revisionString) { 085 try { 086 return Integer.parseInt(revisionString); 087 } catch (NumberFormatException ex) { 088 return 0; 089 } 090 } 091 092 protected void addFile(ScmFile file) { 093 files.add(file); 094 } 095 096 public final int getRevision() { 097 return revision; 098 } 099 100 public File getWorkingDirectory() { 101 return workingDirectory; 102 } 103}