Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. exec {
  2. commandLine command("npm"), "install"
  3. }
  4.  
  5. //
  6. // find a command with this name in the path
  7. //
  8. String command( String name )
  9. {
  10. def onWindows = (System.env.PATH==null);
  11. def pathBits = onWindows ? System.env.Path.split(";") : System.env.PATH.split(":");
  12. def isMatch = onWindows ? {path ->
  13. for (String extension : System.env.PATHEXT.split(";"))
  14. {
  15. File theFile = new File( path, name + extension);
  16. if (theFile.exists())
  17. return theFile;
  18. }
  19. return null;
  20. } : {path -> def file = new File(path,name);if (file.exists() && file.canExecute()) return file;return null;}
  21.  
  22. def foundLocal = isMatch(".");
  23. if (foundLocal)
  24. return foundLocal;
  25. for (String pathBit : pathBits)
  26. {
  27. def found = isMatch(pathBit);
  28. if (found)
  29. return found;
  30. }
  31. throw new TaskExecutionException(it, "Failed to find " + name + " in the path")
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement