Skip to content

Instantly share code, notes, and snippets.

@mubbashir
Last active April 9, 2019 11:38
Show Gist options
  • Select an option

  • Save mubbashir/821e9327e48ae828b8658626ed0a69b2 to your computer and use it in GitHub Desktop.

Select an option

Save mubbashir/821e9327e48ae828b8658626ed0a69b2 to your computer and use it in GitHub Desktop.

Revisions

  1. mubbashir revised this gist Apr 9, 2019. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions build.gradle
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,11 @@ task("checkEnv"){
    }
    }
    }

    /**
    * Static function to verify if a file/command exist in PATH environment
    * @param file
    * @return true if found, else false
    */
    def static isFoundInPath( file){
    def PATH_ENV = System.getenv('PATH')
    def fileFound = PATH_ENV.split(File.pathSeparator).find{ folder ->
    @@ -21,5 +25,5 @@ def static isFoundInPath( file){
    }
    return fileFound
    }

    // Making test task to depend on checkEnv
    test.dependsOn checkEnv
  2. mubbashir created this gist Apr 9, 2019.
    25 changes: 25 additions & 0 deletions build.gradle
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    // rest of your build
    // Verfied with gradle 4.10
    task("checkEnv"){
    doFirst {
    def listOfFileToCheckInPath = ['find', 'grep']
    listOfFileToCheckInPath.each { file ->
    if(!isFoundInPath(file))
    throw new GradleException("${file} was not found in any of the folder in PATH: ${System.getenv('PATH').split(File.pathSeparator)}")
    }
    }
    }

    def static isFoundInPath( file){
    def PATH_ENV = System.getenv('PATH')
    def fileFound = PATH_ENV.split(File.pathSeparator).find{ folder ->
    println("Looking for ${file} in ${folder}")
    if (Paths.get( "${folder}${File.separator}${file}").toFile().exists()){
    println("Found ${file} in ${folder}")
    return true
    }
    }
    return fileFound
    }

    test.dependsOn checkEnv