Fix a few minor bugs. * Change to split source lines with "\\R". When split with "\\R+" empty lines were skipped. * Reduce logger output size, no need to dump full exception call stacks. * Check null repoManager pointer before use; avoid exception in unit tests. Change-Id: Id4fa4d445eee4f16619f46052dd3139b2461d6bb
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 0729f72..9f48be6 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java +++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
@@ -128,7 +128,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 @@ -145,8 +145,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); @@ -375,16 +374,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 317bea7..e5be62f 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Parser.java +++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Parser.java
@@ -296,7 +296,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 cc60789..fcc230d 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/findowners/OwnersValidatorTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/OwnersValidatorTest.java
@@ -177,17 +177,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( @@ -197,9 +197,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 {