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
37 public class GitRemoveConsumer extends AbstractConsumer {
38
39
40
41 private static final Pattern REMOVED_PATTERN = Pattern.compile("^rm\\s'(.*)'");
42
43 private final List<ScmFile> removedFiles = new ArrayList<>();
44
45 private final URI relativeRepositoryPath;
46
47
48
49
50
51 public GitRemoveConsumer() {
52 this(null);
53 }
54
55 public GitRemoveConsumer(URI relativeRepositoryPath) {
56 this.relativeRepositoryPath = relativeRepositoryPath;
57 }
58
59
60
61
62 public void consumeLine(String line) {
63 if (line.length() <= 2) {
64 return;
65 }
66
67 Matcher matcher = REMOVED_PATTERN.matcher(line);
68 if (matcher.matches()) {
69 String file = GitStatusConsumer.resolvePath(matcher.group(1), relativeRepositoryPath);
70 removedFiles.add(new ScmFile(file, ScmFileStatus.DELETED));
71 } else {
72 if (logger.isInfoEnabled()) {
73 logger.info("could not parse line: " + line);
74 }
75
76 return;
77 }
78 }
79
80 public List<ScmFile> getRemovedFiles() {
81 return removedFiles;
82 }
83 }