Is there a way to access properties of the Exec task in a custom task delegating to project.exec {}?


(Ferzan Rizvi) #1

I want to print the commandLine and environment properties of a custom task delegating to project.exec using something like this

tasks.withType(com.scrippsnetworks.gradle.plugin.db.EtlPopulateTask) {
    doFirst {
        println "CMD:" + environment
        println "CMD:" + commandLine
    }
}
  1. Is this possible without extending the Exec class? 2) If there is another way to get the commandLine and environment, I am open to it 3) If this is only possible by extending the Exec class, could someone please post an example?

-------------------------------- Custom Task --------------------------------

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
  class EtlPopulateTask extends DefaultTask {
    File etlScriptsRoot
      String cdwJdbcConnection
    String cdwPassword
      String wcmJdbcConnection
    String wcmPassword
      String impJdbcConnection
    String impPassword
      String springConfig
      @TaskAction
    def etlDeployAction() {
          List pvConfig = [
                springConfig,
                "-db.cdw.url $cdwJdbcConnection",
                "-db.cdw.pass $cdwPassword",
                "-db.wcm.url $wcmJdbcConnection",
                "-db.wcm.pass $wcmPassword",
                "-db.imp.url $impJdbcConnection",
                "-db.imp.pass $impPassword"
        ]
          Map environmentVariables = [
                WORKDIR: etlScriptsRoot,
                PATH: System.getenv('PATH') + ":${System.getenv('EC2_HOME')}/bin",
                PV_CONFIG: pvConfig.join(" "),
        ]
          project.exec {
            workingDir etlScriptsRoot
            executable "./imp-pv-node.bash"
            environment environmentVariables
        }
    }
}

(Peter Niederwieser) #2

Unless ‘project.exec’ already logs something (e.g. on ‘–info’ level), the way to do this is to add println or log statements to your custom task class, e.g. just before the call to ‘project.exec’.