Skip to content

Commit

Permalink
Support array syntax for lists of things
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebind committed Oct 21, 2020
1 parent 363095f commit 464596d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 11 deletions.
7 changes: 4 additions & 3 deletions .buildkite/pipeline.extra-steps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ environment {
blockStep 'Wait a minute!'

commandStep {
def xVal = 1
plugin 'foobar', [
name: 'Baz',
list: [
[
x: 1
],
{
x = xVal
},
[
x: 2
]
Expand Down
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ buildkite {

plugin 'Widen/gradle#v1', {
tasks 'check'
systemProperties "com.widen.plugins.buildkite.foo": "bar"
foo = [
{
bar = 2
}
]
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.widen.plugins.buildkite

import groovy.json.JsonBuilder
import groovy.json.JsonOutput
import org.gradle.api.Project

Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.widen.plugins.buildkite

class PluginBuilder {
protected final Map<String, Object> 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)
}
}
5 changes: 5 additions & 0 deletions buildSrc/src/main/resources/idea.gdsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def ctx = context(pathRegexp: /.*\/pipeline(\.[^.]+)?\.gradle/)

contributor(ctx) {
delegatesTo(findClass('com.widen.plugins.buildkite.BuildkitePipeline'))
}
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 464596d

Please sign in to comment.