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.info;
20
21 import java.time.format.DateTimeFormatter;
22 import java.time.temporal.TemporalAccessor;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.maven.scm.command.info.InfoItem;
27 import org.apache.maven.scm.util.AbstractConsumer;
28
29
30
31
32 public class SvnInfoConsumer extends AbstractConsumer {
33 private final List<InfoItem> infoItems = new ArrayList<>();
34
35 private InfoItem currentItem = new InfoItem();
36
37 private static final DateTimeFormatter DT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss Z");
38
39
40
41
42 public void consumeLine(String s) {
43 if (s.equals("")) {
44 if (currentItem != null) {
45 infoItems.add(currentItem);
46 }
47
48 currentItem = new InfoItem();
49 } else if (s.startsWith("Path: ")) {
50 currentItem.setPath(getValue(s));
51 } else if (s.startsWith("URL: ")) {
52 currentItem.setURL(getValue(s));
53 } else if (s.startsWith("Repository Root: ")) {
54 currentItem.setRepositoryRoot(getValue(s));
55 } else if (s.startsWith("Repository UUID: ")) {
56 currentItem.setRepositoryUUID(getValue(s));
57 } else if (s.startsWith("Revision: ")) {
58 currentItem.setRevision(getValue(s));
59 } else if (s.startsWith("Node Kind: ")) {
60 currentItem.setNodeKind(getValue(s));
61 } else if (s.startsWith("Schedule: ")) {
62 currentItem.setSchedule(getValue(s));
63 } else if (s.startsWith("Last Changed Author: ")) {
64 currentItem.setLastChangedAuthor(getValue(s));
65 } else if (s.startsWith("Last Changed Rev: ")) {
66 currentItem.setLastChangedRevision(getValue(s));
67 } else if (s.startsWith("Last Changed Date: ")) {
68 currentItem.setLastChangedDateTime(parseDate(getValue(s)));
69 currentItem.setLastChangedDate(getValue(s));
70 }
71 }
72
73 private static String getValue(String s) {
74 int idx = s.indexOf(": ");
75
76 if (idx < 0) {
77
78 return null;
79 } else {
80 return s.substring(idx + 2);
81 }
82 }
83
84 public List<InfoItem> getInfoItems() {
85 return infoItems;
86 }
87
88 static TemporalAccessor parseDate(String dateText) {
89
90 int startSuffix = dateText.indexOf('(');
91 if (startSuffix != -1) {
92 dateText = dateText.substring(0, startSuffix);
93 }
94 return DT_FORMATTER.parse(dateText.trim());
95 }
96 }