mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Remove code duplication.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.openapi.vcs;
|
||||
|
||||
import com.intellij.execution.configurations.PathEnvironmentVariableUtil;
|
||||
import com.intellij.execution.process.CapturingProcessHandler;
|
||||
import com.intellij.execution.process.ProcessOutput;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
@@ -196,30 +197,15 @@ public class Executor {
|
||||
if (exec != null) {
|
||||
return exec;
|
||||
}
|
||||
exec = findInPath(programName, unixExec, winExec);
|
||||
if (exec != null) {
|
||||
return exec;
|
||||
File fileExec = PathEnvironmentVariableUtil.findInPath(SystemInfo.isWindows ? winExec : unixExec);
|
||||
if (fileExec != null) {
|
||||
return fileExec.getAbsolutePath();
|
||||
}
|
||||
throw new IllegalStateException(programName + " executable not found. " +
|
||||
"Please define a valid environment variable " + pathEnvs.iterator().next() +
|
||||
" pointing to the " + programName + " executable.");
|
||||
}
|
||||
|
||||
protected static String findInPath(String programName, String unixExec, String winExec) {
|
||||
String path = System.getenv(SystemInfo.isWindows ? "Path" : "PATH");
|
||||
if (path != null) {
|
||||
String name = SystemInfo.isWindows ? winExec : unixExec;
|
||||
for (String dir : path.split(File.pathSeparator)) {
|
||||
File file = new File(dir, name);
|
||||
if (file.canExecute()) {
|
||||
log("Using " + programName + " from PATH: " + file.getPath());
|
||||
return file.getPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static String findInPathEnvs(String programName, Collection<String> pathEnvs) {
|
||||
for (String pathEnv : pathEnvs) {
|
||||
String exec = System.getenv(pathEnv);
|
||||
|
||||
Reference in New Issue
Block a user