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.update;
20
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.List;
25
26 import org.apache.maven.scm.ChangeFile;
27 import org.apache.maven.scm.ChangeSet;
28 import org.apache.maven.scm.ScmFile;
29 import org.apache.maven.scm.ScmFileStatus;
30 import org.apache.maven.scm.provider.svn.svnexe.command.AbstractFileCheckingConsumer;
31
32
33
34
35 public class SvnUpdateConsumer extends AbstractFileCheckingConsumer {
36 private static final String UPDATED_TO_REVISION_TOKEN = "Updated to revision";
37
38 private static final String AT_REVISION_TOKEN = "At revision";
39
40 private static final String EXPORTED_REVISION_TOKEN = "Exported revision";
41
42 private static final String RESTORED_TOKEN = "Restored";
43
44 private List<ChangeSet> changeSets = new ArrayList<>();
45
46
47
48
49
50 public SvnUpdateConsumer(File workingDirectory) {
51 super(workingDirectory);
52 }
53
54
55
56
57
58
59
60
61 protected void parseLine(String line) {
62 line = line.trim();
63
64 String statusString = line.substring(0, 1);
65
66 String file = line.substring(3).trim();
67
68 if (file.startsWith(workingDirectory.getAbsolutePath())) {
69 if (file.length() == workingDirectory.getAbsolutePath().length()) {
70 file = ".";
71 } else {
72 file = file.substring(this.workingDirectory.getAbsolutePath().length() + 1);
73 }
74 }
75
76 ScmFileStatus status;
77
78 if (line.startsWith(UPDATED_TO_REVISION_TOKEN)) {
79 String revisionString = line.substring(UPDATED_TO_REVISION_TOKEN.length() + 1, line.length() - 1);
80
81 revision = parseInt(revisionString);
82
83 return;
84 } else if (line.startsWith(AT_REVISION_TOKEN)) {
85 String revisionString = line.substring(AT_REVISION_TOKEN.length() + 1, line.length() - 1);
86
87 revision = parseInt(revisionString);
88
89 return;
90 } else if (line.startsWith(EXPORTED_REVISION_TOKEN)) {
91 String revisionString = line.substring(EXPORTED_REVISION_TOKEN.length() + 1, line.length() - 1);
92
93 revision = parseInt(revisionString);
94
95 return;
96 } else if (line.startsWith(RESTORED_TOKEN)) {
97 return;
98 } else if (statusString.equals("A")) {
99 status = ScmFileStatus.ADDED;
100 } else if (statusString.equals("U") || statusString.equals("M")) {
101 status = ScmFileStatus.UPDATED;
102 } else if (statusString.equals("D")) {
103 status = ScmFileStatus.DELETED;
104 } else {
105
106
107 return;
108 }
109
110 addFile(new ScmFile(file, status));
111
112 List<ChangeFile> changeFiles = Arrays.asList(
113 new ChangeFile[] {new ChangeFile(line, Integer.valueOf(revision).toString())});
114
115 ChangeSet changeSet = new ChangeSet(null, null, null, changeFiles);
116 changeSets.add(changeSet);
117 }
118
119 public List<ScmFile> getUpdatedFiles() {
120 return getFiles();
121 }
122
123 public List<ChangeSet> getChangeSets() {
124 return changeSets;
125 }
126
127 public void setChangeSets(List<ChangeSet> changeSets) {
128 this.changeSets = changeSets;
129 }
130 }