Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
biopet.biopet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Mirrors
biopet.biopet
Commits
6a3a7959
Commit
6a3a7959
authored
May 13, 2016
by
Peter van 't Hof
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added check on unused config values
parent
43253296
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
2 deletions
+56
-2
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/ConfigUtils.scala
...rc/main/scala/nl/lumc/sasc/biopet/utils/ConfigUtils.scala
+27
-0
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/config/Config.scala
.../main/scala/nl/lumc/sasc/biopet/utils/config/Config.scala
+14
-2
biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/ConfigUtilsTest.scala
...est/scala/nl/lumc/sasc/biopet/utils/ConfigUtilsTest.scala
+15
-0
No files found.
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/ConfigUtils.scala
View file @
6a3a7959
...
...
@@ -30,6 +30,33 @@ import scala.collection.JavaConversions._
*
*/
object
ConfigUtils
extends
Logging
{
/**
* This method give back all nested values that does exist in map1 but not in map2
* @param map1 input map
* @param map2 input map
* @return Uniqe map1
*/
def
uniqeKeys
(
map1
:
Map
[
String
,
Any
],
map2
:
Map
[
String
,
Any
])
:
Map
[
String
,
Any
]
=
{
filterEmtpyMapValues
(
map1
.
flatMap
{
case
(
key
,
value
:
Map
[
_
,
_
])
=>
Some
(
key
->
uniqeKeys
(
value
.
asInstanceOf
[
Map
[
String
,
Any
]],
map2
.
getOrElse
(
key
,
Map
()).
asInstanceOf
[
Map
[
String
,
Any
]]))
case
(
key
,
value
)
if
!
map2
.
contains
(
key
)
=>
Some
(
key
->
value
)
case
_
=>
None
})
}
/**
* Filter values that are a map but are empty
* @param map input map
* @return output map
*/
def
filterEmtpyMapValues
(
map
:
Map
[
String
,
Any
])
:
Map
[
String
,
Any
]
=
{
map
.
filter
{
case
(
key
,
value
:
Map
[
_
,
_
])
=>
value
.
nonEmpty
case
_
=>
true
}
}
/**
* Merge 2 maps, when value is in a map in map1 and map2 the value calls recursively this function
* @param map1 Prio over map2
...
...
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/config/Config.scala
View file @
6a3a7959
...
...
@@ -215,6 +215,17 @@ class Config(protected var _map: Map[String, Any],
// Positions where values are found
val
found
=
convertIndexValuesToMap
(
foundCache
.
filter
(!
_
.
_2
.
default
).
toList
.
map
(
x
=>
(
x
.
_2
.
foundIndex
,
x
.
_2
.
value
)))
val
fixed
=
convertIndexValuesToMap
(
fixedCache
.
filter
(!
_
.
_2
.
default
).
toList
.
map
(
x
=>
(
x
.
_2
.
foundIndex
,
x
.
_2
.
value
)))
val
unused
=
uniqeKeys
(
map
,
found
)
def
reportUnused
(
map
:
Map
[
String
,
Any
],
path
:
List
[
String
]
=
Nil
)
:
Unit
=
{
map
.
foreach
{
case
(
key
,
value
:
Map
[
_
,
_
])
=>
reportUnused
(
value
.
asInstanceOf
[
Map
[
String
,
Any
]],
path
:+
key
)
case
(
key
,
value
)
=>
logger
.
warn
(
s
"config key in user config is never used, key: $key"
+
(
if
(
path
.
nonEmpty
)
s
", path: ${path.mkString("
->
")}"
else
""
))
}
}
reportUnused
(
unused
)
// Positions where to start searching
val
effectiveFound
=
convertIndexValuesToMap
(
foundCache
.
filter
(!
_
.
_2
.
default
).
toList
.
map
(
x
=>
(
x
.
_2
.
requestIndex
,
x
.
_2
.
value
)),
Some
(
false
))
...
...
@@ -226,7 +237,8 @@ class Config(protected var _map: Map[String, Any],
val
fullEffective
=
ConfigUtils
.
mergeMaps
(
effectiveFound
,
effectiveDefaultFound
)
val
fullEffectiveWithNotFound
=
ConfigUtils
.
mergeMaps
(
fullEffective
,
notFound
)
writeMapToJsonFile
(
_map
,
"input"
)
writeMapToJsonFile
(
map
,
"input"
)
writeMapToJsonFile
(
unused
,
"unused"
)
writeMapToJsonFile
(
_defaults
,
"defaults"
)
writeMapToJsonFile
(
found
,
"found"
)
writeMapToJsonFile
(
fixed
,
"fixed"
)
...
...
@@ -238,7 +250,7 @@ class Config(protected var _map: Map[String, Any],
writeMapToJsonFile
(
fullEffectiveWithNotFound
,
"effective.full.notfound"
)
}
override
def
toString
:
String
=
_
map
.
toString
()
override
def
toString
:
String
=
map
.
toString
()
}
object
Config
extends
Logging
{
...
...
biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/ConfigUtilsTest.scala
View file @
6a3a7959
...
...
@@ -223,6 +223,21 @@ class ConfigUtilsTest extends TestNGSuite with Matchers {
mergeMaps
(
map2
,
map1
,
(
a
,
b
,
k
)
=>
a
.
toString
+
b
.
toString
)
shouldBe
Map
(
"c"
->
Map
(
"x"
->
"21"
))
mergeMaps
(
map2
,
map2
,
(
a
,
b
,
k
)
=>
a
.
toString
+
b
.
toString
)
shouldBe
Map
(
"c"
->
Map
(
"x"
->
"22"
))
}
@Test
def
testFilterEmtpyMapValues
:
Unit
=
{
ConfigUtils
.
filterEmtpyMapValues
(
Map
(
"bla"
->
"bla"
))
shouldBe
Map
(
"bla"
->
"bla"
)
ConfigUtils
.
filterEmtpyMapValues
(
Map
(
"bla"
->
Map
()))
shouldBe
Map
()
ConfigUtils
.
filterEmtpyMapValues
(
Map
(
"bla"
->
Map
(
"bla"
->
"bla"
)))
shouldBe
Map
(
"bla"
->
Map
(
"bla"
->
"bla"
))
ConfigUtils
.
filterEmtpyMapValues
(
Map
(
"bla"
->
Map
(
"bla"
->
"bla"
)))
shouldBe
Map
(
"bla"
->
Map
(
"bla"
->
"bla"
))
ConfigUtils
.
filterEmtpyMapValues
(
Map
(
"bla"
->
Map
(
"bla"
->
"bla"
),
"bla2"
->
"bla"
))
shouldBe
Map
(
"bla"
->
Map
(
"bla"
->
"bla"
),
"bla2"
->
"bla"
)
}
@Test
def
testUniqeKeys
:
Unit
=
{
ConfigUtils
.
uniqeKeys
(
Map
(
"bla"
->
"bla"
),
Map
(
"bla"
->
"bla"
))
shouldBe
Map
()
ConfigUtils
.
uniqeKeys
(
Map
(
"bla"
->
"bla"
),
Map
())
shouldBe
Map
(
"bla"
->
"bla"
)
ConfigUtils
.
uniqeKeys
(
Map
(
"bla"
->
Map
(
"bla"
->
"bla"
)),
Map
(
"bla"
->
Map
(
"bla"
->
"bla"
)))
shouldBe
Map
()
ConfigUtils
.
uniqeKeys
(
Map
(
"bla"
->
Map
(
"bla"
->
"bla"
)),
Map
(
"bla"
->
Map
()))
shouldBe
Map
(
"bla"
->
Map
(
"bla"
->
"bla"
))
}
}
object
ConfigUtilsTest
{
...
...
Write
Preview
Markdown
is supported
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