Refactor out the LoggerSink creation from TabFile users

Since users of the TabFile class are likely to need to create a
ValidationError.Sink class using similar text, make a common method in
the TabFile class to do so and use it by the current users of TabFile.
Also, add a new helper method to the ValidationError class to be used by
the new TabFile method.

Change-Id: Ie79db11322ec2c2659200367c031bfdf7aea40f2
This commit is contained in:
Martin Fick
2015-08-31 13:03:57 -06:00
parent 5953bdea1b
commit de40ff47f4
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 { private GroupList readGroupList() throws IOException {
ValidationError.Sink errors = new ValidationError.Sink() { return GroupList.parse(readUTF8(GroupList.FILE_NAME),
@Override GroupList.createLoggerSink(GroupList.FILE_NAME, log));
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);
} }
@Override @Override

View File

@@ -53,14 +53,8 @@ public class VersionedAccountQueries extends VersionedMetaData {
@Override @Override
protected void onLoad() throws IOException, ConfigInvalidException { protected void onLoad() throws IOException, ConfigInvalidException {
ValidationError.Sink errors = new ValidationError.Sink() { queryList = QueryList.parse(readUTF8(QueryList.FILE_NAME),
@Override QueryList.createLoggerSink(QueryList.FILE_NAME, log));
public void error(ValidationError error) {
log.error("Error parsing file " + QueryList.FILE_NAME + ": " +
error.getMessage());
}
};
queryList = QueryList.parse(readUTF8(QueryList.FILE_NAME), errors);
} }
@Override @Override

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.git; package com.google.gerrit.server.git;
import org.slf4j.Logger;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
@@ -126,4 +128,9 @@ public class TabFile {
} }
return r.toString(); 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; package com.google.gerrit.server.git;
import org.slf4j.Logger;
/** Indicates a problem with Git based data. */ /** Indicates a problem with Git based data. */
public class ValidationError { public class ValidationError {
private final String message; private final String message;
@@ -42,4 +44,13 @@ public class ValidationError {
public interface Sink { public interface Sink {
void error(ValidationError error); 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());
}
};
}
} }