From 1227d53a1401462b6cb53a543e0f4e4303093977 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Mon, 5 Dec 2011 22:12:20 -0600 Subject: [PATCH] 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. --- project.properties | 6 +++--- src/main/com/jdbernard/util/SmartConfig.groovy | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/project.properties b/project.properties index 140132f..8192ecd 100644 --- a/project.properties +++ b/project.properties @@ -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 diff --git a/src/main/com/jdbernard/util/SmartConfig.groovy b/src/main/com/jdbernard/util/SmartConfig.groovy index 227444f..3f80289 100644 --- a/src/main/com/jdbernard/util/SmartConfig.groovy +++ b/src/main/com/jdbernard/util/SmartConfig.groovy @@ -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() }