blob: fc202c265a6af8eac08586d73d7c09c33a15cf1b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package org.jetbrains.idea.svn.api;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.util.containers.Convertor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.wc.ISVNEventHandler;
import org.tmatesoft.svn.core.wc.SVNEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Konstantin Kolosovsky.
*/
public class FileStatusResultParser {
private static final double DEFAULT_PROGRESS = 0.0;
@NotNull
private Pattern myLinePattern;
@Nullable
private ISVNEventHandler handler;
@NotNull
private Convertor<Matcher, SVNEvent> myConvertor;
public FileStatusResultParser(@NotNull Pattern linePattern,
@Nullable ISVNEventHandler handler,
@NotNull Convertor<Matcher, SVNEvent> convertor) {
myLinePattern = linePattern;
this.handler = handler;
myConvertor = convertor;
}
public void parse(@NotNull String output) throws VcsException {
if (StringUtil.isEmpty(output)) {
return;
}
for (String line : StringUtil.splitByLines(output)) {
onLine(line);
}
}
public void onLine(@NotNull String line) throws VcsException {
Matcher matcher = myLinePattern.matcher(line);
if (matcher.matches()) {
process(matcher);
}
else {
throw new VcsException("unknown state on line " + line);
}
}
public void process(@NotNull Matcher matcher) throws VcsException {
if (handler != null) {
try {
handler.handleEvent(myConvertor.convert(matcher), DEFAULT_PROGRESS);
} catch (SVNException e) {
throw new VcsException(e);
}
}
}
}
|