Merge "Refactor out the LoggerSink creation from TabFile users"

This commit is contained in:
Martin Fick 2015-09-01 15:37:32 +00:00 committed by Gerrit Code Review
commit 40b7472fef
4 changed files with 22 additions and 17 deletions

View File

@ -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

View File

@ -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

View File

@ -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);
}
}

View File

@ -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());
}
};
}
}