1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.provider.svn.svnexe.command;
20
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import org.apache.maven.scm.ScmFile;
27 import org.apache.maven.scm.ScmFileStatus;
28 import org.apache.maven.scm.util.AbstractConsumer;
29
30
31
32
33
34 public abstract class AbstractFileCheckingConsumer extends AbstractConsumer {
35 protected File workingDirectory;
36
37 private final List<ScmFile> files = new ArrayList<>();
38
39 protected int revision;
40
41 private boolean filtered;
42
43 public AbstractFileCheckingConsumer(File workingDirectory) {
44 this.workingDirectory = workingDirectory;
45 }
46
47
48 public final void consumeLine(String line) {
49 if (line.length() <= 3) {
50 return;
51 }
52
53 if (logger.isDebugEnabled()) {
54 logger.debug(line);
55 }
56
57 try {
58 parseLine(line);
59 } catch (RuntimeException re) {
60 logger.warn("RuntimeException while parsing: " + line, re);
61 throw re;
62 }
63 }
64
65 protected abstract void parseLine(String line);
66
67 protected List<ScmFile> getFiles() {
68
69 if (!filtered) {
70 for (Iterator<ScmFile> ite = files.iterator(); ite.hasNext(); ) {
71 ScmFile file = ite.next();
72 if (!file.getStatus().equals(ScmFileStatus.DELETED)
73 && !new File(workingDirectory, file.getPath()).isFile()) {
74 ite.remove();
75 }
76 }
77
78 filtered = true;
79 }
80
81 return files;
82 }
83
84 protected final int parseInt(String revisionString) {
85 try {
86 return Integer.parseInt(revisionString);
87 } catch (NumberFormatException ex) {
88 return 0;
89 }
90 }
91
92 protected void addFile(ScmFile file) {
93 files.add(file);
94 }
95
96 public final int getRevision() {
97 return revision;
98 }
99
100 public File getWorkingDirectory() {
101 return workingDirectory;
102 }
103 }