diff --git a/.buildkite/pipeline.extra-steps.gradle b/.buildkite/pipeline.extra-steps.gradle index 3ade4f9..9b54773 100644 --- a/.buildkite/pipeline.extra-steps.gradle +++ b/.buildkite/pipeline.extra-steps.gradle @@ -5,12 +5,13 @@ environment { blockStep 'Wait a minute!' commandStep { + def xVal = 1 plugin 'foobar', [ name: 'Baz', list: [ - [ - x: 1 - ], + { + x = xVal + }, [ x: 2 ] diff --git a/build.gradle b/build.gradle index bb30c27..a7a1ad1 100644 --- a/build.gradle +++ b/build.gradle @@ -70,6 +70,12 @@ buildkite { plugin 'Widen/gradle#v1', { tasks 'check' + systemProperties "com.widen.plugins.buildkite.foo": "bar" + foo = [ + { + bar = 2 + } + ] } } diff --git a/buildSrc/src/main/groovy/com/widen/plugins/buildkite/BuildkitePipeline.groovy b/buildSrc/src/main/groovy/com/widen/plugins/buildkite/BuildkitePipeline.groovy index 79fe91b..73a28fd 100644 --- a/buildSrc/src/main/groovy/com/widen/plugins/buildkite/BuildkitePipeline.groovy +++ b/buildSrc/src/main/groovy/com/widen/plugins/buildkite/BuildkitePipeline.groovy @@ -1,6 +1,5 @@ package com.widen.plugins.buildkite -import groovy.json.JsonBuilder import groovy.json.JsonOutput import org.gradle.api.Project @@ -212,11 +211,7 @@ class BuildkitePipeline implements ConfigurableEnvironment { * syntax for the plugin name. */ void plugin(String name, Object config = null) { - if (config instanceof Closure) { - def builder = new JsonBuilder() - builder.call(config) - config = builder.content - } + config = PluginBuilder.expand(config) // If no version is given and a default version is defined, set it. if (!name.contains("#") && buildkite.pluginVersions.containsKey(name)) { diff --git a/buildSrc/src/main/groovy/com/widen/plugins/buildkite/PluginBuilder.groovy b/buildSrc/src/main/groovy/com/widen/plugins/buildkite/PluginBuilder.groovy new file mode 100644 index 0000000..93a5285 --- /dev/null +++ b/buildSrc/src/main/groovy/com/widen/plugins/buildkite/PluginBuilder.groovy @@ -0,0 +1,48 @@ +package com.widen.plugins.buildkite + +class PluginBuilder { + protected final Map model = [:] + + static Object expand(Object value) { + if (value instanceof Closure) { + def builder = new PluginBuilder() + Closure cloned = (Closure) value.clone() + cloned.delegate = builder + cloned.resolveStrategy = Closure.DELEGATE_FIRST + cloned.call() + value = builder.model + } + + if (value instanceof Map) { + return value.collectEntries { + [(it.key): expand(it.value)] + } + } + + if (value instanceof Iterable) { + return value.collect { + expand(it) + } + } + + return value + } + + Object invokeMethod(String name, Object args) { + Collection expandedArgs = args.collect { + expand(it) + } + + if (expandedArgs.isEmpty()) { + model[name] = null + } else if (expandedArgs.size() == 1) { + model[name] = expandedArgs[0] + } else { + model[name] = expandedArgs + } + } + + void setProperty(String propertyName, Object newValue) { + model[propertyName] = expand(newValue) + } +} diff --git a/buildSrc/src/main/resources/idea.gdsl b/buildSrc/src/main/resources/idea.gdsl new file mode 100644 index 0000000..49993a0 --- /dev/null +++ b/buildSrc/src/main/resources/idea.gdsl @@ -0,0 +1,5 @@ +def ctx = context(pathRegexp: /.*\/pipeline(\.[^.]+)?\.gradle/) + +contributor(ctx) { + delegatesTo(findClass('com.widen.plugins.buildkite.BuildkitePipeline')) +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e0b3fb8..8522e8f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Wed Oct 21 16:26:08 CDT 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME