Skip to content
GitLab
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
8fc4872e
Commit
8fc4872e
authored
Apr 06, 2015
by
Peter van 't Hof
Browse files
Switch defaults from BIOPET_CONFIG env to a defaults var
parent
d4b8ed2c
Changes
2
Hide whitespace changes
Inline
Side-by-side
public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Config.scala
View file @
8fc4872e
...
...
@@ -27,7 +27,8 @@ import scala.reflect.io.Directory
* @param map Map with value for new config
* @constructor Load config with existing map
*/
class
Config
(
var
map
:
Map
[
String
,
Any
])
extends
Logging
{
class
Config
(
var
map
:
Map
[
String
,
Any
],
protected
[
core
]
var
defaults
:
Map
[
String
,
Any
]
=
Map
())
extends
Logging
{
logger
.
debug
(
"Init phase of config"
)
/**
...
...
@@ -42,14 +43,14 @@ class Config(var map: Map[String, Any]) extends Logging {
* Loading a environmental variable as location of config files to merge into the config
* @param valueName Name of value
*/
def
loadConfigEnv
(
valueName
:
String
)
{
def
loadConfigEnv
(
valueName
:
String
,
default
:
Boolean
)
{
sys
.
env
.
get
(
valueName
)
match
{
case
Some
(
globalFiles
)
=>
{
for
(
globalFile
<-
globalFiles
.
split
(
":"
))
{
val
file
:
File
=
new
File
(
globalFile
)
if
(
file
.
exists
)
{
logger
.
info
(
"Loading config file: "
+
file
)
loadConfigFile
(
file
)
loadConfigFile
(
file
,
default
)
}
else
logger
.
warn
(
valueName
+
" value found but file '"
+
file
+
"' does not exist, no global config is loaded"
)
}
}
...
...
@@ -61,19 +62,24 @@ class Config(var map: Map[String, Any]) extends Logging {
* Loading default value for biopet
*/
def
loadDefaultConfig
()
{
loadConfigEnv
(
"BIOPET_CONFIG"
)
loadConfigEnv
(
"BIOPET_CONFIG"
,
true
)
}
/**
* Merge a json file into the config
* @param configFile Location of file
*/
def
loadConfigFile
(
configFile
:
File
)
{
def
loadConfigFile
(
configFile
:
File
,
default
:
Boolean
=
false
)
{
val
configMap
=
fileToConfigMap
(
configFile
)
if
(
map
.
isEmpty
)
map
=
configMap
else
map
=
mergeMaps
(
configMap
,
map
)
logger
.
debug
(
"New config: "
+
map
)
if
(
default
)
{
if
(
defaults
.
isEmpty
)
defaults
=
configMap
else
defaults
=
mergeMaps
(
configMap
,
defaults
)
logger
.
debug
(
"New defaults: "
+
defaults
)
}
else
{
if
(
map
.
isEmpty
)
map
=
configMap
else
map
=
mergeMaps
(
configMap
,
map
)
logger
.
debug
(
"New config: "
+
map
)
}
}
protected
[
config
]
var
notFoundCache
:
List
[
ConfigValueIndex
]
=
List
()
...
...
public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Configurable.scala
View file @
8fc4872e
...
...
@@ -39,7 +39,7 @@ trait Configurable extends ImplicitConversions {
/** Map to store defaults for config */
def
defaults
:
Map
[
String
,
Any
]
=
{
if
(
root
!=
null
)
root
.
defaults
else
Map
()
else
globalConfig
.
defaults
}
val
config
=
new
ConfigFunctions
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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