Commit Graph

265 Commits

Author SHA1 Message Date
Havoc Pennington
38fb8d6834 move publish settings to config/ project instead of global 2011-11-30 16:35:41 -05:00
Havoc Pennington
2365db970e Get the build ready for publishing releases
Not sure this is quite right, but closer than before.
2011-11-30 16:30:03 -05:00
Havoc Pennington
0ff5f1ff8c README code example fix 2011-11-30 11:18:46 -05:00
Havoc Pennington
2abd5ad09c minor README tweaks 2011-11-30 10:52:01 -05:00
Havoc Pennington
6d8e476dcf remove two "future directions" from the README
I don't think they made sense:

- "fallback lists" in substitutions can already be done another way
- the "delete" operator isn't clearly useful and feels imperative
  rather than declarative
2011-11-30 10:44:47 -05:00
Havoc Pennington
9578a79538 Better handle includes for files and classpaths
- support "/" to get an absolute file or resource
- fall back to a resource if there's no file
2011-11-30 10:35:21 -05:00
Havoc Pennington
5cc18bdc03 handle file: URLs the same as files; support including absolute filenames 2011-11-30 09:43:11 -05:00
Havoc Pennington
9689abd781 make ConfigException abstract 2011-11-30 09:24:46 -05:00
Havoc Pennington
9f9b351f0e add some more javadoc to ConfigException.java 2011-11-30 09:15:49 -05:00
Havoc Pennington
4896b7d75d When using "singleton holder" catch ExceptionInInitializerError and pull out the ConfigException if any 2011-11-30 09:01:48 -05:00
Havoc Pennington
62628b6404 some README cleanups 2011-11-30 01:55:56 -05:00
Havoc Pennington
9b44709c89 support -Dconfig.resource, -Dconfig.file, -Dconfig.url system props
These override application.{conf,json,properties} for ConfigFactory.load()
2011-11-30 01:51:36 -05:00
Havoc Pennington
a3988e9b03 improve path rendering to avoid quoting hyphenated keys like foo-bar 2011-11-29 20:51:57 -05:00
Havoc Pennington
81ce6038c7 remove special-case fallback to system props in substitutions.
The earlier change to make ${user.home} in a file included underneath
"foo" search both ${foo.user.home} and then ${user.home}, means
that even in included files system props are picked up just fine
as long as they were merged into the root config. So there is no
longer any need to have a special-case fallback to system properties.

This leaves ConfigResolveOptions as a really complex way to pass
in a single bool, but of course the point is to allow for future
extension.
2011-11-29 15:46:55 -05:00
Havoc Pennington
ad6fd0f156 add more tests for substitution behavior in included files 2011-11-29 15:39:27 -05:00
Havoc Pennington
53193a48d3 Search for substitutions both included-file-relative and root-relative
This should lay the groundwork for removing the special case fallback
to system properties, and allows included files to look at the reference
configuration.
2011-11-29 15:21:13 -05:00
Havoc Pennington
baa126633a Move ConfigMergeable.toValue to be private, as MergeableValue.toFallbackValue
Avoids confusion because ConfigValue.toValue was pointless and
Config.toValue was not as clear as Config.root (plus having two ways
to do it on Config was strange).

This change does require a cast in the withFallback implementation but
we already have the analogous pattern all over the place (i.e. assuming that
instances of the public interfaces are always instances of our private
implementations).
2011-11-29 14:30:33 -05:00
Havoc Pennington
b50ed75f92 add missing "final" to SimpleConfig, was an oversight 2011-11-29 12:11:39 -05:00
Havoc Pennington
444219bb17 Optimize no-op object merges by throwing away the new HashMap and using the old one
One side effect of this is that if an object merge does nothing, the ConfigOrigin
for the fallback is discarded instead of merged in, but I think that's OK.
2011-11-29 10:02:26 -05:00
Havoc Pennington
4964fdcbf0 In the examples, also show using the config for the app itself 2011-11-29 09:09:50 -05:00
Havoc Pennington
9af5a67d6c fix api doc note about setUseSystemProperties doing nothing
This is a mess, I earlier added a note to the README about needing
to fix it.
2011-11-29 08:56:25 -05:00
Havoc Pennington
a840c2599d Rename getMemorySizeInBytesList to getBytesList to match getBytes 2011-11-29 08:44:07 -05:00
Havoc Pennington
4f3a91fd86 document why substitutions special-case system props
currently needed for files that are included in other files.

not really happy with how this works now, but documenting it
as a starting point.

maybe to force a substitution to resolve from the root we could
start it with a period? ${.this.is.a.root.prop} ?
2011-11-28 15:11:26 -05:00
Havoc Pennington
00a19f3f5d fix a typo in a comment in simple-lib 2011-11-28 12:52:44 -05:00
Havoc Pennington
130544f98a fix simple-lib to call checkValid() specifying a path. 2011-11-28 12:52:13 -05:00
Havoc Pennington
cfb4887d50 use a cached singleton for ConfigFactory.load() 2011-11-28 12:46:11 -05:00
Havoc Pennington
9aae9e2a80 Overhaul ConfigFactory API and ConfigFactory.load().
Update all docs and tests.

Add example library and application.
2011-11-28 12:23:21 -05:00
Havoc Pennington
e6ee3d6232 mention using several env vars for one setting in README 2011-11-28 01:37:29 -05:00
Havoc Pennington
789930cd8e Implement Config.checkValid() to check against a reference config
This allows verifying that a config has all the keys it's supposed
to have, and also that they have plausible value types. It uses
a reference config as a kind of very loose schema.

Another benefit is that it can give users a big batch of error
messages at once, rather than one at a time via exceptions
when config settings are used.

Because the reference config is not really a schema, users of
checkValid() may have to tune its behavior by removing some
things from the reference config used for validation, or
ignoring certain errors, or doing additional validation
on their own. But checkValid() is a good basic validator
for all your simple settings and if you have complex
settings you can write additional code to support them
while still using checkValid() for the simple ones.
2011-11-28 01:14:31 -05:00
Havoc Pennington
6692dba893 make SimpleConfigList.get return an AbstractConfigValue
preserve the detailed type that we know for the subclass
2011-11-28 01:13:18 -05:00
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