mirror of
https://github.com/lightbend/config.git
synced 2025-01-15 23:01:05 +08:00
rename parse() methods to parseFoo()
for clarity and to avoid overload ambiguity
This commit is contained in:
parent
adb80f6017
commit
31b9ccf983
@ -70,8 +70,9 @@ public final class ConfigFactory {
|
||||
ConfigParseOptions options) {
|
||||
ConfigRoot system = systemPropertiesRoot(rootPath);
|
||||
|
||||
Config mainFiles = parse(rootPath, options);
|
||||
Config referenceFiles = parse(rootPath + ".reference", options);
|
||||
Config mainFiles = parseResourcesForPath(rootPath, options);
|
||||
Config referenceFiles = parseResourcesForPath(rootPath + ".reference",
|
||||
options);
|
||||
|
||||
return system.withFallbacks(mainFiles, referenceFiles);
|
||||
}
|
||||
@ -123,24 +124,24 @@ public final class ConfigFactory {
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
public static Config parse(Properties properties,
|
||||
public static Config parseProperties(Properties properties,
|
||||
ConfigParseOptions options) {
|
||||
return Parseable.newProperties(properties, options).parse().toConfig();
|
||||
}
|
||||
|
||||
public static Config parse(Reader reader, ConfigParseOptions options) {
|
||||
public static Config parseReader(Reader reader, ConfigParseOptions options) {
|
||||
return Parseable.newReader(reader, options).parse().toConfig();
|
||||
}
|
||||
|
||||
public static Config parse(URL url, ConfigParseOptions options) {
|
||||
public static Config parseURL(URL url, ConfigParseOptions options) {
|
||||
return Parseable.newURL(url, options).parse().toConfig();
|
||||
}
|
||||
|
||||
public static Config parse(File file, ConfigParseOptions options) {
|
||||
public static Config parseFile(File file, ConfigParseOptions options) {
|
||||
return Parseable.newFile(file, options).parse().toConfig();
|
||||
}
|
||||
|
||||
public static Config parse(Class<?> klass, String resource,
|
||||
public static Config parseResource(Class<?> klass, String resource,
|
||||
ConfigParseOptions options) {
|
||||
return Parseable.newResource(klass, resource, options).parse()
|
||||
.toConfig();
|
||||
@ -156,9 +157,10 @@ public final class ConfigFactory {
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
public static Config parse(String path, ConfigParseOptions options) {
|
||||
public static Config parseResourcesForPath(String rootPath,
|
||||
ConfigParseOptions options) {
|
||||
// null originDescription is allowed in parseResourcesForPath
|
||||
return ConfigImpl.parseResourcesForPath(path, options).toConfig();
|
||||
return ConfigImpl.parseResourcesForPath(rootPath, options).toConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,12 +42,12 @@ class EquivalentsTest extends TestUtils {
|
||||
|
||||
private def parse(flavor: ConfigSyntax, f: File) = {
|
||||
val options = ConfigParseOptions.defaults().setSyntax(flavor)
|
||||
postParse(ConfigFactory.parse(f, options).toObject)
|
||||
postParse(ConfigFactory.parseFile(f, options).toObject)
|
||||
}
|
||||
|
||||
private def parse(f: File) = {
|
||||
val options = ConfigParseOptions.defaults()
|
||||
postParse(ConfigFactory.parse(f, options).toObject)
|
||||
postParse(ConfigFactory.parseFile(f, options).toObject)
|
||||
}
|
||||
|
||||
// would like each "equivNN" directory to be a suite and each file in the dir
|
||||
|
@ -51,7 +51,7 @@ class PropertiesTest extends TestUtils {
|
||||
|
||||
props.setProperty(propsPath, propsPath)
|
||||
|
||||
val conf = ConfigFactory.parse(props, ConfigParseOptions.defaults())
|
||||
val conf = ConfigFactory.parseProperties(props, ConfigParseOptions.defaults())
|
||||
|
||||
assertEquals(propsPath, conf.getString(confPath))
|
||||
}
|
||||
@ -83,7 +83,7 @@ class PropertiesTest extends TestUtils {
|
||||
props.setProperty("x.y", "bar")
|
||||
props.setProperty("x.y.z", "foo")
|
||||
|
||||
val conf = ConfigFactory.parse(props, ConfigParseOptions.defaults())
|
||||
val conf = ConfigFactory.parseProperties(props, ConfigParseOptions.defaults())
|
||||
|
||||
assertEquals(2, conf.toObject.size())
|
||||
assertEquals("foo", conf.getString("a.b"))
|
||||
|
@ -217,7 +217,7 @@ class PublicApiTest extends TestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private def resource(filename: String) = {
|
||||
private def resourceFile(filename: String) = {
|
||||
val resourceDir = new File("src/test/resources")
|
||||
if (!resourceDir.exists())
|
||||
throw new RuntimeException("This test can only be run from the project's root directory")
|
||||
@ -236,11 +236,11 @@ class PublicApiTest extends TestUtils {
|
||||
@Test
|
||||
def allowMissing() {
|
||||
val e = intercept[ConfigException.IO] {
|
||||
ConfigFactory.parse(resource("nonexistent.conf"), ConfigParseOptions.defaults().setAllowMissing(false))
|
||||
ConfigFactory.parseFile(resourceFile("nonexistent.conf"), ConfigParseOptions.defaults().setAllowMissing(false))
|
||||
}
|
||||
assertTrue(e.getMessage.contains("No such"))
|
||||
|
||||
val conf = ConfigFactory.parse(resource("nonexistent.conf"), ConfigParseOptions.defaults().setAllowMissing(true))
|
||||
val conf = ConfigFactory.parseFile(resourceFile("nonexistent.conf"), ConfigParseOptions.defaults().setAllowMissing(true))
|
||||
assertTrue(conf.isEmpty())
|
||||
}
|
||||
|
||||
@ -251,10 +251,10 @@ class PublicApiTest extends TestUtils {
|
||||
// change that the includes are allowed to be missing.
|
||||
// This can break because some options might "propagate" through
|
||||
// to includes, but we don't want them all to do so.
|
||||
val conf = ConfigFactory.parse(resource("test03.conf"), ConfigParseOptions.defaults().setAllowMissing(false))
|
||||
val conf = ConfigFactory.parseFile(resourceFile("test03.conf"), ConfigParseOptions.defaults().setAllowMissing(false))
|
||||
assertEquals(42, conf.getInt("test01.booleans"))
|
||||
|
||||
val conf2 = ConfigFactory.parse(resource("test03.conf"), ConfigParseOptions.defaults().setAllowMissing(true))
|
||||
val conf2 = ConfigFactory.parseFile(resourceFile("test03.conf"), ConfigParseOptions.defaults().setAllowMissing(true))
|
||||
assertEquals(conf, conf2)
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ class PublicApiTest extends TestUtils {
|
||||
|
||||
@Test
|
||||
def includersAreUsedWithFiles() {
|
||||
val included = whatWasIncluded(ConfigFactory.parse(resource("test03.conf"), _))
|
||||
val included = whatWasIncluded(ConfigFactory.parseFile(resourceFile("test03.conf"), _))
|
||||
|
||||
assertEquals(List("test01", "test02.conf", "equiv01/original.json",
|
||||
"nothere", "nothere.conf", "nothere.json", "nothere.properties"),
|
||||
@ -298,7 +298,7 @@ class PublicApiTest extends TestUtils {
|
||||
@Test
|
||||
def includersAreUsedRecursivelyWithFiles() {
|
||||
// includes.conf has recursive includes in it
|
||||
val included = whatWasIncluded(ConfigFactory.parse(resource("equiv03/includes.conf"), _))
|
||||
val included = whatWasIncluded(ConfigFactory.parseFile(resourceFile("equiv03/includes.conf"), _))
|
||||
|
||||
assertEquals(List("letters/a.conf", "numbers/1.conf", "numbers/2", "letters/b.json", "letters/c"),
|
||||
included.map(_.name))
|
||||
@ -306,7 +306,7 @@ class PublicApiTest extends TestUtils {
|
||||
|
||||
@Test
|
||||
def includersAreUsedWithClasspath() {
|
||||
val included = whatWasIncluded(ConfigFactory.parse(classOf[PublicApiTest], "/test03.conf", _))
|
||||
val included = whatWasIncluded(ConfigFactory.parseResource(classOf[PublicApiTest], "/test03.conf", _))
|
||||
|
||||
assertEquals(List("test01", "test02.conf", "equiv01/original.json",
|
||||
"nothere", "nothere.conf", "nothere.json", "nothere.properties"),
|
||||
@ -316,7 +316,7 @@ class PublicApiTest extends TestUtils {
|
||||
@Test
|
||||
def includersAreUsedRecursivelyWithClasspath() {
|
||||
// includes.conf has recursive includes in it
|
||||
val included = whatWasIncluded(ConfigFactory.parse(classOf[PublicApiTest], "/equiv03/includes.conf", _))
|
||||
val included = whatWasIncluded(ConfigFactory.parseResource(classOf[PublicApiTest], "/equiv03/includes.conf", _))
|
||||
|
||||
assertEquals(List("letters/a.conf", "numbers/1.conf", "numbers/2", "letters/b.json", "letters/c"),
|
||||
included.map(_.name))
|
||||
|
@ -340,7 +340,7 @@ abstract trait TestUtils {
|
||||
val options = ConfigParseOptions.defaults().
|
||||
setOriginDescription("test string").
|
||||
setSyntax(ConfigSyntax.CONF);
|
||||
ConfigFactory.parse(new StringReader(s), options).asInstanceOf[SimpleConfig]
|
||||
ConfigFactory.parseReader(new StringReader(s), options).asInstanceOf[SimpleConfig]
|
||||
}
|
||||
|
||||
protected def subst(ref: String) = {
|
||||
|
Loading…
Reference in New Issue
Block a user