mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[terminal] IJ-CR-178413 cleanup LocalTerminalDirectRunner.doCreateProcess
GitOrigin-RevId: da3328d21e9177e2bcec19ed7dd20d87786c0940
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d67be8e4ac
commit
0843f4df69
+19
-23
@@ -5,7 +5,6 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.platform.eel.EelDescriptor;
|
||||
import com.intellij.terminal.pty.PtyProcessTtyConnector;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.TimeoutUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jediterm.core.util.TermSize;
|
||||
@@ -27,7 +26,10 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -94,13 +96,16 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
|
||||
}
|
||||
|
||||
private @NotNull ShellProcessHolder doCreateProcess(@NotNull ShellStartupOptions options) throws ExecutionException {
|
||||
String[] command = ArrayUtil.toStringArray(options.getShellCommand());
|
||||
List<String> command = Objects.requireNonNull(options.getShellCommand(), () -> {
|
||||
return "Shell command must not be null, " + options;
|
||||
});
|
||||
Map<String, String> envs = options.getEnvVariables();
|
||||
TermSize initialTermSize = options.getInitialTermSize();
|
||||
String workingDir = options.getWorkingDirectory();
|
||||
if (workingDir == null) {
|
||||
throw new IllegalStateException("Working directory must not be null, startup options: " + options);
|
||||
}
|
||||
TermSize initialTermSize = Objects.requireNonNull(options.getInitialTermSize(), () -> {
|
||||
return "Initial term size must not be null, " + options;
|
||||
});
|
||||
String workingDir = Objects.requireNonNull(options.getWorkingDirectory(), () -> {
|
||||
return "Working directory must not be null, " + options;
|
||||
});
|
||||
|
||||
var shellIntegration = options.getShellIntegration();
|
||||
boolean isBlockTerminal =
|
||||
@@ -113,24 +118,15 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
|
||||
TerminalUsageTriggerCollector.triggerLocalShellStarted(myProject, command, isBlockTerminal);
|
||||
}
|
||||
|
||||
Path workingDirPath = null;
|
||||
try {
|
||||
workingDirPath = Path.of(workingDir);
|
||||
}
|
||||
catch (InvalidPathException ignored) {
|
||||
}
|
||||
try {
|
||||
long startNano = System.nanoTime();
|
||||
Path workingDirPath = Path.of(workingDir);
|
||||
ShellProcessHolder processHolder;
|
||||
if (workingDirPath != null && shouldUseEelApi()) {
|
||||
processHolder = startProcess(
|
||||
List.of(command), envs, workingDirPath, Objects.requireNonNull(initialTermSize)
|
||||
);
|
||||
if (shouldUseEelApi()) {
|
||||
processHolder = startProcess(command, envs, workingDirPath, initialTermSize);
|
||||
}
|
||||
else {
|
||||
processHolder = startLocalProcess(
|
||||
List.of(command), envs, workingDir, Objects.requireNonNull(initialTermSize)
|
||||
);
|
||||
processHolder = startLocalProcess(command, envs, workingDir, initialTermSize);
|
||||
}
|
||||
LOG.info("Started " + processHolder.getPtyProcess().getClass().getName() + " in " + TimeoutUtil.getDurationMillis(startNano)
|
||||
+ " ms from " + stringifyProcessInfo(command, workingDir, initialTermSize, envs, !LOG.isDebugEnabled()));
|
||||
@@ -145,12 +141,12 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
|
||||
return TerminalOptionsProvider.getInstance().getShellIntegration();
|
||||
}
|
||||
|
||||
private static @NotNull String stringifyProcessInfo(String @NotNull[] command,
|
||||
private static @NotNull String stringifyProcessInfo(@NotNull List<String> command,
|
||||
@NotNull String workingDirectory,
|
||||
@Nullable TermSize initialTermSize,
|
||||
@NotNull Map<String, String> environment,
|
||||
boolean envDiff) {
|
||||
String info = Arrays.toString(command) + " in " + workingDirectory + (isDirectory(workingDirectory) ? "" : " [no such directory]") +
|
||||
String info = command + " in " + workingDirectory + (isDirectory(workingDirectory) ? "" : " [no such directory]") +
|
||||
", [" + initialTermSize + "]";
|
||||
if (envDiff) {
|
||||
return info + ", diff_envs=" + getEnvironmentDiff(environment, System.getenv());
|
||||
|
||||
+1
-1
@@ -180,7 +180,7 @@ object ReworkedTerminalUsageCollector : CounterUsagesCollector() {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun logLocalShellStarted(project: Project, shellCommand: Array<String>) {
|
||||
fun logLocalShellStarted(project: Project, shellCommand: List<String>) {
|
||||
localShellStartedEvent.log(project,
|
||||
osVersion,
|
||||
getShellNameForStat(shellCommand.firstOrNull()))
|
||||
|
||||
@@ -128,7 +128,7 @@ object TerminalUsageTriggerCollector : CounterUsagesCollector() {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun triggerLocalShellStarted(project: Project, shellCommand: Array<String>, isBlockTerminal: Boolean) {
|
||||
fun triggerLocalShellStarted(project: Project, shellCommand: List<String>, isBlockTerminal: Boolean) {
|
||||
localExecEvent.log(project,
|
||||
Version.parseVersion(SystemInfo.OS_VERSION)?.toCompactString() ?: "unknown",
|
||||
TerminalShellInfoStatistics.getShellNameForStat(shellCommand.firstOrNull()),
|
||||
|
||||
Reference in New Issue
Block a user