forked from reposense/RepoSense
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepoConfigCsvParser.java
More file actions
86 lines (70 loc) · 3.54 KB
/
RepoConfigCsvParser.java
File metadata and controls
86 lines (70 loc) · 3.54 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package reposense.parser;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import org.apache.commons.csv.CSVRecord;
import reposense.model.CommitHash;
import reposense.model.FileType;
import reposense.model.RepoConfiguration;
import reposense.model.RepoLocation;
/**
* Container for the values parsed from {@code repo-config.csv} file.
*/
public class RepoConfigCsvParser extends CsvParser<RepoConfiguration> {
public static final String REPO_CONFIG_FILENAME = "repo-config.csv";
private static final String IGNORE_STANDALONE_CONFIG_KEYWORD = "yes";
/**
* Positions of the elements of a line in repo-config.csv config file
*/
private static final int LOCATION_POSITION = 0;
private static final int BRANCH_POSITION = 1;
private static final int FILE_FORMATS_POSITION = 2;
private static final int IGNORE_GLOB_LIST_POSITION = 3;
private static final int IGNORE_STANDALONE_CONFIG_POSITION = 4;
private static final int IGNORE_COMMIT_LIST_CONFIG_POSITION = 5;
public RepoConfigCsvParser(Path csvFilePath) throws IOException {
super(csvFilePath);
}
/**
* Gets the list of positions that are mandatory for verification.
*/
@Override
protected int[] mandatoryPositions() {
return new int[] {
LOCATION_POSITION,
};
}
/**
* Processes the csv file line by line and add created {@code RepoConfiguration} into {@code results} but
* ignores duplicated {@code RepoConfiguration} if there exists one that has same {@code location} and
* {@code branch}.
*/
@Override
protected void processLine(List<RepoConfiguration> results, CSVRecord record) throws InvalidLocationException {
RepoLocation location = new RepoLocation(get(record, LOCATION_POSITION));
String branch = getOrDefault(record, BRANCH_POSITION, RepoConfiguration.DEFAULT_BRANCH);
boolean isFormatsOverriding = isElementOverridingStandaloneConfig(record, FILE_FORMATS_POSITION);
List<FileType> formats = FileType.convertFormatStringsToFileTypes(
getAsListWithoutOverridePrefix(record, FILE_FORMATS_POSITION));
boolean isIgnoreGlobListOverriding = isElementOverridingStandaloneConfig(record, IGNORE_GLOB_LIST_POSITION);
List<String> ignoreGlobList = getAsListWithoutOverridePrefix(record, IGNORE_GLOB_LIST_POSITION);
boolean isIgnoreCommitListOverriding =
isElementOverridingStandaloneConfig(record, IGNORE_COMMIT_LIST_CONFIG_POSITION);
List<CommitHash> ignoreCommitList = CommitHash.convertStringsToCommits(
getAsListWithoutOverridePrefix(record, IGNORE_COMMIT_LIST_CONFIG_POSITION));
String ignoreStandaloneConfig = get(record, IGNORE_STANDALONE_CONFIG_POSITION);
boolean isStandaloneConfigIgnored = ignoreStandaloneConfig.equalsIgnoreCase(IGNORE_STANDALONE_CONFIG_KEYWORD);
if (!isStandaloneConfigIgnored && !ignoreStandaloneConfig.isEmpty()) {
logger.warning(
"Ignoring unknown value " + ignoreStandaloneConfig + " in ignore standalone config column.");
}
RepoConfiguration config = new RepoConfiguration(
location, branch, formats, ignoreGlobList, isStandaloneConfigIgnored, ignoreCommitList,
isFormatsOverriding, isIgnoreGlobListOverriding, isIgnoreCommitListOverriding);
if (results.contains(config)) {
logger.warning("Ignoring duplicated repository " + location + " " + branch);
return;
}
results.add(config);
}
}