Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Fix set of lazy version parameter for paketPack (#32)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
Larusso authored Mar 30, 2018
1 parent c1bb49c commit bba1473
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 18 additions & 1 deletion src/main/groovy/wooga/gradle/paket/pack/tasks/PaketPack.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bba1473

Please sign in to comment.