snowch / biginsight-examples

Example projects to help you quickly get started with BigInsights
Apache License 2.0
7 stars 4 forks source link

Refactor duplicated code in tasks #53

Closed snowch closed 8 years ago

snowch commented 8 years ago

E.g.

this

// task to run the groovy script
task('Ls', type: JavaExec) {

    environment 'gateway', props.gateway
    environment 'username', props.username
    environment 'password', props.password

    main = 'Ls'
    classpath = sourceSets.main.runtimeClasspath
}
task('Mkdir', type: JavaExec) {

    environment 'gateway', props.gateway
    environment 'username', props.username
    environment 'password', props.password

    main = 'Mkdir'
    classpath = sourceSets.main.runtimeClasspath
}

task('Put', type: JavaExec) {

    environment 'gateway', props.gateway
    environment 'username', props.username
    environment 'password', props.password

    main = 'Put'
    classpath = sourceSets.main.runtimeClasspath
}

can become this:

['Ls', 'Mkdir', 'Put'].each { taskName ->
    task "$taskName"(type: JavaExec) {

        environment 'gateway', props.gateway
        environment 'username', props.username
        environment 'password', props.password

        main = taskName
        classpath = sourceSets.main.runtimeClasspath
    }
}
pregazzoni commented 8 years ago

Nice way to simplify Chris. Did one commit for ambari dir. Will do one dir at a time next.