1 | |
package com.aragost.javahg.internals; |
2 | |
|
3 | |
import java.io.File; |
4 | |
import java.io.IOException; |
5 | |
import java.util.List; |
6 | |
|
7 | |
import com.google.common.collect.Lists; |
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
public class AddRemoveCommandHelper { |
13 | |
|
14 | |
private AbstractCommand command; |
15 | |
|
16 | |
private String prefix; |
17 | |
|
18 | |
public AddRemoveCommandHelper(AbstractCommand command, String prefix) { |
19 | 1710 | super(); |
20 | 1710 | this.command = command; |
21 | 1710 | this.prefix = prefix; |
22 | 1710 | } |
23 | |
|
24 | |
public List<String> execute(String... files) { |
25 | 1712 | List<String> result = Lists.newArrayList(); |
26 | 1712 | for (String line : command.launchIterator(files)) { |
27 | 929 | if (line.startsWith(prefix)) { |
28 | 929 | String file = new String(line.substring(prefix.length())); |
29 | 929 | result.add(file); |
30 | 929 | } else { |
31 | 0 | command.cleanUp(); |
32 | 0 | throw new UnexpectedCommandOutputException(this.command, line); |
33 | |
} |
34 | |
} |
35 | 1711 | return result; |
36 | |
} |
37 | |
|
38 | |
public List<File> execute(File... files) { |
39 | 944 | return stringList2fileList(execute(fileArray2StringArray(files))); |
40 | |
} |
41 | |
|
42 | |
public List<File> execute() { |
43 | 941 | return execute(new File[0]); |
44 | |
} |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
private final String[] fileArray2StringArray(File[] files) { |
53 | 944 | return Utils.fileArray2StringArray(files); |
54 | |
} |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
private final List<File> stringList2fileList(List<String> strings) { |
64 | 943 | String[] strArray = strings.toArray(new String[strings.size()]); |
65 | 943 | File[] fileArray = Utils.stringArray2FileArray(this.command.getRepository().getDirectory(), strArray); |
66 | 943 | return Lists.newArrayList(fileArray); |
67 | |
} |
68 | |
|
69 | |
} |