Skip to content

Commit

Permalink
Expose args property from AbstractPaketTask to all tasks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Larusso committed Mar 14, 2018
1 parent cf88749 commit 93e2ce0
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 1 deletion.
@@ -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<String> 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'
}
}
Expand Up @@ -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 {

Expand Down
@@ -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<String> getTestTasks() {
return [
PaketGetPlugin.INSTALL_TASK_NAME,
PaketGetPlugin.UPDATE_TASK_NAME,
PaketGetPlugin.RESTORE_TASK_NAME,
PaketGetPlugin.OUTDATED_TASK_NAME
]
}
}
@@ -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<String> 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")
}
}
Expand Up @@ -64,7 +64,53 @@ abstract class AbstractPaketTask<T extends AbstractPaketTask> extends Convention
@Internal
protected ByteArrayOutputStream stdErr

protected Collection<String> args = []
protected ArrayList<String> arguments = []

/**
* Returns the arguments for the command to be executed. Defaults to an empty list.
*/
List<String> 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<T> taskType) {
super()
Expand Down

0 comments on commit 93e2ce0

Please sign in to comment.