// this function is a little tricky because there are three places we're
// trying to use it; for 'include "basename"' in a .conf file, for
// loading app.{conf,json,properties} from classpath, and for
// loading app.{conf,json,properties} from the filesystem.
static ConfigObject fromBasename(final NameSource source, final String name, final ConfigParseOptions options) {
ConfigObject obj;
if (name.endsWith(".conf") || name.endsWith(".json") || name.endsWith(".properties")) {
final ConfigParseable p = source.nameToParseable(name, options);
obj = p.parse(p.options().setAllowMissing(options.getAllowMissing()));
} else {
final ConfigParseable confHandle = source.nameToParseable(name + ".conf", options);
final ConfigParseable jsonHandle = source.nameToParseable(name + ".json", options);
final ConfigParseable propsHandle = source.nameToParseable(name + ".properties", options);
boolean gotSomething = false;
final List<String> failMessages = new ArrayList<String>();
final ConfigSyntax syntax = options.getSyntax();
obj = SimpleConfigObject.empty(SimpleConfigOrigin.newSimple(name));
if (syntax == null || syntax == ConfigSyntax.CONF) {
try {
obj = confHandle.parse(confHandle.options().setAllowMissing(false)
.setSyntax(ConfigSyntax.CONF));
gotSomething = true;
} catch (ConfigException.IO e) {
failMessages.add(e.getMessage());
}
}
if (syntax == null || syntax == ConfigSyntax.JSON) {
try {
final ConfigObject parsed = jsonHandle.parse(jsonHandle.options()
.setAllowMissing(false).setSyntax(ConfigSyntax.JSON));
obj = obj.withFallback(parsed);
gotSomething = true;
} catch (ConfigException.IO e) {
failMessages.add(e.getMessage());
}
}
if (syntax == null || syntax == ConfigSyntax.PROPERTIES) {
try {
final ConfigObject parsed = propsHandle.parse(propsHandle.options()
.setAllowMissing(false).setSyntax(ConfigSyntax.PROPERTIES));
obj = obj.withFallback(parsed);
gotSomething = true;
} catch (ConfigException.IO e) {
failMessages.add(e.getMessage());