List<GerritProject> dynamicGerritProjects = new ArrayList<GerritProject>();
List<Branch> branches = null;
List<Topic> topics = null;
List<FilePath> filePaths = null;
List<FilePath> forbiddenFilePaths = null;
GerritProject dynamicGerritProject = null;
String line = "";
int lineNr = 0;
while ((line = reader.readLine()) != null) {
++lineNr;
// Remove any comments starting with a #
int commentPos = line.indexOf('#');
if (commentPos > -1) {
line = line.substring(0, commentPos);
}
// Remove any comments starting with a ;
commentPos = line.indexOf(';');
if (commentPos > -1) {
line = line.substring(0, commentPos);
}
// Trim leading and trailing whitespace
line = line.trim();
if (line.isEmpty()) {
continue;
}
Matcher matcher = linePattern.matcher(line);
if (!matcher.matches()) {
throw new ParseException("Line " + lineNr + ": cannot parse '" + line + "'", lineNr);
}
// CS IGNORE MagicNumber FOR NEXT 3 LINES. REASON: ConstantsNotNeeded
String item = matcher.group(1);
String oper = matcher.group(2);
String text = matcher.group(3);
if (item == null || oper == null || text == null) {
throw new ParseException("Line " + lineNr + ": cannot parse '" + line + "'", lineNr);
}
char operChar = oper.charAt(0);
CompareType type = CompareType.findByOperator(operChar);
logger.trace("==> item:({0}) oper:({1}) text:({2})", new Object[]{item, oper, text});
if (SHORTNAME_PROJECT.equals(item)) { // Project
// stash previous project to the list
if (dynamicGerritProject != null) {
dynamicGerritProjects.add(dynamicGerritProject);
}
branches = new ArrayList<Branch>();
topics = new ArrayList<Topic>();
filePaths = new ArrayList<FilePath>();
forbiddenFilePaths = new ArrayList<FilePath>();
dynamicGerritProject = new GerritProject(type, text, branches, topics, filePaths, forbiddenFilePaths);
} else if (SHORTNAME_BRANCH.equals(item)) { // Branch
if (branches == null) {
throw new ParseException("Line " + lineNr + ": attempt to use 'Branch' before 'Project'", lineNr);
}
Branch branch = new Branch(type, text);
branches.add(branch);
dynamicGerritProject.setBranches(branches);
} else if (SHORTNAME_TOPIC.equals(item)) { // Topic
if (topics == null) {
throw new ParseException("Line " + lineNr + ": attempt to use 'Topic' before 'Project'", lineNr);
}
Topic topic = new Topic(type, text);
topics.add(topic);
dynamicGerritProject.setTopics(topics);
} else if (SHORTNAME_FILE.equals(item)) { // FilePath
if (filePaths == null) {
throw new ParseException("Line " + lineNr + ": attempt to use 'FilePath' before 'Project'", lineNr);
}
FilePath filePath = new FilePath(type, text);
filePaths.add(filePath);
dynamicGerritProject.setFilePaths(filePaths);
} else if (SHORTNAME_FORBIDDEN_FILE.equals(item)) { // ForbiddenFilePath
if (forbiddenFilePaths == null) {
throw new ParseException("Line " + lineNr + ": attempt to use 'ForbiddenFilePath' before 'Project'", lineNr);
}
FilePath filePath = new FilePath(type, text);
forbiddenFilePaths.add(filePath);
dynamicGerritProject.setForbiddenFilePaths(filePaths);
}
}
// Finally stash the last project to the list
if (dynamicGerritProject != null) {