Update configme (#1631)
* Upgrade to ConfigMe 1.0.1 * Use ConfigMe reader whenever possible, minor simplifications
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package fr.xephi.authme.service.yaml;
|
||||
|
||||
import ch.jalu.configme.exception.ConfigMeException;
|
||||
import ch.jalu.configme.resource.PropertyReader;
|
||||
import ch.jalu.configme.resource.YamlFileResource;
|
||||
import org.yaml.snakeyaml.parser.ParserException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -15,16 +16,32 @@ public final class YamlFileResourceProvider {
|
||||
|
||||
/**
|
||||
* Creates a {@link YamlFileResource} instance for the given file. Wraps SnakeYAML's parse exception
|
||||
* into an AuthMe exception.
|
||||
* thrown when a reader is created into an AuthMe exception.
|
||||
*
|
||||
* @param file the file to load
|
||||
* @return the generated resource
|
||||
*/
|
||||
public static YamlFileResource loadFromFile(File file) {
|
||||
try {
|
||||
return new YamlFileResource(file);
|
||||
} catch (ParserException e) {
|
||||
throw new YamlParseException(file.getPath(), e);
|
||||
return new AuthMeYamlFileResource(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension of {@link YamlFileResource} which wraps SnakeYAML's parse exception into a custom
|
||||
* exception when a reader is created.
|
||||
*/
|
||||
private static final class AuthMeYamlFileResource extends YamlFileResource {
|
||||
|
||||
AuthMeYamlFileResource(File file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyReader createReader() {
|
||||
try {
|
||||
return super.createReader();
|
||||
} catch (ConfigMeException e) {
|
||||
throw new YamlParseException(getFile().getPath(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user