in java/com/google/gerrit/plugins/codeowners/backend/findowners/FindOwnersCodeOwnerConfigParser.java [242:306]
private CodeOwnerSet parsePerFileLine(String line) {
Matcher perFileMatcher = PAT_PER_FILE.matcher(line);
if (!perFileMatcher.matches() || !isGlobs(perFileMatcher.group(1).trim())) {
return null;
}
String matchedGroup2 = perFileMatcher.group(2).trim();
if (!PAT_PER_FILE_OWNERS.matcher(matchedGroup2).matches()) {
if (PAT_PER_FILE_INCLUDE.matcher(matchedGroup2).matches()) {
error(
ValidationError.create(
String.format(
"keyword 'include' is not supported for per file imports: %s", line)));
// return an empty code owner set to avoid that the line will be reported as invalid once
// more
return CodeOwnerSet.builder().build();
}
return null;
}
String[] globsAndOwners =
new String[] {
removeExtraSpaces(perFileMatcher.group(1)), removeExtraSpaces(perFileMatcher.group(2))
};
ImmutableSet<String> dirGlobs = splitGlobs(globsAndOwners[0]);
String directive = globsAndOwners[1];
if (directive.equals(TOK_SET_NOPARENT)) {
return CodeOwnerSet.builder()
.setIgnoreGlobalAndParentCodeOwners()
.setPathExpressions(dirGlobs)
.build();
}
CodeOwnerConfigReference codeOwnerConfigReference;
if ((codeOwnerConfigReference = parseInclude(directive)) != null) {
return CodeOwnerSet.builder()
.addImport(codeOwnerConfigReference)
.setPathExpressions(dirGlobs)
.build();
}
List<String> ownerEmails = Arrays.asList(directive.split(COMMA, -1));
// Get the comment part of the line (the first '#' and everything that follows).
String comment = perFileMatcher.group(3);
Set<CodeOwnerAnnotation> annotations = new HashSet<>();
if (comment != null) {
Matcher annotationMatcher = PAT_ANNOTATION.matcher(comment);
while (annotationMatcher.find()) {
String annotation = annotationMatcher.group(1);
annotations.add(CodeOwnerAnnotation.create(annotation));
}
}
CodeOwnerSet.Builder codeOwnerSet =
CodeOwnerSet.builder()
.setPathExpressions(dirGlobs)
.setCodeOwners(
ownerEmails.stream().map(CodeOwnerReference::create).collect(toImmutableSet()));
ownerEmails.stream()
.forEach(
email -> codeOwnerSet.addAnnotations(CodeOwnerReference.create(email), annotations));
return codeOwnerSet.build();
}