Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
biopet.biopet
Commits
b7fe37de
Commit
b7fe37de
authored
Feb 09, 2015
by
Peter van 't Hof
Browse files
Removed required argument for config, now handled by conversions, not a option means required
parent
e3964450
Changes
3
Hide whitespace changes
Inline
Side-by-side
public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Config.scala
View file @
b7fe37de
...
...
@@ -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
=
{
...
...
public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Configurable.scala
View file @
b7fe37de
...
...
@@ -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
)
}
/**
...
...
public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/ConfigUtils.scala
View file @
b7fe37de
...
...
@@ -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
=
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment