From 5fe76eb9dc066c41936924e7c3fcf94ec539aad7 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Mon, 19 Feb 2018 12:53:08 +0100 Subject: [PATCH] Replace usage of lists for denoting keys by sets. The characteristics of a list are o the order of the entries is significant o duplicates are allowed The characteristics of a set are o the order is not significant o duplicates are not allowed. When describing keys for a step the characteristics of a set applies here, whereas the characteristics of a list does not apply. --- src/com/sap/piper/ConfigurationMerger.groovy | 16 ++++++++-------- .../com/sap/piper/ConfigurationMergerTest.groovy | 14 +++++++------- vars/artifactSetVersion.groovy | 4 ++-- vars/checksPublishResults.groovy | 4 ++-- vars/influxWriteData.groovy | 4 ++-- vars/mavenExecute.groovy | 4 ++-- vars/mtaBuild.groovy | 6 +++--- vars/neoDeploy.groovy | 4 ++-- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/com/sap/piper/ConfigurationMerger.groovy b/src/com/sap/piper/ConfigurationMerger.groovy index 05ee43f90..9f6c2c220 100644 --- a/src/com/sap/piper/ConfigurationMerger.groovy +++ b/src/com/sap/piper/ConfigurationMerger.groovy @@ -6,7 +6,7 @@ import com.sap.piper.MapUtils class ConfigurationMerger { @NonCPS - def static merge(Map configs, List configKeys, Map defaults) { + def static merge(Map configs, Set configKeys, Map defaults) { Map filteredConfig = configKeys?configs.subMap(configKeys):configs Map merged = [:] @@ -23,8 +23,8 @@ class ConfigurationMerger { @NonCPS def static merge( - Map parameters, List parameterKeys, - Map configuration, List configurationKeys, + Map parameters, Set parameterKeys, + Map configuration, Set configurationKeys, Map defaults=[:] ){ Map merged @@ -34,9 +34,9 @@ class ConfigurationMerger { } @NonCPS - def static mergeWithPipelineData(Map parameters, List parameterKeys, + def static mergeWithPipelineData(Map parameters, Set parameterKeys, Map pipelineDataMap, - Map configurationMap, List configurationKeys, + Map configurationMap, Set configurationKeys, Map stepDefaults=[:] ){ Map merged @@ -49,9 +49,9 @@ class ConfigurationMerger { @NonCPS def static merge( - Map parameters, List parameterKeys, - Map generalConfigurationMap, List generalConfigurationKeys, Map generalConfigurationDefaults, - Map stepConfigurationMap, List stepConfigurationKeys, Map stepConfigurationDefaults=[:] + Map parameters, Set parameterKeys, + Map generalConfigurationMap, Set generalConfigurationKeys, Map generalConfigurationDefaults, + Map stepConfigurationMap, Set stepConfigurationKeys, Map stepConfigurationDefaults=[:] ){ Map merged Map mergedStepConfiguration = merge(stepConfigurationMap, stepConfigurationKeys, stepConfigurationDefaults) diff --git a/test/groovy/com/sap/piper/ConfigurationMergerTest.groovy b/test/groovy/com/sap/piper/ConfigurationMergerTest.groovy index 125b18712..64d3c7e3a 100644 --- a/test/groovy/com/sap/piper/ConfigurationMergerTest.groovy +++ b/test/groovy/com/sap/piper/ConfigurationMergerTest.groovy @@ -9,9 +9,9 @@ class ConfigurationMergerTest { void testMerge(){ Map defaults = [dockerImage: 'mvn'] Map parameters = [goals: 'install', flags: ''] - List parameterKeys = ['flags'] + Set parameterKeys = ['flags'] Map configuration = [flags: '-B'] - List configurationKeys = ['flags'] + Set configurationKeys = ['flags'] Map merged = ConfigurationMerger.merge(parameters, parameterKeys, configuration, configurationKeys, defaults) Assert.assertEquals('mvn', merged.dockerImage) Assert.assertNull(merged.goals) @@ -22,7 +22,7 @@ class ConfigurationMergerTest { void testMergeParameterWithDefault(){ Map defaults = [nonErpDestinations: []] Map parameters = [nonErpDestinations: null] - List parameterKeys = ['nonErpDestinations'] + Set parameterKeys = ['nonErpDestinations'] Map merged = ConfigurationMerger.merge(parameters, parameterKeys, defaults) Assert.assertEquals([], merged.nonErpDestinations) } @@ -31,9 +31,9 @@ class ConfigurationMergerTest { void testMergeCustomPipelineValues(){ Map defaults = [dockerImage: 'mvn'] Map parameters = [goals: 'install', flags: ''] - List parameterKeys = ['flags'] + Set parameterKeys = ['flags'] Map configuration = [flags: '-B'] - List configurationKeys = ['flags'] + Set configurationKeys = ['flags'] Map pipelineDataMap = [artifactVersion: '1.2.3', flags: 'test'] Map merged = ConfigurationMerger.mergeWithPipelineData(parameters, parameterKeys, pipelineDataMap, configuration, configurationKeys, defaults) Assert.assertEquals('', merged.flags) @@ -44,9 +44,9 @@ class ConfigurationMergerTest { void testMergeDeepStructure(){ Map defaults = [fruits: [apples: 1, oranges: 10, bananaaas: 0]] Map configuration = [fruits: [bananaaas: 50, cucumbers: 1000]] - List configurationKeys = ['fruits'] + Set configurationKeys = ['fruits'] Map parameters = [fruits: [apples: 18], veggie: []] - List parameterKeys = ['fruits'] + Set parameterKeys = ['fruits'] Map merged = ConfigurationMerger.merge(parameters, parameterKeys, configuration, configurationKeys, defaults) Assert.assertEquals(50, merged.fruits.bananaaas) Assert.assertEquals(18, merged.fruits.apples) diff --git a/vars/artifactSetVersion.groovy b/vars/artifactSetVersion.groovy index 8b75014d8..107880dd3 100644 --- a/vars/artifactSetVersion.groovy +++ b/vars/artifactSetVersion.groovy @@ -29,7 +29,7 @@ def call(Map parameters = [:]) { final Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, stepName) final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, stepName) - List parameterKeys = [ + Set parameterKeys = [ 'artifactType', 'buildTool', 'dockerVersionSource', @@ -47,7 +47,7 @@ def call(Map parameters = [:]) { Map pipelineDataMap = [ gitCommitId: gitUtils.getGitCommitId() ] - List stepConfigurationKeys = [ + Set stepConfigurationKeys = [ 'artifactType', 'buildTool', 'dockerVersionSource', diff --git a/vars/checksPublishResults.groovy b/vars/checksPublishResults.groovy index 641741dea..a4dfbcb41 100644 --- a/vars/checksPublishResults.groovy +++ b/vars/checksPublishResults.groovy @@ -7,7 +7,7 @@ import com.sap.piper.MapUtils import groovy.transform.Field @Field def STEP_NAME = 'checksPublishResults' -@Field List TOOLS = [ +@Field Set TOOLS = [ 'aggregation', 'tasks', 'pmd', 'cpd', 'findbugs', 'checkstyle', 'eslint', 'pylint' ] @@ -24,7 +24,7 @@ def call(Map parameters = [:]) { prepareDefaultValues script: script prepare(parameters) - List configKeys = TOOLS.plus('archive') + Set configKeys = TOOLS.plus('archive') final Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, STEP_NAME) final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, STEP_NAME) diff --git a/vars/influxWriteData.groovy b/vars/influxWriteData.groovy index d4f8b3751..168c55782 100644 --- a/vars/influxWriteData.groovy +++ b/vars/influxWriteData.groovy @@ -17,7 +17,7 @@ def call(Map parameters = [:]) { final Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, stepName) final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, stepName) - List parameterKeys = [ + Set parameterKeys = [ 'artifactVersion', 'influxServer', 'influxPrefix' @@ -25,7 +25,7 @@ def call(Map parameters = [:]) { Map pipelineDataMap = [ artifactVersion: commonPipelineEnvironment.getArtifactVersion() ] - List stepConfigurationKeys = [ + Set stepConfigurationKeys = [ 'influxServer', 'influxPrefix' ] diff --git a/vars/mavenExecute.groovy b/vars/mavenExecute.groovy index cbd1a43a6..c43f78b56 100644 --- a/vars/mavenExecute.groovy +++ b/vars/mavenExecute.groovy @@ -11,7 +11,7 @@ def call(Map parameters = [:]) { final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, 'mavenExecute') - List parameterKeys = [ + Set parameterKeys = [ 'dockerImage', 'globalSettingsFile', 'projectSettingsFile', @@ -21,7 +21,7 @@ def call(Map parameters = [:]) { 'm2Path', 'defines' ] - List stepConfigurationKeys = [ + Set stepConfigurationKeys = [ 'dockerImage', 'globalSettingsFile', 'projectSettingsFile', diff --git a/vars/mtaBuild.groovy b/vars/mtaBuild.groovy index 6f92c8946..9fc1b9170 100644 --- a/vars/mtaBuild.groovy +++ b/vars/mtaBuild.groovy @@ -6,16 +6,16 @@ def call(Map parameters = [:]) { def stepName = 'mtaBuild' - List parameterKeys = [ + Set parameterKeys = [ 'buildTarget', 'mtaJarLocation' ] - List stepConfigurationKeys = [ + Set stepConfigurationKeys = [ 'buildTarget' ] - List generalConfigurationKeys = [ + Set generalConfigurationKeys = [ 'mtaJarLocation' ] diff --git a/vars/neoDeploy.groovy b/vars/neoDeploy.groovy index 4e53463e3..dc35be6b3 100644 --- a/vars/neoDeploy.groovy +++ b/vars/neoDeploy.groovy @@ -7,7 +7,7 @@ def call(parameters = [:]) { def stepName = 'neoDeploy' - List parameterKeys = [ + Set parameterKeys = [ 'applicationName', 'archivePath', 'account', @@ -27,7 +27,7 @@ def call(parameters = [:]) { 'warAction' ] - List stepConfigurationKeys = [ + Set stepConfigurationKeys = [ 'account', 'dockerEnvVars', 'dockerImage',