Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. // rest of your build
  2. // Verfied with gradle 4.10
  3. task("checkEnv"){
  4. doFirst {
  5. def listOfFileToCheckInPath = ['find', 'grep']
  6. listOfFileToCheckInPath.each { file ->
  7. if(!isFoundInPath(file))
  8. throw new GradleException("${file} was not found in any of the folder in PATH: ${System.getenv('PATH').split(File.pathSeparator)}")
  9. }
  10. }
  11. }
  12. /**
  13. * Static function to verify if a file/command exist in PATH environment
  14. * @param file
  15. * @return true if found, else false
  16. */
  17. def static isFoundInPath( file){
  18. def PATH_ENV = System.getenv('PATH')
  19. def fileFound = PATH_ENV.split(File.pathSeparator).find{ folder ->
  20. println("Looking for ${file} in ${folder}")
  21. if (Paths.get( "${folder}${File.separator}${file}").toFile().exists()){
  22. println("Found ${file} in ${folder}")
  23. return true
  24. }
  25. }
  26. return fileFound
  27. }
  28. // Making test task to depend on checkEnv
  29. test.dependsOn checkEnv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement