fix testing if executable is installed

This commit is contained in:
Renaud Pawlak 2020-07-25 12:28:47 +02:00
parent c196424c28
commit 98d2081afd

View File

@ -104,10 +104,17 @@ public class ProcessUtil {
+ "bin" + File.separator + mainFileName;
}
/**
* Gets the full path of a global package's JS main file installed with npm.
*/
public static String getGlobalNpmPackageExecutablePath(String command) {
return getGlobalNpmPackageExecutablePath(command, true);
}
/**
* Gets the full path of a global package's JS main file installed with npm.
*/
public static String getGlobalNpmPackageExecutablePath(String command) {
public static String getGlobalNpmPackageExecutablePath(String command, boolean throwError) {
File commandFile = new File(command);
if (commandFile.isFile() && commandFile.isAbsolute()) {
return command;
@ -121,8 +128,13 @@ public class ProcessUtil {
}
logger.info("cannot find " + command + " - searching in " + NPM_DIR.getAbsolutePath());
return lookupGlobalNpmPackageExecutablePath(NPM_DIR, command)
.orElseThrow(() -> new RuntimeException("Could not locate command " + command));
if (throwError) {
return lookupGlobalNpmPackageExecutablePath(NPM_DIR, command)
.orElseThrow(() -> new RuntimeException("Could not locate command " + command));
} else {
return lookupGlobalNpmPackageExecutablePath(NPM_DIR, command).get();
}
}
}
@ -177,7 +189,7 @@ public class ProcessUtil {
* Tells if this node command is globally installed.
*/
public static boolean isExecutableInstalledGloballyWithNpm(String command) {
String executablePath = getGlobalNpmPackageExecutablePath(command);
String executablePath = getGlobalNpmPackageExecutablePath(command, false);
return executablePath != null && new File(executablePath).exists();
}