mirror of
https://github.com/lightbend/config.git
synced 2025-02-24 02:00:46 +08:00
Make string, stream parsers support classpath includes
Previously they didn't support any kind of include.
This commit is contained in:
parent
386613909b
commit
05c60ea0fb
@ -97,7 +97,14 @@ public abstract class Parseable implements ConfigParseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConfigParseable relativeTo(String filename) {
|
ConfigParseable relativeTo(String filename) {
|
||||||
return null;
|
// fall back to classpath; we treat the "filename" as absolute
|
||||||
|
// (don't add a package name in front),
|
||||||
|
// if it starts with "/" then remove the "/", for consistency
|
||||||
|
// with ParseableResources.relativeTo
|
||||||
|
String resource = filename;
|
||||||
|
if (filename.startsWith("/"))
|
||||||
|
resource = filename.substring(1);
|
||||||
|
return newResources(resource, options().setOriginDescription(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigIncludeContext includeContext() {
|
ConfigIncludeContext includeContext() {
|
||||||
@ -434,14 +441,7 @@ public abstract class Parseable implements ConfigParseable {
|
|||||||
if (sibling.exists()) {
|
if (sibling.exists()) {
|
||||||
return newFile(sibling, options().setOriginDescription(null));
|
return newFile(sibling, options().setOriginDescription(null));
|
||||||
} else {
|
} else {
|
||||||
// fall back to classpath; we treat the "filename" as absolute
|
return super.relativeTo(filename);
|
||||||
// (don't add a package name in front),
|
|
||||||
// if it starts with "/" then remove the "/", for consistency
|
|
||||||
// with ParseableResources.relativeTo
|
|
||||||
String resource = filename;
|
|
||||||
if (filename.startsWith("/"))
|
|
||||||
resource = filename.substring(1);
|
|
||||||
return newResources(resource, options().setOriginDescription(null));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,6 +329,14 @@ class PublicApiTest extends TestUtils {
|
|||||||
included.map(_.name))
|
included.map(_.name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
def includersAreUsedRecursivelyWithString() {
|
||||||
|
val included = whatWasIncluded(ConfigFactory.parseString(""" include "equiv03/includes.conf" """, _))
|
||||||
|
|
||||||
|
assertEquals(List("equiv03/includes.conf", "letters/a.conf", "numbers/1.conf", "numbers/2", "letters/b.json", "letters/c", "root/foo.conf"),
|
||||||
|
included.map(_.name))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
def includersAreUsedWithClasspath() {
|
def includersAreUsedWithClasspath() {
|
||||||
val included = whatWasIncluded(ConfigFactory.parseResources(classOf[PublicApiTest], "/test03.conf", _))
|
val included = whatWasIncluded(ConfigFactory.parseResources(classOf[PublicApiTest], "/test03.conf", _))
|
||||||
|
Loading…
Reference in New Issue
Block a user