From b7fe37de45991d958ca9eb9feff843b1fe039588 Mon Sep 17 00:00:00 2001 From: Peter van 't Hof <p.j.van_t_hof@lumc.nl> Date: Mon, 9 Feb 2015 10:41:34 +0100 Subject: [PATCH] Removed required argument for config, now handled by conversions, not a option means required --- .../nl/lumc/sasc/biopet/core/config/Config.scala | 7 ++++--- .../lumc/sasc/biopet/core/config/Configurable.scala | 12 ++---------- .../nl/lumc/sasc/biopet/utils/ConfigUtils.scala | 4 +++- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Config.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Config.scala index 4ea65cb5a..0e404dd5c 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Config.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Config.scala @@ -133,11 +133,12 @@ class Config(var map: Map[String, Any]) extends Logging { */ protected[config] def apply(module: String, path: List[String], key: String, default: Any = null, freeVar: Boolean = true): ConfigValue = { val requestedIndex = ConfigValueIndex(module, path, key, freeVar) - if (contains(requestedIndex)) return foundCache(requestedIndex) + if (contains(requestedIndex)) foundCache(requestedIndex) else if (default != null) { defaultCache += (requestedIndex -> ConfigValue(requestedIndex, null, default, freeVar)) - return defaultCache(requestedIndex) - } else throw new IllegalStateException("Value in config could not be found but it seems required, index: " + requestedIndex) + defaultCache(requestedIndex) + } else ConfigValue(requestedIndex, null, null, freeVar) + //else throw new IllegalStateException("Value in config could not be found but it seems required, index: " + requestedIndex) } def writeReport(id: String, directory: String): Unit = { diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Configurable.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Configurable.scala index 54e6dfd17..774b15d2d 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Configurable.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Configurable.scala @@ -79,7 +79,6 @@ trait Configurable extends ImplicitConversions { * @param key Name of value * @param default Default value if not found * @param submodule Adds to the path - * @param required Default false, if true and value is not found this function will raise an exception * @param freeVar Default true, if set false value must exist in module * @param sample Default null, when set path is prefixed with "samples" -> "sampleID" * @param library Default null, when set path is prefixed with "libraries" -> "libraryID" @@ -88,7 +87,6 @@ trait Configurable extends ImplicitConversions { def apply(key: String, default: Any = null, submodule: String = null, - required: Boolean = false, freeVar: Boolean = true, sample: String = null, library: String = null): ConfigValue = { @@ -100,14 +98,8 @@ trait Configurable extends ImplicitConversions { val value = Config.getValueFromMap(defaults.toMap, ConfigValueIndex(m, p, key, freeVar)) if (value.isDefined) value.get.value else default } - if (!contains(key, submodule, freeVar, sample = s, library = l) && d == null) { - if (required) { - Logging.logger.error("Value in config could not be found but it is required, key: " + key + " module: " + m + " path: " + p) - throw new IllegalStateException("Value in config could not be found but it is required, key: " + key + " module: " + m + " path: " + p) - } else return null - } - if (d == null) return Config.global(m, p, key, freeVar = freeVar) - else return Config.global(m, p, key, d, freeVar) + if (d == null) Config.global(m, p, key, freeVar = freeVar) + else Config.global(m, p, key, d, freeVar) } /** diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/ConfigUtils.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/ConfigUtils.scala index cef97ffaa..c3a79b24c 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/ConfigUtils.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/ConfigUtils.scala @@ -332,7 +332,9 @@ object ConfigUtils extends Logging { private def requiredValue(value: ConfigValue): Unit = { if (!valueExists(value)) - throw new IllegalStateException("Value does not exist but is required, key: '" + value.requestIndex.key + "'") + throw new IllegalStateException("Value does not exist but is required, key: " + value.requestIndex.key + + " module: " + value.requestIndex.module + + (if (value.requestIndex.path != Nil) " path: " + value.requestIndex.path.mkString("->") else "")) } private def valueExists(value: ConfigValue): Boolean = { -- GitLab