mirror of
https://github.com/lightbend/config.git
synced 2025-03-22 23:30:27 +08:00
Merge e1f3ce7786
into aa6958469a
This commit is contained in:
commit
28b51a0a4f
@ -711,10 +711,11 @@ public final class ConfigFactory {
|
|||||||
* with all known extensions and merges whatever is found.
|
* with all known extensions and merges whatever is found.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* In the current implementation, the extension ".conf" forces
|
* In the current implementation, the extension ".conf" or ".hocon" forces
|
||||||
* {@link ConfigSyntax#CONF}, ".json" forces {@link ConfigSyntax#JSON}, and
|
* {@link ConfigSyntax#CONF}, ".json" forces {@link ConfigSyntax#JSON}, and
|
||||||
* ".properties" forces {@link ConfigSyntax#PROPERTIES}. When merging files,
|
* ".properties" forces {@link ConfigSyntax#PROPERTIES}. When merging files,
|
||||||
* ".conf" falls back to ".json" falls back to ".properties".
|
* ".conf" falls back to ".hocon" fall back to ".json" falls back to
|
||||||
|
* ".properties".
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Future versions of the implementation may add additional syntaxes or
|
* Future versions of the implementation may add additional syntaxes or
|
||||||
@ -821,8 +822,9 @@ public final class ConfigFactory {
|
|||||||
* classpath order. To keep it simple, the lists are simply concatenated,
|
* classpath order. To keep it simple, the lists are simply concatenated,
|
||||||
* with the same syntax priorities as
|
* with the same syntax priorities as
|
||||||
* {@link #parseFileAnySyntax(File,ConfigParseOptions) parseFileAnySyntax()}
|
* {@link #parseFileAnySyntax(File,ConfigParseOptions) parseFileAnySyntax()}
|
||||||
* - all ".conf" resources are ahead of all ".json" resources which are
|
* - all ".conf" resources are ahead of all ".hocon" resources which are
|
||||||
* ahead of all ".properties" resources.
|
* ahead of all ".json" resources which are ahead of all ".properties"
|
||||||
|
* resources.
|
||||||
*
|
*
|
||||||
* @param klass
|
* @param klass
|
||||||
* class which determines the <code>ClassLoader</code> and the
|
* class which determines the <code>ClassLoader</code> and the
|
||||||
|
@ -6,7 +6,7 @@ package com.typesafe.config;
|
|||||||
/**
|
/**
|
||||||
* The syntax of a character stream (<a href="http://json.org">JSON</a>, <a
|
* The syntax of a character stream (<a href="http://json.org">JSON</a>, <a
|
||||||
* href="https://github.com/typesafehub/config/blob/master/HOCON.md">HOCON</a>
|
* href="https://github.com/typesafehub/config/blob/master/HOCON.md">HOCON</a>
|
||||||
* aka ".conf", or <a href=
|
* aka ".conf" and ".hocon", or <a href=
|
||||||
* "http://download.oracle.com/javase/7/docs/api/java/util/Properties.html#load%28java.io.Reader%29"
|
* "http://download.oracle.com/javase/7/docs/api/java/util/Properties.html#load%28java.io.Reader%29"
|
||||||
* >Java properties</a>).
|
* >Java properties</a>).
|
||||||
*
|
*
|
||||||
|
@ -327,7 +327,7 @@ public abstract class Parseable implements ConfigParseable {
|
|||||||
private static ConfigSyntax syntaxFromExtension(String name) {
|
private static ConfigSyntax syntaxFromExtension(String name) {
|
||||||
if (name.endsWith(".json"))
|
if (name.endsWith(".json"))
|
||||||
return ConfigSyntax.JSON;
|
return ConfigSyntax.JSON;
|
||||||
else if (name.endsWith(".conf"))
|
else if (name.endsWith(".conf") || name.endsWith(".hocon"))
|
||||||
return ConfigSyntax.CONF;
|
return ConfigSyntax.CONF;
|
||||||
else if (name.endsWith(".properties"))
|
else if (name.endsWith(".properties"))
|
||||||
return ConfigSyntax.PROPERTIES;
|
return ConfigSyntax.PROPERTIES;
|
||||||
|
@ -166,12 +166,14 @@ class SimpleIncluder implements FullIncluder {
|
|||||||
// loading app.{conf,json,properties} from the filesystem.
|
// loading app.{conf,json,properties} from the filesystem.
|
||||||
static ConfigObject fromBasename(NameSource source, String name, ConfigParseOptions options) {
|
static ConfigObject fromBasename(NameSource source, String name, ConfigParseOptions options) {
|
||||||
ConfigObject obj;
|
ConfigObject obj;
|
||||||
if (name.endsWith(".conf") || name.endsWith(".json") || name.endsWith(".properties")) {
|
if (name.endsWith(".conf") || name.endsWith(".hocon") || name.endsWith(".json")
|
||||||
|
|| name.endsWith(".properties")) {
|
||||||
ConfigParseable p = source.nameToParseable(name, options);
|
ConfigParseable p = source.nameToParseable(name, options);
|
||||||
|
|
||||||
obj = p.parse(p.options().setAllowMissing(options.getAllowMissing()));
|
obj = p.parse(p.options().setAllowMissing(options.getAllowMissing()));
|
||||||
} else {
|
} else {
|
||||||
ConfigParseable confHandle = source.nameToParseable(name + ".conf", options);
|
ConfigParseable confHandle = source.nameToParseable(name + ".conf", options);
|
||||||
|
ConfigParseable hoconHandle = source.nameToParseable(name + ".hocon", options);
|
||||||
ConfigParseable jsonHandle = source.nameToParseable(name + ".json", options);
|
ConfigParseable jsonHandle = source.nameToParseable(name + ".json", options);
|
||||||
ConfigParseable propsHandle = source.nameToParseable(name + ".properties", options);
|
ConfigParseable propsHandle = source.nameToParseable(name + ".properties", options);
|
||||||
boolean gotSomething = false;
|
boolean gotSomething = false;
|
||||||
@ -190,6 +192,16 @@ class SimpleIncluder implements FullIncluder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (syntax == null || syntax == ConfigSyntax.CONF) {
|
||||||
|
try {
|
||||||
|
obj = hoconHandle.parse(hoconHandle.options().setAllowMissing(false)
|
||||||
|
.setSyntax(ConfigSyntax.CONF));
|
||||||
|
gotSomething = true;
|
||||||
|
} catch (ConfigException.IO e) {
|
||||||
|
failMessages.add(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (syntax == null || syntax == ConfigSyntax.JSON) {
|
if (syntax == null || syntax == ConfigSyntax.JSON) {
|
||||||
try {
|
try {
|
||||||
ConfigObject parsed = jsonHandle.parse(jsonHandle.options()
|
ConfigObject parsed = jsonHandle.parse(jsonHandle.options()
|
||||||
|
@ -24,7 +24,8 @@ class EquivalentsTest extends TestUtils {
|
|||||||
|
|
||||||
private def filesForEquiv(equiv: File) = {
|
private def filesForEquiv(equiv: File) = {
|
||||||
val rawFiles = equiv.listFiles()
|
val rawFiles = equiv.listFiles()
|
||||||
val files = rawFiles.filter({ f => f.getName().endsWith(".json") || f.getName().endsWith(".conf") })
|
val files = rawFiles.filter({ f => f.getName().endsWith(".json") || f.getName().endsWith(".conf")
|
||||||
|
|| f.getName().endsWith(".hocon") })
|
||||||
files
|
files
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user