From bba1473dd36e9dc4e5e78777411b1dcbf28e6161 Mon Sep 17 00:00:00 2001 From: Manfred Endres <2523575+Larusso@users.noreply.github.com> Date: Fri, 30 Mar 2018 07:07:31 +0000 Subject: [PATCH] Fix set of lazy version parameter for paketPack (#32) Description =========== This change makes it possible to set the `version` parameter in the task `PaketPack` as a lazy value (`Closure`, eg `Callable`). Changes ======= * ![FIX] version parameter in `PaketPack` --- .../pack/PaketPackIntegrationSpec.groovy | 44 +++++++++++++++++++ .../gradle/paket/pack/tasks/PaketPack.groovy | 19 +++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/integrationTest/groovy/wooga/gradle/paket/pack/PaketPackIntegrationSpec.groovy b/src/integrationTest/groovy/wooga/gradle/paket/pack/PaketPackIntegrationSpec.groovy index 82ed0b1..7b7bb61 100644 --- a/src/integrationTest/groovy/wooga/gradle/paket/pack/PaketPackIntegrationSpec.groovy +++ b/src/integrationTest/groovy/wooga/gradle/paket/pack/PaketPackIntegrationSpec.groovy @@ -204,6 +204,50 @@ class PaketPackIntegrationSpec extends PaketIntegrationDependencyFileSpec { taskToRun << ["paketPack-WoogaTest", "buildNupkg", "assemble"] } + //https://github.com/wooga/atlas-paket/issues/31 + @Unroll + def "evaluates lazy version #taskToRun"(String taskToRun) { + given: "a custom template file without version" + paketTemplateFile.text = "" + paketTemplateFile << """ + type file + id $packageID + authors Wooga + owners Wooga + description + Empty nuget package. + """.stripIndent() + + and: "a build file with version set in pack task" + buildFile.text = "" + buildFile << """ + group = 'test' + ${applyPlugin(PaketPackPlugin)} + + project.tasks."paketPack-WoogaTest" { + version = {"$version"} + } + """.stripIndent() + + + and: "a future output file" + def outputFile = new File(new File(new File(projectDir, 'build'), "outputs"), "${packageID}.${version}.nupkg") + assert !outputFile.exists() + + and: "a empty paket.dependencies file" + createFile("paket.dependencies") + + when: + def result = runTasksSuccessfully(taskToRun) + + then: + outputFile.exists() + result.wasExecuted("paketPack-WoogaTest") + + where: + taskToRun << ["paketPack-WoogaTest", "buildNupkg", "assemble"] + } + @Unroll def "fails #taskToRun when no version is set"(String taskToRun) { given: "a build file without version" diff --git a/src/main/groovy/wooga/gradle/paket/pack/tasks/PaketPack.groovy b/src/main/groovy/wooga/gradle/paket/pack/tasks/PaketPack.groovy index 83e764e..74ac5cd 100644 --- a/src/main/groovy/wooga/gradle/paket/pack/tasks/PaketPack.groovy +++ b/src/main/groovy/wooga/gradle/paket/pack/tasks/PaketPack.groovy @@ -22,6 +22,7 @@ import org.gradle.api.tasks.* import wooga.gradle.paket.internal.PaketCommand import wooga.gradle.paket.base.tasks.internal.AbstractPaketTask import wooga.gradle.paket.base.utils.internal.PaketTemplate +import java.util.concurrent.Callable /** * A task to invoke {@code paket pack} command with given {@code paket.template} file. @@ -50,7 +51,23 @@ class PaketPack extends AbstractPaketTask { * The nuget package version. */ @Input - String version + String getVersion() { + if (!version) { + return null + } + + if (version instanceof Callable) { + version = version.call() + } + + version.toString() + } + + private Object version + + void setVersion(Object value) { + this.version = value + } @Optional @InputFile