defining a task based on another pre-configured task

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

defining a task based on another pre-configured task

Rob Fletcher
Hi

I'm doing several very similar Exec tasks which only vary based on their `workingDir`. The `commandLine` is the same in each case and incremental build inputs & outputs are a function of the `workingDir`. Instead of repeating myself is there a way I can define a new task as a pre-configured Exec task?

Sorry if that's confusing. The build I'm talking about is here: https://github.com/robfletcher/gazebo/blob/master/build.gradle#L15

Rob
Reply | Threaded
Open this post in threaded view
|

Re: defining a task based on another pre-configured task

Justin Ryan
How 'bout:

['standard', 'nonStandard', 'customDir'].each { target ->
    task("init${target.capitalize()}DirProject", type: Exec) {
        workingDir "src/test/resources/projects/${target}"
        commandLine 'bower', 'install'
        inputs.files new File(workingDir, 'component.json')
        outputs.files new File(workingDir, 'web-app')
    }
}


On Thu, Dec 20, 2012 at 4:48 PM, Robert Fletcher <[hidden email]> wrote:
Hi

I'm doing several very similar Exec tasks which only vary based on their `workingDir`. The `commandLine` is the same in each case and incremental build inputs & outputs are a function of the `workingDir`. Instead of repeating myself is there a way I can define a new task as a pre-configured Exec task?

Sorry if that's confusing. The build I'm talking about is here: https://github.com/robfletcher/gazebo/blob/master/build.gradle#L15

Rob

Reply | Threaded
Open this post in threaded view
|

Re: defining a task based on another pre-configured task

Luke Daley-3
Another option is to not subclass Exec, but use project.exec {} in your own implementation.

We are aware that this kind of composition can be awkward and have some long term plans to improve the situation.

On 20/12/2012, at 16:55, Justin Ryan <[hidden email]> wrote:

How 'bout:

['standard', 'nonStandard', 'customDir'].each { target ->
    task("init${target.capitalize()}DirProject", type: Exec) {
        workingDir "src/test/resources/projects/${target}"
        commandLine 'bower', 'install'
        inputs.files new File(workingDir, 'component.json')
        outputs.files new File(workingDir, 'web-app')
    }
}


On Thu, Dec 20, 2012 at 4:48 PM, Robert Fletcher <[hidden email]> wrote:
Hi

I'm doing several very similar Exec tasks which only vary based on their `workingDir`. The `commandLine` is the same in each case and incremental build inputs & outputs are a function of the `workingDir`. Instead of repeating myself is there a way I can define a new task as a pre-configured Exec task?

Sorry if that's confusing. The build I'm talking about is here: https://github.com/robfletcher/gazebo/blob/master/build.gradle#L15

Rob

Reply | Threaded
Open this post in threaded view
|

Re: defining a task based on another pre-configured task

TheKaptain
In reply to this post by Rob Fletcher
You should be able to do something like this as well if you prefer:

def configureExec = { task, projectName, outputDir, cmdLine = ['bower, install'] ->
    task.workingDir "src/test/resources/projects/$projectName"
    task.commandLine cmdLine
    task.inputs.files file("${task.workingDir}/component.json")
    task.outputs.files file("${task.workingDir}/$outputDir")
}

task initStandardProject(type: Exec){ task ->
    configureExec(task, 'standard', 'components')
}

task initCustomDirProject(type: Exec){ task ->
    configureExec(task, 'customDir', 'web-app')
}

task initNonStandardProject(type: Exec){ task ->
    configureExec(task, 'nonStandard', 'lib', ['bower', 'install', '--directory=lib'])
}

processTestResources.dependsOn initStandardProject
processTestResources.dependsOn initNonStandardProject
processTestResources.dependsOn initCustomDirProject
Reply | Threaded
Open this post in threaded view
|

Re: defining a task based on another pre-configured task

Rob Fletcher
Thanks for the help, guys. I have a solution in place now based on Justin's suggestion. https://github.com/robfletcher/gazebo/blob/master/build.gradle#L15


On Fri, Dec 21, 2012 at 7:18 AM, TheKaptain <[hidden email]> wrote:
You should be able to do something like this as well if you prefer:

def configureExec = { task, projectName, outputDir, cmdLine = ['bower,
install'] ->
    task.workingDir "src/test/resources/projects/$projectName"
    task.commandLine cmdLine
    task.inputs.files file("${task.workingDir}/component.json")
    task.outputs.files file("${task.workingDir}/$outputDir")
}

task initStandardProject(type: Exec){ task ->
    configureExec(task, 'standard', 'components')
}

task initCustomDirProject(type: Exec){ task ->
    configureExec(task, 'customDir', 'web-app')
}

task initNonStandardProject(type: Exec){ task ->
    configureExec(task, 'nonStandard', 'lib', ['bower', 'install',
'--directory=lib'])
}

processTestResources.dependsOn initStandardProject
processTestResources.dependsOn initNonStandardProject
processTestResources.dependsOn initCustomDirProject




--
View this message in context: http://gradle.1045684.n5.nabble.com/defining-a-task-based-on-another-pre-configured-task-tp5710571p5710576.html
Sent from the gradle-user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email