You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-09-16 09:26:22 +02:00
fix NonCPS issues (#796)
* remove NonCPS statement * remove NonCPS anntotation * fix typo * remove NonCPS anntotation * remove NonCPS anntotation * remove NonCPS anntotation * remove NonCPS anntotation * remove NonCPS anntotation * remove Iterable * remove mixins * add mixins * add mixins 2 * add mixins 3 * add NonCPS anntotation * remove tokenize * remove closure * remove closure * replace closure * use Object * use Object * use Object * remove object * remove object * add logic * change type * change type * remove NonCPS anntotation * remove NonCPS anntotation * add import
This commit is contained in:
committed by
GitHub
parent
0c3e5f1ea9
commit
7845e18f4d
@@ -22,6 +22,7 @@ class ConfigurationHelper implements Serializable {
|
||||
private Script step
|
||||
private String name
|
||||
private Map validationResults = null
|
||||
private String dependingOn
|
||||
|
||||
private ConfigurationHelper(Script step, Map config){
|
||||
this.config = config ?: [:]
|
||||
@@ -87,22 +88,25 @@ class ConfigurationHelper implements Serializable {
|
||||
return newConfig
|
||||
}
|
||||
|
||||
Map dependingOn(dependentKey){
|
||||
return [
|
||||
mixin: {key ->
|
||||
def parts = tokenizeKey(key)
|
||||
def targetMap = config
|
||||
if(parts.size() > 1) {
|
||||
key = parts.last()
|
||||
parts.remove(key)
|
||||
targetMap = getConfigPropertyNested(config, (parts as Iterable).join(SEPARATOR))
|
||||
}
|
||||
def dependentValue = config[dependentKey]
|
||||
if(targetMap[key] == null && dependentValue && config[dependentValue])
|
||||
targetMap[key] = config[dependentValue][key]
|
||||
return this
|
||||
}
|
||||
]
|
||||
ConfigurationHelper mixin(String key){
|
||||
def parts = tokenizeKey(key)
|
||||
def targetMap = config
|
||||
if(parts.size() > 1) {
|
||||
key = parts.last()
|
||||
parts.remove(key)
|
||||
targetMap = getConfigPropertyNested(config, parts.join(SEPARATOR))
|
||||
}
|
||||
def dependentValue = config[dependingOn]
|
||||
if(targetMap[key] == null && dependentValue && config[dependentValue])
|
||||
targetMap[key] = config[dependentValue][key]
|
||||
|
||||
dependingOn = null
|
||||
return this
|
||||
}
|
||||
|
||||
ConfigurationHelper dependingOn(dependentKey){
|
||||
dependingOn = dependentKey
|
||||
return this
|
||||
}
|
||||
|
||||
ConfigurationHelper addIfEmpty(key, value){
|
||||
@@ -121,8 +125,6 @@ class ConfigurationHelper implements Serializable {
|
||||
return this
|
||||
}
|
||||
|
||||
@NonCPS // required because we have a closure in the
|
||||
// method body that cannot be CPS transformed
|
||||
Map use(){
|
||||
handleValidationFailures()
|
||||
MapUtils.traverse(config, { v -> (v instanceof GString) ? v.toString() : v })
|
||||
@@ -130,8 +132,6 @@ class ConfigurationHelper implements Serializable {
|
||||
return MapUtils.deepCopy(config)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* private */ def getConfigPropertyNested(key) {
|
||||
return getConfigPropertyNested(config, key)
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class ConfigurationHelper implements Serializable {
|
||||
if (config[parts.head()] != null) {
|
||||
|
||||
if (config[parts.head()] in Map && !parts.tail().isEmpty()) {
|
||||
return getConfigPropertyNested(config[parts.head()], (parts.tail() as Iterable).join(SEPARATOR))
|
||||
return getConfigPropertyNested(config[parts.head()], parts.tail().join(SEPARATOR))
|
||||
}
|
||||
|
||||
if (config[parts.head()].class == String) {
|
||||
@@ -193,15 +193,12 @@ class ConfigurationHelper implements Serializable {
|
||||
return this
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
private handleValidationFailures() {
|
||||
if(! validationResults) return
|
||||
if(validationResults.size() == 1) throw validationResults.values().first()
|
||||
String msg = 'ERROR - NO VALUE AVAILABLE FOR: ' +
|
||||
(validationResults.keySet().stream().collect() as Iterable).join(', ')
|
||||
String msg = 'ERROR - NO VALUE AVAILABLE FOR: ' + validationResults.keySet().join(', ')
|
||||
IllegalArgumentException iae = new IllegalArgumentException(msg)
|
||||
validationResults.each { e -> iae.addSuppressed(e.value) }
|
||||
throw iae
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,30 +1,23 @@
|
||||
package com.sap.piper
|
||||
|
||||
import com.cloudbees.groovy.cps.NonCPS
|
||||
|
||||
@API(deprecated = true)
|
||||
class ConfigurationLoader implements Serializable {
|
||||
@NonCPS
|
||||
static Map stepConfiguration(script, String stepName) {
|
||||
return loadConfiguration(script, 'steps', stepName, ConfigurationType.CUSTOM_CONFIGURATION)
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
static Map stageConfiguration(script, String stageName) {
|
||||
return loadConfiguration(script, 'stages', stageName, ConfigurationType.CUSTOM_CONFIGURATION)
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
static Map defaultStepConfiguration(script, String stepName) {
|
||||
return loadConfiguration(script, 'steps', stepName, ConfigurationType.DEFAULT_CONFIGURATION)
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
static Map defaultStageConfiguration(script, String stageName) {
|
||||
return loadConfiguration(script, 'stages', stageName, ConfigurationType.DEFAULT_CONFIGURATION)
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
static Map generalConfiguration(script){
|
||||
try {
|
||||
return script?.commonPipelineEnvironment?.configuration?.general ?: [:]
|
||||
@@ -33,17 +26,14 @@ class ConfigurationLoader implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
static Map defaultGeneralConfiguration(script){
|
||||
return DefaultValueCache.getInstance()?.getDefaultValues()?.general ?: [:]
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
static Map postActionConfiguration(script, String actionName){
|
||||
return loadConfiguration(script, 'postActions', actionName, ConfigurationType.CUSTOM_CONFIGURATION)
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
private static Map loadConfiguration(script, String type, String entryName, ConfigurationType configType){
|
||||
switch (configType) {
|
||||
case ConfigurationType.CUSTOM_CONFIGURATION:
|
||||
|
@@ -1,10 +1,8 @@
|
||||
package com.sap.piper
|
||||
|
||||
import com.cloudbees.groovy.cps.NonCPS
|
||||
|
||||
@API(deprecated = true)
|
||||
class ConfigurationMerger {
|
||||
@NonCPS
|
||||
static Map merge(Map configs, Set configKeys, Map defaults) {
|
||||
Map filteredConfig = configKeys?configs.subMap(configKeys):configs
|
||||
|
||||
@@ -12,7 +10,6 @@ class ConfigurationMerger {
|
||||
MapUtils.pruneNulls(filteredConfig))
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
static Map merge(
|
||||
Map parameters, Set parameterKeys,
|
||||
Map configuration, Set configurationKeys,
|
||||
|
@@ -2,8 +2,6 @@ package com.sap.piper
|
||||
|
||||
import com.sap.piper.MapUtils
|
||||
|
||||
import com.cloudbees.groovy.cps.NonCPS
|
||||
|
||||
@API
|
||||
class DefaultValueCache implements Serializable {
|
||||
private static DefaultValueCache instance
|
||||
@@ -14,7 +12,6 @@ class DefaultValueCache implements Serializable {
|
||||
this.defaultValues = defaultValues
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
static getInstance(){
|
||||
return instance
|
||||
}
|
||||
@@ -23,7 +20,6 @@ class DefaultValueCache implements Serializable {
|
||||
instance = new DefaultValueCache(defaultValues)
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
Map getDefaultValues(){
|
||||
return defaultValues
|
||||
}
|
||||
|
@@ -1,30 +1,25 @@
|
||||
package com.sap.piper
|
||||
|
||||
import com.cloudbees.groovy.cps.NonCPS
|
||||
|
||||
class MapUtils implements Serializable {
|
||||
@NonCPS
|
||||
static boolean isMap(object){
|
||||
return object in Map
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
static Map pruneNulls(Map m) {
|
||||
|
||||
Map result = [:]
|
||||
|
||||
m = m ?: [:]
|
||||
|
||||
for(def e : m.entrySet())
|
||||
if(isMap(e.value))
|
||||
result[e.key] = pruneNulls(e.value)
|
||||
else if(e.value != null)
|
||||
result[e.key] = e.value
|
||||
m.each { key, value ->
|
||||
if(isMap(value))
|
||||
result[key] = pruneNulls(value)
|
||||
else if(value != null)
|
||||
result[key] = value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@NonCPS
|
||||
static Map merge(Map base, Map overlay) {
|
||||
|
||||
Map result = [:]
|
||||
@@ -33,9 +28,9 @@ class MapUtils implements Serializable {
|
||||
|
||||
result.putAll(base)
|
||||
|
||||
for(def e : overlay.entrySet())
|
||||
result[e.key] = isMap(e.value) ? merge(base[e.key], e.value) : e.value
|
||||
|
||||
overlay.each { key, value ->
|
||||
result[key] = isMap(value) ? merge(base[key], value) : value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -46,18 +41,16 @@ class MapUtils implements Serializable {
|
||||
* in <code>m</code> in a recursive manner.
|
||||
* @param strategy Strategy applied to all non-map entries
|
||||
*/
|
||||
@NonCPS
|
||||
static void traverse(Map m, Closure strategy) {
|
||||
|
||||
def updates = [:]
|
||||
for(def e : m.entrySet()) {
|
||||
if(isMap(e.value)) {
|
||||
traverse(e.getValue(), strategy)
|
||||
}
|
||||
else {
|
||||
m.each { key, value ->
|
||||
if(isMap(value)) {
|
||||
traverse(value, strategy)
|
||||
} else {
|
||||
// do not update the map while it is traversed. Depending
|
||||
// on the map implementation the behavior is undefined.
|
||||
updates.put(e.getKey(), strategy(e.getValue()))
|
||||
updates.put(key, strategy(value))
|
||||
}
|
||||
}
|
||||
m.putAll(updates)
|
||||
|
@@ -12,7 +12,6 @@ class Telemetry implements Serializable{
|
||||
|
||||
protected Telemetry(){}
|
||||
|
||||
@NonCPS
|
||||
protected static Telemetry getInstance(){
|
||||
if(!instance) {
|
||||
instance = new Telemetry()
|
||||
|
@@ -181,7 +181,6 @@ def createCommonOptionsMap(publisherName, settings){
|
||||
return result
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
def prepare(parameters){
|
||||
// ensure tool maps are initialized correctly
|
||||
for(String tool : TOOLS){
|
||||
@@ -190,7 +189,6 @@ def prepare(parameters){
|
||||
return parameters
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
def toMap(parameter){
|
||||
if(MapUtils.isMap(parameter))
|
||||
parameter.put('active', parameter.active == null?true:parameter.active)
|
||||
|
@@ -1,7 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.cloudbees.groovy.cps.NonCPS
|
||||
|
||||
import com.sap.piper.GenerateDocumentation
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.JenkinsUtils
|
||||
@@ -173,7 +171,6 @@ def archiveResults(archive, pattern, allowEmpty) {
|
||||
}
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
def prepare(parameters){
|
||||
// ensure tool maps are initialized correctly
|
||||
for(String tool : TOOLS){
|
||||
@@ -182,7 +179,6 @@ def prepare(parameters){
|
||||
return parameters
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
def toMap(parameters){
|
||||
if(MapUtils.isMap(parameters))
|
||||
parameters.put('active', parameters.active == null?true:parameters.active)
|
||||
|
Reference in New Issue
Block a user