Browse files

Make string, stream parsers support classpath includes

Previously they didn't support any kind of include.
  • Loading branch information...
1 parent 3866139 commit 05c60ea0fbca067235af540a90204b0aeabd5d72 @havocp havocp committed Apr 9, 2012
View
18 config/src/main/java/com/typesafe/config/impl/Parseable.java
@@ -97,7 +97,14 @@ ConfigSyntax guessSyntax() {
}
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() {
@@ -434,14 +441,7 @@ ConfigParseable relativeTo(String filename) {
if (sibling.exists()) {
return newFile(sibling, options().setOriginDescription(null));
} else {
- // 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));
+ return super.relativeTo(filename);
}
}
View
8 config/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala
@@ -330,6 +330,14 @@ class PublicApiTest extends TestUtils {
}
@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
def includersAreUsedWithClasspath() {
val included = whatWasIncluded(ConfigFactory.parseResources(classOf[PublicApiTest], "/test03.conf", _))

0 comments on commit 05c60ea

Please sign in to comment.