Merge "Fix a few minor bugs."
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
index 8048558..bf5a2c7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
@@ -129,7 +129,7 @@
String content = getFile(repo, id, filePath, logs);
if (content != null && !content.isEmpty()) {
addFile(projectName, branch, dir + "/", dir + "/" + ownersFileName,
- content.split("\\R+"));
+ content.split("\\R"));
}
if (stopLooking.contains(dir + "/") || !dir.contains("/")) {
break; // stop looking through parent directory
@@ -146,8 +146,7 @@
}
}
} catch (Exception e) {
- logger.atSevere().withCause(e).log(
- "Fail to find repository of project %s", projectName);
+ logger.atSevere().log("OwnersDb failed to find repository of project %s", projectName);
logException(logs, "OwnersDb get repository", e);
}
countNumOwners(files);
@@ -384,16 +383,17 @@
String project, String branch, String file, List<String> logs) {
// 'file' must be an absolute path from the root of 'project'.
logs.add("getRepoFile:" + project + ":" + branch + ":" + file);
- try (Repository repo = repoManager.openRepository(new Project.NameKey(project))) {
- ObjectId id = repo.resolve(branch);
- if (id != null) {
- return getFile(repo, id, file, logs);
+ if (repoManager != null) { // ParserTest can call with null repoManager
+ try (Repository repo = repoManager.openRepository(new Project.NameKey(project))) {
+ ObjectId id = repo.resolve(branch);
+ if (id != null) {
+ return getFile(repo, id, file, logs);
+ }
+ logs.add("getRepoFile not found branch " + branch);
+ } catch (Exception e) {
+ logger.atSevere().log("getRepoFile failed to find repository of project %s", project);
+ logException(logs, "getRepoFile", e);
}
- logs.add("getRepoFile not found branch " + branch);
- } catch (Exception e) {
- logger.atSevere().withCause(e).log(
- "Fail to find repository of project %s", project);
- logException(logs, "getRepoFile", e);
}
return "";
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Parser.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Parser.java
index ad2fe74..0bf1cca 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Parser.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Parser.java
@@ -289,7 +289,7 @@
String content =
OwnersDb.getRepoFile(repoManager, project, branch, repoFile, logs);
if (content != null && !content.isEmpty()) {
- result.append(parseFile(dir, content.split("\\R+")));
+ result.append(parseFile(dir, content.split("\\R")));
} else {
logs.add("parseLine:include:(empty)");
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/OwnersValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/OwnersValidatorTest.java
index f81e465..769ddbd 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/findowners/OwnersValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/OwnersValidatorTest.java
@@ -178,17 +178,17 @@
"README",
"# some content\nu2@g.com\n",
OWNERS,
- "\nwrong syntax\n#comment\nuser1@google.com\n",
+ "\n\n\nwrong syntax\n#comment\nuser1@google.com\n",
"d2/" + OWNERS,
"u1@g.com\nu3@g.com\n*\n",
"d3/" + OWNERS,
- "\nfile: common/Owners\n");
+ "\n\nfile: common/Owners\n");
private static final ImmutableSet<String> EXPECTED_WRONG_SYNTAX =
ImmutableSet.of(
- "ERROR: syntax: " + OWNERS + ":2: wrong syntax",
+ "ERROR: syntax: " + OWNERS + ":4: wrong syntax",
"ERROR: unknown: u3@g.com at d2/" + OWNERS + ":2",
- "ERROR: ignored: d3/" + OWNERS + ":2: file: common/Owners");
+ "ERROR: ignored: d3/" + OWNERS + ":3: file: common/Owners");
private static final ImmutableSet<String> EXPECTED_VERBOSE_WRONG_SYNTAX =
ImmutableSet.of(
@@ -198,9 +198,9 @@
"MSG: owner: user1@google.com",
"MSG: owner: u1@g.com",
"MSG: owner: u3@g.com",
- "ERROR: syntax: " + OWNERS + ":2: wrong syntax",
+ "ERROR: syntax: " + OWNERS + ":4: wrong syntax",
"ERROR: unknown: u3@g.com at d2/" + OWNERS + ":2",
- "ERROR: ignored: d3/" + OWNERS + ":2: file: common/Owners");
+ "ERROR: ignored: d3/" + OWNERS + ":3: file: common/Owners");
@Test
public void testWrongSyntax() throws Exception {