Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exec {
- commandLine command("npm"), "install"
- }
- //
- // find a command with this name in the path
- //
- String command( String name )
- {
- def onWindows = (System.env.PATH==null);
- def pathBits = onWindows ? System.env.Path.split(";") : System.env.PATH.split(":");
- def isMatch = onWindows ? {path ->
- for (String extension : System.env.PATHEXT.split(";"))
- {
- File theFile = new File( path, name + extension);
- if (theFile.exists())
- return theFile;
- }
- return null;
- } : {path -> def file = new File(path,name);if (file.exists() && file.canExecute()) return file;return null;}
- def foundLocal = isMatch(".");
- if (foundLocal)
- return foundLocal;
- for (String pathBit : pathBits)
- {
- def found = isMatch(pathBit);
- if (found)
- return found;
- }
- throw new TaskExecutionException(it, "Failed to find " + name + " in the path")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement