Commit Graph

735 Commits

Author SHA1 Message Date
Havoc Pennington
dd16b29fbc make mergeOrigins a lot smarter and preserve more structured info
The main case that motivated this was:

    a.b.c = 1
    a.b.x = 2

where the two a.b objects are merged. With this patch, ConfigOrigin
still reports the filename only once, and correctly, for the a.b
object.
2011-11-28 01:11:07 -05:00
Havoc Pennington
2a7c403aa6 Fix a line numbering off-by-one in parser
When we see a newline token, its number is the line it was on
(i.e. the line just ended) not the line we are now on.
This was correct in one place in Parser.java but not
in the other place.
2011-11-27 23:57:40 -05:00
Havoc Pennington
907048fe2b factor out resourceDir and resourceFile (centralize assumption about test pwd) 2011-11-27 20:10:06 -05:00
Havoc Pennington
0457e352fb correct spec's text about empty environment variables 2011-11-27 12:06:10 -05:00
Havoc Pennington
6ec2681055 missing, optional substitutions ${?foo} become undefined not null
This is more useful behavior because it permits an optional override
for example.
2011-11-27 12:04:44 -05:00
Havoc Pennington
4dddfdaf19 Make ${missing} throw an exception and add ${?missing} for the old behavior.
Also updated the spec; in this patch, the spec says ${?missing} will be
undefined, but the code still evaluates it to null as in the old
behavior. A follow-up patch will introduce the undefined behavior
that is now specified.

This change is needed because missing substitutions are probably
a problem in most cases, and evaluating missing to null is probably
not as useful as evaluating it to undefined. If it turns out that
we need the null behavior, a possible syntax is ${foo.bar,null}
or something like that.
2011-11-27 11:33:10 -05:00
Havoc Pennington
5a1bd5aa58 use "SingletonHolder" pattern rather than synchronized in ConfigImpl 2011-11-27 01:59:04 -05:00
Havoc Pennington
f9276c27b5 rename ConfigImpl.parseResourceForPath to parseResourcesForPath
to match actual behavior.
2011-11-27 01:48:11 -05:00
Havoc Pennington
680a295add change ConfigParseable.url to ConfigParseable.origin 2011-11-27 01:22:27 -05:00
Havoc Pennington
cb5017af8b change parseResource to parseResources
parse all resources with the requested name in classpath order.

also extend SimpleConfigOrigin to distinguish resources by URL
2011-11-27 01:09:50 -05:00
Havoc Pennington
a7d6c23a9e when loading resource, keep ClassLoader not class and pre-canonicalize resource name
This makes the resource in the ConfigOrigin nice and predictable.

It also lets us use the full ClassLoader API instead of only the
Class methods that have the special resource name handling.
2011-11-26 22:38:23 -05:00
Havoc Pennington
7e22880cd0 add a test-lib and use it to test resource loading behavior 2011-11-26 20:34:03 -05:00
Havoc Pennington
70fad92b50 Fix the directory names used in test suite for relocated sources 2011-11-26 20:33:06 -05:00
Havoc Pennington
93b87097fd Move the main project to config/ subdir and add a root aggregate project 2011-11-26 19:42:52 -05:00
Havoc Pennington
bc0cf31359 add a Build.scala
As preliminary for adding subprojects
2011-11-26 18:58:23 -05:00
Havoc Pennington
ff2a5064aa make ConfigValue.toString create a single-line compact string
while render() creates the formatted verbose string with comments.
2011-11-25 15:58:15 -05:00
Havoc Pennington
69b5a765df add ConfigValue.render() which returns a String version of the value
also toString() includes the render() plus the class name.
2011-11-25 15:45:12 -05:00
Havoc Pennington
7c55d91149 make Path.render() properly handle empty string path elements 2011-11-25 15:39:41 -05:00
Havoc Pennington
21d9b8b358 add methods to ConfigOrigin for filename, resource, url, and lineNumber
Play wanted to use these to jump to the problematic spot in a
config file when an exception occurs.
2011-11-25 14:04:05 -05:00
Havoc Pennington
2e283367de when rethrowing a json exception don't use AssertionError
it seems to make Eclipse fail to show the "cause" exception,
and I don't know of a reason we need to use AssertionError.
2011-11-25 13:41:38 -05:00
Havoc Pennington
00f8b3d507 Prohibit additional chars in unquoted strings.
The general idea here is to permit future syntax extensions;
as a rule, new syntax can only be added by using one of these
characters that can't be a string.

Backtick ` in particular is in the current ECMAScript drafts
for multiline strings, so supporting multiline strings with
that would be a very natural thing to do.

The other characters added here (^, !, ?, @, *, &) are
more or less arbitrary. &, ! and * have special meaning
in YAML so might be natural ones to use for similar
purposes. ? would have some natural "let this be missing"
meaning, @ is often used in template-like things, and ^
could be used for some unforeseen need.
2011-11-25 12:13:38 -05:00
Havoc Pennington
515a71ba66 Change getMemorySizeInBytes to getBytes and support mebi/gibi/etc. 2011-11-25 11:56:59 -05:00
Havoc Pennington
1d62477338 rename Config.toObject to Config.root
This is clearer about what the object represents and how it relates
to the Config. I didn't name it root() before because it might have
implied some relationship to ConfigRoot. But since ConfigRoot
is now gone, toObject() can have the nicer name root().
2011-11-25 10:44:34 -05:00
Havoc Pennington
7420a3da33 drop the ConfigRoot interface.
This was intended to make resolve() typesafe (only allowed on root objects).
However, in practice it was not safe because it was too easy to create a
root by merging a non-root object into a root object. To fix it, we'd
have to prohibit that (root objects can only merge with other roots).

But it seems simpler to just document that resolving on subtrees
will do the wrong thing, and hopefully it won't be an issue in practice.
2011-11-25 10:34:51 -05:00
Havoc Pennington
afff7c61ef Explain in README how to take advantage of substitutions 2011-11-22 10:53:35 -05:00
Havoc Pennington
0fe4fe19f3 implement ConfigResolveOptions.noSystem() in terms of defaults() 2011-11-21 13:24:01 -05:00
Havoc Pennington
69c5f0d132 linkify a javadoc method reference 2011-11-21 13:23:39 -05:00
Havoc Pennington
d9cac206e1 Clean up the javadocs. 2011-11-21 11:36:58 -05:00
Havoc Pennington
554461eabb exclude "impl" package from the API docs 2011-11-21 09:21:59 -05:00
Havoc Pennington
cabfdf528f remove ParseableInputStream, not used
We only let you parse a reader, so we don't have to
play "what encoding is this stream in"
2011-11-21 09:11:01 -05:00
Havoc Pennington
4619d05cd2 minor tweaks to explanation of classpath includes 2011-11-21 09:10:06 -05:00
Havoc Pennington
ded3604019 remove TODO.txt 2011-11-21 09:09:57 -05:00
Havoc Pennington
2a635478dd fix bug in locating resource includes relative to parent classpath resource
also add various tests related to the parseables
2011-11-21 09:08:43 -05:00
Havoc Pennington
0684ffbea1 make "unresolved subst" exception suggest calling resolve()
this way it's clear what the problem is.
2011-11-19 15:02:12 -05:00
Havoc Pennington
bb43762608 un-hose the test code checking that withFallback is associative and use it more
withFallback didn't used to be reliably associative but now it should be.
2011-11-19 15:01:12 -05:00
Havoc Pennington
f6e3ab48cd make doc task complain about how you should use javadoc 2011-11-18 18:34:30 -05:00
Havoc Pennington
037357c59f Add javadoc task, using self-built jar of javadoc-sbt
javadoc-sbt commit id was 138e530bba49a4d77900415e4c600c45f5ce8667
2011-11-18 18:27:27 -05:00
Havoc Pennington
c16b305c0d add a few more test assertions for withFallback 2011-11-18 17:52:46 -05:00
Havoc Pennington
4f623d9dd5 throw exception if you getInt() and the int is out of range 2011-11-18 17:49:40 -05:00
Havoc Pennington
13362f46b4 fix the example API usage in the README 2011-11-18 17:49:40 -05:00
Havoc Pennington
8b6f4c6156 Refactor withFallback() implementations to share more logic among subtypes
Also add some tests and fix some correctness issues.

If we fall back to a value that has ignoresFallbacks()=true, then we need
to "catch" its ignoresFallbacks.

Don't create new RootConfig objects if the underlying has not changed.

Get rid of ConfigImpl.merge() utility, no longer useful.
2011-11-18 17:46:11 -05:00
Havoc Pennington
7df8e342f6 remove withFallbacks() convenience method
since withFallback() now works properly, it's easy
to do things without withFallbacks().
2011-11-18 17:44:21 -05:00
Havoc Pennington
4b9e5ec325 Fix withFallback() to avoid the mess where it has to be called from the bottom up.
Make ConfigObject have an includeFallbacks flag for whether it has
"ended" and will no longer merge anything.
2011-11-18 17:44:21 -05:00
Havoc Pennington
dc5098d52f put .settings in .gitignore 2011-11-18 17:44:21 -05:00
Havoc Pennington
d4bfdab913 add copyright comment to top of all files 2011-11-18 09:20:02 -05:00
Havoc Pennington
278db76719 add parseFileAnySyntax and parseResourceAnySyntax
To parse a basename.{conf,json,properties}
2011-11-17 23:33:11 -05:00
Havoc Pennington
d700404242 fix AbstractConfigValue.withFallbacks and clean up ConfigDelayedMerge withFallback
Had previously fixed AbstractConfigObject.merge() in the same way. For this
patch, factor out the code from AbstractConfigObject and use it everywhere.

Add some tests for merges with substitutions involved.

Also write some docs for ConfigMergeable explaining the easy way
to do it wrong.
2011-11-17 23:09:29 -05:00
Havoc Pennington
f6395d629d make ConfigException.Null extend Missing instead of WrongType
WrongType makes sense in the context of ConfigObject, but
Missing makes sense in the context of Config.
2011-11-17 21:45:07 -05:00
Havoc Pennington
7cdbe721a9 add ConfigFactory.parseString 2011-11-17 21:33:36 -05:00
Havoc Pennington
31b9ccf983 rename parse() methods to parseFoo()
for clarity and to avoid overload ambiguity
2011-11-17 21:31:45 -05:00