From 93e2ce0ec55e37b1450a6cd4886c002996a1729f Mon Sep 17 00:00:00 2001 From: Manfred Endres Date: Wed, 14 Mar 2018 11:07:39 +0100 Subject: [PATCH] Expose args property from AbstractPaketTask to all tasks Description =========== This pull request adds changes to allow all possible additional paket command switches be set through the gradle tasks. The most important switches are implemented already within the task interface. But some optional switches are not. We don't want to add a big support list of all possible commandline options at the time, the users of the tasks can configure these options themself. Changes ======= ![IMPROVE] paket tasks interface --- .../PaketIntegrationArgumentsSpec.groovy | 109 ++++++++++++++++++ .../paket/PaketIntegrationBaseSpec.groovy | 1 + .../paket/get/PaketGetArgumentsSpec.groovy | 24 ++++ .../paket/pack/PaketPackArgumentsSpec.groovy | 38 ++++++ .../tasks/internal/AbstractPaketTask.groovy | 48 +++++++- 5 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 src/integrationTest/groovy/wooga/gradle/paket/PaketIntegrationArgumentsSpec.groovy create mode 100644 src/integrationTest/groovy/wooga/gradle/paket/get/PaketGetArgumentsSpec.groovy create mode 100644 src/integrationTest/groovy/wooga/gradle/paket/pack/PaketPackArgumentsSpec.groovy diff --git a/src/integrationTest/groovy/wooga/gradle/paket/PaketIntegrationArgumentsSpec.groovy b/src/integrationTest/groovy/wooga/gradle/paket/PaketIntegrationArgumentsSpec.groovy new file mode 100644 index 0000000..f2ee0a1 --- /dev/null +++ b/src/integrationTest/groovy/wooga/gradle/paket/PaketIntegrationArgumentsSpec.groovy @@ -0,0 +1,109 @@ +package wooga.gradle.paket + +import nebula.test.IntegrationSpec +import spock.lang.IgnoreIf +import spock.lang.Unroll + +abstract class PaketIntegrationArgumentsSpec extends IntegrationSpec { + + abstract Class getTestPlugin() + abstract List getTestTasks() + + def setup() { + given: "a paket dependency file" + createFile("paket.dependencies") + + and: "a empty lock file" + createFile("paket.lock") + + buildFile << """ + group = 'test' + ${applyPlugin(getTestPlugin())} + """.stripIndent() + } + + @IgnoreIf({ env["CI"] }) + @Unroll + def "task: #taskToRun is available"() { + when: + def result = runTasksSuccessfully("tasks") + + then: + result.standardOutput.contains(taskToRun) + + where: + taskToRun << getTestTasks() + } + + @Unroll + def "task :#taskToRun can set custom arguments '-customFlag1, -customFlag2' with args(arguments,...)"() { + given: + buildFile << """ + + project.tasks."${taskToRun}" { + args($value) + } + """.stripIndent() + + when: + def result = runTasks(taskToRun) + + then: + result.wasExecuted(taskToRun) + result.standardOutput.contains("Starting process 'command '") + result.standardOutput.contains(" $expectedCommandlineSwitch") + + where: + taskToRun << getTestTasks() + value = '"-customFlag1", "-customFlag2"' + expectedCommandlineSwitch = '-customFlag1 -customFlag2' + } + + @Unroll + def "task :#taskToRun can set custom arguments '-customFlag1, -customFlag2' with args([arguments])"() { + given: + buildFile << """ + + project.tasks."${taskToRun}" { + args($value) + } + """.stripIndent() + + when: + def result = runTasks(taskToRun) + + then: + result.wasExecuted(taskToRun) + result.standardOutput.contains("Starting process 'command '") + result.standardOutput.contains(" $expectedCommandlineSwitch") + + where: + taskToRun << getTestTasks() + value = '["-customFlag1", "-customFlag2"]' + expectedCommandlineSwitch = '-customFlag1 -customFlag2' + } + + @Unroll + def "task :#taskToRun can set custom arguments '-customFlag1, -customFlag2' with args = [arguments]"() { + given: + buildFile << """ + + project.tasks."${taskToRun}" { + args = $value + } + """.stripIndent() + + when: + def result = runTasks(taskToRun) + + then: + result.wasExecuted(taskToRun) + result.standardOutput.contains("Starting process 'command '") + result.standardOutput.contains(" $expectedCommandlineSwitch") + + where: + taskToRun << getTestTasks() + value = '["-customFlag1", "-customFlag2"]' + expectedCommandlineSwitch = '-customFlag1 -customFlag2' + } +} diff --git a/src/integrationTest/groovy/wooga/gradle/paket/PaketIntegrationBaseSpec.groovy b/src/integrationTest/groovy/wooga/gradle/paket/PaketIntegrationBaseSpec.groovy index 3211aef..d529115 100644 --- a/src/integrationTest/groovy/wooga/gradle/paket/PaketIntegrationBaseSpec.groovy +++ b/src/integrationTest/groovy/wooga/gradle/paket/PaketIntegrationBaseSpec.groovy @@ -21,6 +21,7 @@ import nebula.test.IntegrationSpec import nebula.test.functional.ExecutionResult import spock.lang.Shared import spock.lang.Unroll +import wooga.gradle.paket.get.PaketGetPlugin abstract class PaketIntegrationBaseSpec extends IntegrationSpec { diff --git a/src/integrationTest/groovy/wooga/gradle/paket/get/PaketGetArgumentsSpec.groovy b/src/integrationTest/groovy/wooga/gradle/paket/get/PaketGetArgumentsSpec.groovy new file mode 100644 index 0000000..0b0a966 --- /dev/null +++ b/src/integrationTest/groovy/wooga/gradle/paket/get/PaketGetArgumentsSpec.groovy @@ -0,0 +1,24 @@ +package wooga.gradle.paket.get; + +import wooga.gradle.paket.PaketIntegrationArgumentsSpec; +import wooga.gradle.paket.PaketPlugin; + +import java.util.List; + +class PaketGetArgumentsSpec extends PaketIntegrationArgumentsSpec { + + @Override + Class getTestPlugin() { + return PaketGetPlugin.class + } + + @Override + List getTestTasks() { + return [ + PaketGetPlugin.INSTALL_TASK_NAME, + PaketGetPlugin.UPDATE_TASK_NAME, + PaketGetPlugin.RESTORE_TASK_NAME, + PaketGetPlugin.OUTDATED_TASK_NAME + ] + } +} diff --git a/src/integrationTest/groovy/wooga/gradle/paket/pack/PaketPackArgumentsSpec.groovy b/src/integrationTest/groovy/wooga/gradle/paket/pack/PaketPackArgumentsSpec.groovy new file mode 100644 index 0000000..c0fbfad --- /dev/null +++ b/src/integrationTest/groovy/wooga/gradle/paket/pack/PaketPackArgumentsSpec.groovy @@ -0,0 +1,38 @@ +package wooga.gradle.paket.pack + +import wooga.gradle.paket.PaketIntegrationArgumentsSpec + +class PaketPackArgumentsSpec extends PaketIntegrationArgumentsSpec { + + @Override + Class getTestPlugin() { + return PaketPackPlugin.class + } + + @Override + List getTestTasks() { + return ["paketPack-WoogaTest"] + } + + def paketTemplateFile + def version = "1.0.0" + def packageID = "Wooga.Test" + + def setup() { + buildFile << """ + version = "$version" + """.stripIndent() + + paketTemplateFile = createFile("paket.template") + paketTemplateFile << """ + type file + id $packageID + authors Wooga + owners Wooga + description + Empty nuget package. + """.stripIndent() + + createFile("paket.lock") + } +} diff --git a/src/main/groovy/wooga/gradle/paket/base/tasks/internal/AbstractPaketTask.groovy b/src/main/groovy/wooga/gradle/paket/base/tasks/internal/AbstractPaketTask.groovy index eaf7a6e..a1d6176 100644 --- a/src/main/groovy/wooga/gradle/paket/base/tasks/internal/AbstractPaketTask.groovy +++ b/src/main/groovy/wooga/gradle/paket/base/tasks/internal/AbstractPaketTask.groovy @@ -64,7 +64,53 @@ abstract class AbstractPaketTask extends Convention @Internal protected ByteArrayOutputStream stdErr - protected Collection args = [] + protected ArrayList arguments = [] + + /** + * Returns the arguments for the command to be executed. Defaults to an empty list. + */ + List getArgs() { + arguments + } + + /** + * Adds arguments for the command to be executed. + * + * @param args args for the command + * @return this + */ + T args(Object... args) { + args.each { + arguments.add(it.toString()) + } + + T.cast(this) + } + + /** + * Adds arguments for the command to be executed. + * + * @param args args for the command + * @return this + */ + T args(Iterable args) { + args.each { + arguments.add(it.toString()) + } + + T.cast(this) + } + + /** + * Sets the arguments for the command to be executed. + * + * @param args args for the command + * @return this + */ + T setArgs(Iterable args) { + arguments.clear() + this.args(args) + } AbstractPaketTask(Class taskType) { super()