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.git.gitexe.command.remove;
20
21 import java.net.URI;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26
27 import org.apache.maven.scm.ScmFile;
28 import org.apache.maven.scm.ScmFileStatus;
29 import org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusConsumer;
30 import org.apache.maven.scm.util.AbstractConsumer;
31
32
33
34
35
36 public class GitRemoveConsumer extends AbstractConsumer {
37
38
39
40 private static final Pattern REMOVED_PATTERN = Pattern.compile("^rm\\s'(.*)'");
41
42 private final List<ScmFile> removedFiles = new ArrayList<>();
43
44 private final URI relativeRepositoryPath;
45
46
47
48
49
50 public GitRemoveConsumer() {
51 this(null);
52 }
53
54 public GitRemoveConsumer(URI relativeRepositoryPath) {
55 this.relativeRepositoryPath = relativeRepositoryPath;
56 }
57
58
59
60
61 public void consumeLine(String line) {
62 if (line.length() <= 2) {
63 return;
64 }
65
66 Matcher matcher = REMOVED_PATTERN.matcher(line);
67 if (matcher.matches()) {
68 String file = GitStatusConsumer.resolvePath(matcher.group(1), relativeRepositoryPath);
69 removedFiles.add(new ScmFile(file, ScmFileStatus.DELETED));
70 } else {
71 if (logger.isInfoEnabled()) {
72 logger.info("could not parse line: " + line);
73 }
74 }
75 }
76
77 public List<ScmFile> getRemovedFiles() {
78 return removedFiles;
79 }
80 }