diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/api/AllProjectsConfig.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/api/AllProjectsConfig.java index 06d907a11a..d6c0dc9920 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/api/AllProjectsConfig.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/api/AllProjectsConfig.java @@ -102,15 +102,8 @@ public class AllProjectsConfig extends VersionedMetaData { } private GroupList readGroupList() throws IOException { - ValidationError.Sink errors = new ValidationError.Sink() { - @Override - public void error(ValidationError error) { - log.error("Error parsing file " + GroupList.FILE_NAME + ": " + error.getMessage()); - } - }; - String text = readUTF8(GroupList.FILE_NAME); - - return GroupList.parse(text, errors); + return GroupList.parse(readUTF8(GroupList.FILE_NAME), + GroupList.createLoggerSink(GroupList.FILE_NAME, log)); } @Override diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/VersionedAccountQueries.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/VersionedAccountQueries.java index b12e7ceacb..18e1310f91 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/VersionedAccountQueries.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/VersionedAccountQueries.java @@ -53,14 +53,8 @@ public class VersionedAccountQueries extends VersionedMetaData { @Override protected void onLoad() throws IOException, ConfigInvalidException { - ValidationError.Sink errors = new ValidationError.Sink() { - @Override - public void error(ValidationError error) { - log.error("Error parsing file " + QueryList.FILE_NAME + ": " + - error.getMessage()); - } - }; - queryList = QueryList.parse(readUTF8(QueryList.FILE_NAME), errors); + queryList = QueryList.parse(readUTF8(QueryList.FILE_NAME), + QueryList.createLoggerSink(QueryList.FILE_NAME, log)); } @Override diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/TabFile.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/TabFile.java index 74d8f2d7b5..13d2b1efc4 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/TabFile.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/TabFile.java @@ -14,6 +14,8 @@ package com.google.gerrit.server.git; +import org.slf4j.Logger; + import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; @@ -126,4 +128,9 @@ public class TabFile { } return r.toString(); } + + public static ValidationError.Sink createLoggerSink(String file, Logger log) { + return ValidationError.createLoggerSink("Error parsing file " + file + ": ", + log); + } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/ValidationError.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/ValidationError.java index ad84046e35..e6a8ae46b8 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/ValidationError.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/ValidationError.java @@ -14,6 +14,8 @@ package com.google.gerrit.server.git; +import org.slf4j.Logger; + /** Indicates a problem with Git based data. */ public class ValidationError { private final String message; @@ -42,4 +44,13 @@ public class ValidationError { public interface Sink { void error(ValidationError error); } + + public static Sink createLoggerSink(final String message, final Logger log) { + return new ValidationError.Sink() { + @Override + public void error(ValidationError error) { + log.error(message + error.getMessage()); + } + }; + } }