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
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
...
@@ -27,7 +27,8 @@ import scala.reflect.io.Directory
* @param map Map with value for new config
* @param map Map with value for new config
* @constructor Load config with existing map
* @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"
)
logger
.
debug
(
"Init phase of config"
)
/**
/**
...
@@ -42,14 +43,14 @@ class Config(var map: Map[String, Any]) extends Logging {
...
@@ -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
* Loading a environmental variable as location of config files to merge into the config
* @param valueName Name of value
* @param valueName Name of value
*/
*/
def
loadConfigEnv
(
valueName
:
String
)
{
def
loadConfigEnv
(
valueName
:
String
,
default
:
Boolean
)
{
sys
.
env
.
get
(
valueName
)
match
{
sys
.
env
.
get
(
valueName
)
match
{
case
Some
(
globalFiles
)
=>
{
case
Some
(
globalFiles
)
=>
{
for
(
globalFile
<-
globalFiles
.
split
(
":"
))
{
for
(
globalFile
<-
globalFiles
.
split
(
":"
))
{
val
file
:
File
=
new
File
(
globalFile
)
val
file
:
File
=
new
File
(
globalFile
)
if
(
file
.
exists
)
{
if
(
file
.
exists
)
{
logger
.
info
(
"Loading config file: "
+
file
)
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"
)
}
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 {
...
@@ -61,19 +62,24 @@ class Config(var map: Map[String, Any]) extends Logging {
* Loading default value for biopet
* Loading default value for biopet
*/
*/
def
loadDefaultConfig
()
{
def
loadDefaultConfig
()
{
loadConfigEnv
(
"BIOPET_CONFIG"
)
loadConfigEnv
(
"BIOPET_CONFIG"
,
true
)
}
}
/**
/**
* Merge a json file into the config
* Merge a json file into the config
* @param configFile Location of file
* @param configFile Location of file
*/
*/
def
loadConfigFile
(
configFile
:
File
)
{
def
loadConfigFile
(
configFile
:
File
,
default
:
Boolean
=
false
)
{
val
configMap
=
fileToConfigMap
(
configFile
)
val
configMap
=
fileToConfigMap
(
configFile
)
if
(
default
)
{
if
(
map
.
isEmpty
)
map
=
configMap
if
(
defaults
.
isEmpty
)
defaults
=
configMap
else
map
=
mergeMaps
(
configMap
,
map
)
else
defaults
=
mergeMaps
(
configMap
,
defaults
)
logger
.
debug
(
"New config: "
+
map
)
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
()
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 {
...
@@ -39,7 +39,7 @@ trait Configurable extends ImplicitConversions {
/** Map to store defaults for config */
/** Map to store defaults for config */
def
defaults
:
Map
[
String
,
Any
]
=
{
def
defaults
:
Map
[
String
,
Any
]
=
{
if
(
root
!=
null
)
root
.
defaults
if
(
root
!=
null
)
root
.
defaults
else
Map
()
else
globalConfig
.
defaults
}
}
val
config
=
new
ConfigFunctions
val
config
=
new
ConfigFunctions
...
...
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