Small updates to SmartConfig.

* Changed the behavior of SmartConfig when setting file type properties. Now it
  tries to coerce the given value into a File object if it is not already a File
  object.
* Changed the behavior of SmartConfig when retrieving a property without
  specifying a default value. Now it returns null if the property is not set and
  no default is given.
This commit is contained in:
Jonathan Bernard 2011-12-05 22:12:20 -06:00
parent 08810e88ed
commit 1227d53a14
2 changed files with 9 additions and 8 deletions

View File

@ -1,6 +1,6 @@
#Tue, 25 Jan 2011 09:33:59 -0600
#Mon, 05 Dec 2011 22:11:12 -0600
name=jdb-util
version=1.3
version=1.4
lib.local=true
build.number=3
build.number=8

View File

@ -37,15 +37,15 @@ public class SmartConfig {
catch (Exception e) { log.warn("Cannot save config file.", e) }
}
def getProperty(String name) { getProperty(name, "") }
def getProperty(String name) { getProperty(name, null) }
def getProperty(String name, Object defVal) {
log.trace("Looking up {}", name)
def val = props.getProperty(name)
def val = props[name]
if (val == null) {
if (val == null && defVal != null) {
log.trace("Doesn't exists, setting with given default")
val = defVal
@ -83,9 +83,10 @@ public class SmartConfig {
if (name ==~ /.*([dD]irectory|[dD]ir|[fF]ile)/) {
log.trace("Interpreting as a file/directory.")
props."$name" = value.canonicalPath
if (!(value instanceof File)) { value = new File(value) }
props[name] = value.canonicalPath
} else {
props."$name" = value.toString()
props[name] = value.toString()
}
save()
}