Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaquimmnetto committed Dec 13, 2023
1 parent 2f64c48 commit c1d78ad
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/net/wooga/jenkins/pipeline/assemble/Assemblers.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class Assemblers {
gradle.wrapper("-Prelease.stage=${releaseType.trim()} -Prelease.scope=${releaseScope.trim()} assemble")
}
}
return jenkins.findFiles(glob: "$workingDir/build/outputs/*.nupkg")[0]
def artifacts = jenkins.findFiles(glob: "$workingDir/build/outputs/*.nupkg")
return artifacts? artifacts[0]: null
}

}
2 changes: 1 addition & 1 deletion src/net/wooga/jenkins/pipeline/config/GradleArgs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GradleArgs {


static GradleArgs fromConfigMap(Map config) {
def environment = new EnvVars((config.gradleEnvironment ?: [:]) as Map<String, ?>)
def environment = EnvVars.fromList((config.gradleEnvironment ?: []) as List<?>)
def showStackTraces = (config.showStackTrace ?: false) as boolean
def refreshDependencies = (config.refreshDependencies ?: false) as boolean
return new GradleArgs(environment, config.logLevel as String, showStackTraces, refreshDependencies)
Expand Down
43 changes: 19 additions & 24 deletions src/net/wooga/jenkins/pipeline/model/EnvVars.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,34 @@ package net.wooga.jenkins.pipeline.model

class EnvVars {

final Map<String, Closure<String>> environment
final List<?> environment

EnvVars(Map<String, ?> environment) {
this.environment = lazifyMap(environment)
static EnvVars fromList(List<?> env) {
return new EnvVars(env)
}

static Map<String, Closure<String>> lazifyMap(Map<String, ?> env) {
Map<String, Closure<String>> lazyMap = [:]
for(String key : env.keySet()) {
if(env[key] instanceof Closure) {
lazyMap.put(key, env[key])
} else {
def value = env.get(key)
lazyMap.put(key, { -> value })
}
}
return lazyMap
EnvVars(List<?> environment) {
this.environment = environment
}


List<String> resolveAsStrings() {
List<String> result = []
for(String key : environment.keySet()) {
Closure<String> lazyValue = environment[key]
def value = lazyValue?.call()
if(value != null) {
result += ["$key=$value"]
}
return environment.collect {
resolveString(it)
}
}

def resolveString(Object obj) {
if(obj instanceof Closure) {
return obj.call().toString()
}
return result
return obj.toString()
}

Closure<String> getAt(String key) {
environment[key]
Object getAt(String key) {
environment.collect{resolveString(it).split("=")}.find{
it[0] == key
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.wooga.jenkins.pipeline.config

import net.wooga.jenkins.pipeline.model.EnvVars
import spock.lang.Specification
import spock.lang.Unroll

Expand All @@ -18,10 +19,10 @@ class GradleArgsSpec extends Specification {

where:
logLevel | stackTrace | refreshDeps | expected
null | null | null | new GradleArgs(null, false, false)
"info" | false | false | new GradleArgs("info", false, false)
"quiet" | true | false | new GradleArgs("quiet", true, false)
"quiet" | false | true | new GradleArgs("quiet", false, true)
null | null | null | new GradleArgs(EnvVars.fromList([]), null, false, false)
"info" | false | false | new GradleArgs(EnvVars.fromList([]), "info", false, false)
"quiet" | true | false | new GradleArgs(EnvVars.fromList([]), "quiet", true, false)
"quiet" | false | true | new GradleArgs(EnvVars.fromList([]), "quiet", false, true)
}

}
2 changes: 1 addition & 1 deletion test/groovy/scripts/BuildUnityWdkV2Spec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class BuildUnityWdkV2Spec extends DeclarativeJenkinsSpec {
"assemble")

and: "has set up environment"
def env = usedEnvironments.first()
def env = usedEnvironments[2]
hasBaseEnvironment(env, "level")
env.UNITY_LOG_CATEGORY == "build"
env.UNITY_PACKAGE_MANAGER == "upm"
Expand Down
10 changes: 5 additions & 5 deletions test/groovy/scripts/GradleWrapperSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class GradleWrapperSpec extends DeclarativeJenkinsSpec {
usedEnvironments.last() == expectedEnv

where:
givenEnv | expectedEnv
[:] | [:]
[ENV: "eager", EAGER: "eager"] | ["ENV": "eager", "EAGER": "eager"]
[EAGER: "eager", LAZY: { "lazy" }] | ["EAGER": "eager", "LAZY": "lazy"]
[ENV: { "lazy" }, LAZY: { "lazy" }] | ["ENV": "lazy", "LAZY": "lazy"]
givenEnv | expectedEnv
[:] | [:]
["ENV=eager", "EAGER=eager"] | ["ENV": "eager", "EAGER": "eager"]
["EAGER=eager", { "LAZY=lazy" }] | ["EAGER": "eager", "LAZY": "lazy"]
[{ "ENV=lazy" }, { "LAZY=lazy" }] | ["ENV": "lazy", "LAZY": "lazy"]
}

@Unroll
Expand Down
6 changes: 3 additions & 3 deletions vars/gradleWrapper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import net.wooga.jenkins.pipeline.model.Gradle
/**
* execute gradlew or gradlew.bat based on current os
*/
def call(String command, Boolean returnStatus = false, Boolean returnStdout = false, Map<String, ?> environment=[:]) {
def call(String command, Boolean returnStatus = false, Boolean returnStdout = false, List<?> environment=[]) {
def gradle = Gradle.fromJenkins(this,
new EnvVars(environment),
EnvVars.fromList(environment),
params.LOG_LEVEL?: env.LOG_LEVEL as String,
params.STACK_TRACE? params.STACK_TRACE as Boolean : false,
params.REFRESH_DEPENDENCIES? params.REFRESH_DEPENDENCIES as Boolean : false)
Expand All @@ -18,7 +18,7 @@ def call(Map args) {
call(args.command?.toString(),
(args.returnStatus?: false) as Boolean,
(args.returnStdout?: false) as Boolean,
(args.environment?: [:]) as Map<String, ?>
(args.environment?: []) as List<?>
)
}

Expand Down

0 comments on commit c1d78ad

Please sign in to comment.