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.remoteinfo;
20
21 import java.util.HashMap;
22 import java.util.regex.Matcher;
23 import java.util.regex.Pattern;
24
25 import org.apache.maven.scm.command.remoteinfo.RemoteInfoScmResult;
26 import org.apache.maven.scm.util.AbstractConsumer;
27
28
29
30
31 public class GitRemoteInfoConsumer extends AbstractConsumer {
32
33
34
35
36 private static final Pattern BRANCH_PATTERN = Pattern.compile("^(.*)\\s+refs/heads/(.*)");
37
38
39
40
41 private static final Pattern TAGS_PATTERN = Pattern.compile("^(.*)\\s+refs/tags/(.*)");
42
43 private final RemoteInfoScmResult remoteInfoScmResult;
44
45
46
47
48
49 public GitRemoteInfoConsumer(String commandLine) {
50 this.remoteInfoScmResult = new RemoteInfoScmResult(commandLine, new HashMap<>(), new HashMap<>());
51 }
52
53
54
55
56
57
58
59
60 public void consumeLine(String line) {
61 if (logger.isDebugEnabled()) {
62 logger.debug(line);
63 }
64
65 Matcher matcher = BRANCH_PATTERN.matcher(line);
66 if (matcher.matches()) {
67 remoteInfoScmResult.getBranches().put(matcher.group(2), matcher.group(1));
68 }
69
70 matcher = TAGS_PATTERN.matcher(line);
71 if (matcher.matches()) {
72 remoteInfoScmResult.getTags().put(matcher.group(2), matcher.group(1));
73 }
74 }
75
76 public RemoteInfoScmResult getRemoteInfoScmResult() {
77 return remoteInfoScmResult;
78 }
79 }