Move pty4j from platform-ide-util-io to it's implementation counterpart

GitOrigin-RevId: 59f167e087223905f737a92c01b2a3aac813f098
This commit is contained in:
Dmitry Trofimov
2021-08-12 01:05:43 +00:00
committed by intellij-monorepo-bot
parent ade5e53070
commit 187ace473b
25 changed files with 144 additions and 50 deletions
+2 -1
View File
@@ -701,6 +701,7 @@
<module fileurl="file://$PROJECT_DIR$/platform/ide-core-impl/intellij.platform.ide.core.impl.iml" filepath="$PROJECT_DIR$/platform/ide-core-impl/intellij.platform.ide.core.impl.iml" />
<module fileurl="file://$PROJECT_DIR$/platform/platform-impl/intellij.platform.ide.impl.iml" filepath="$PROJECT_DIR$/platform/platform-impl/intellij.platform.ide.impl.iml" />
<module fileurl="file://$PROJECT_DIR$/platform/platform-util-io/intellij.platform.ide.util.io.iml" filepath="$PROJECT_DIR$/platform/platform-util-io/intellij.platform.ide.util.io.iml" />
<module fileurl="file://$PROJECT_DIR$/platform/platform-util-io-impl/intellij.platform.ide.util.io.impl.iml" filepath="$PROJECT_DIR$/platform/platform-util-io-impl/intellij.platform.ide.util.io.impl.iml" />
<module fileurl="file://$PROJECT_DIR$/images/intellij.platform.images.iml" filepath="$PROJECT_DIR$/images/intellij.platform.images.iml" />
<module fileurl="file://$PROJECT_DIR$/platform/build-scripts/icons/intellij.platform.images.build.iml" filepath="$PROJECT_DIR$/platform/build-scripts/icons/intellij.platform.images.build.iml" />
<module fileurl="file://$PROJECT_DIR$/platform/indexing-api/intellij.platform.indexing.iml" filepath="$PROJECT_DIR$/platform/indexing-api/intellij.platform.indexing.iml" />
@@ -981,4 +982,4 @@
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/util/compiler-dependencies/kotlin.util.compiler-dependencies.iml" filepath="$PROJECT_DIR$/plugins/kotlin/util/compiler-dependencies/kotlin.util.compiler-dependencies.iml" />
</modules>
</component>
</project>
</project>
@@ -38,7 +38,7 @@
<orderEntry type="library" name="netty-buffer" level="project" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="module" module-name="intellij.platform.workspaceModel.jps" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
<orderEntry type="module" module-name="intellij.platform.serviceContainer" />
</component>
<component name="copyright">
@@ -40,7 +40,7 @@
<orderEntry type="module" module-name="intellij.platform.images" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="library" name="fastutil-min" level="project" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
<orderEntry type="library" name="gson" level="project" />
<orderEntry type="library" name="ASM" level="project" />
</component>
@@ -42,7 +42,7 @@
<orderEntry type="module" module-name="intellij.platform.statistics" exported="" />
<orderEntry type="module" module-name="intellij.platform.util.classLoader" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
</component>
<component name="copyright">
<Base>
+1 -1
View File
@@ -84,7 +84,7 @@
<orderEntry type="module" module-name="intellij.platform.workspaceModel.storage" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="module" module-name="intellij.platform.codeStyle.impl" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
<orderEntry type="module" module-name="intellij.completionMlRanking" scope="TEST" />
<orderEntry type="module" module-name="intellij.platform.workspaceModel.storage" />
<orderEntry type="library" name="ASM" level="project" />
@@ -17,6 +17,6 @@
<orderEntry type="module" module-name="intellij.java" />
<orderEntry type="module" module-name="intellij.java.ui" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
</component>
</module>
@@ -80,6 +80,7 @@ final class PlatformModules {
"intellij.platform.lvcs.impl",
"intellij.platform.vfs.impl",
"intellij.platform.ide.impl",
"intellij.platform.ide.util.io.impl",
"intellij.platform.projectModel.impl",
"intellij.platform.macro",
"intellij.platform.execution.impl",
@@ -281,4 +282,4 @@ final class PlatformModules {
return null
}
}
}
}
@@ -31,6 +31,6 @@
<orderEntry type="library" name="caffeine" level="project" />
<orderEntry type="module" module-name="intellij.platform.concurrency" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
</component>
</module>
@@ -21,6 +21,6 @@
<orderEntry type="module" module-name="intellij.platform.boot" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="library" name="fastutil-min" level="project" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
</component>
</module>
@@ -19,7 +19,7 @@
<orderEntry type="library" name="StreamEx" level="project" />
<orderEntry type="library" name="fastutil-min" level="project" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
<orderEntry type="library" name="jediterm-pty" level="project" />
<orderEntry type="library" name="pty4j" level="project" />
<orderEntry type="module" module-name="intellij.platform.execution" />
@@ -25,7 +25,7 @@
<orderEntry type="library" name="fastutil-min" level="project" />
<orderEntry type="library" name="commons-cli" level="project" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
<orderEntry type="library" name="Velocity" level="project" />
</component>
</module>
@@ -53,7 +53,7 @@
<orderEntry type="module" module-name="intellij.platform.codeStyle" />
<orderEntry type="module" module-name="intellij.platform.codeStyle.impl" />
<orderEntry type="library" name="caffeine" level="project" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
<orderEntry type="module-library">
<library name="find-action-model" type="repository">
<properties maven-id="org.jetbrains.intellij.deps.searchEverywhere.model:find-action-model:0.0.3" />
@@ -57,7 +57,7 @@
<orderEntry type="module" module-name="intellij.platform.objectSerializer" scope="RUNTIME" />
<orderEntry type="library" name="jackson-databind" level="project" />
<orderEntry type="module" module-name="intellij.platform.util.ui" exported="" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
<orderEntry type="module" module-name="intellij.platform.util" />
<orderEntry type="module" module-name="intellij.platform.externalSystem.impl" scope="RUNTIME" />
<orderEntry type="module" module-name="intellij.platform.serviceContainer" />
@@ -105,4 +105,4 @@
<orderEntry type="library" scope="RUNTIME" name="netty-handler-proxy" level="project" />
<orderEntry type="library" scope="RUNTIME" name="rhino" level="project" />
</component>
</module>
</module>
@@ -412,6 +412,10 @@
serviceImplementation="com.intellij.execution.process.ProcessHandlerFactoryImpl" />
<applicationService serviceInterface="com.intellij.execution.process.ColoredOutputTypeRegistry"
serviceImplementation="com.intellij.execution.process.ColoredOutputTypeRegistryImpl" />
<applicationService serviceInterface="com.intellij.execution.process.ProcessService"
serviceImplementation="com.intellij.execution.process.ProcessServiceImpl" />
<applicationService serviceImplementation="com.intellij.ide.CommandLineWaitingManager" />
<applicationService serviceImplementation="com.intellij.ide.CommandLineCustomHandler$StartupService" preload="true" />
@@ -1303,4 +1307,4 @@
activeInHeadlessMode="false" activeInTestMode="false"/>
<listener class="com.intellij.ide.actionsOnSave.impl.ActionsOnSaveFileDocumentManagerListener" topic="com.intellij.openapi.fileEditor.FileDocumentManagerListener"/>
</applicationListeners>
</idea-plugin>
</idea-plugin>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
<orderEntry type="module" module-name="intellij.platform.core" />
<orderEntry type="module" module-name="intellij.platform.util.base" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" exported=""/>
<orderEntry type="library" name="pty4j" level="project" />
<orderEntry type="library" name="winp" level="project" />
</component>
</module>
@@ -0,0 +1,61 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.process
import com.intellij.openapi.application.Application
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.util.SystemInfo
import com.pty4j.PtyProcessBuilder
import com.pty4j.windows.WinPtyProcess
import org.jvnet.winp.WinProcess
import java.io.File
class ProcessServiceImpl: ProcessService {
override fun startPtyProcess(command: Array<String>,
directory: String,
env: MutableMap<String, String>,
options: PtyCommandLineOptions,
app: Application?,
redirectErrorStream: Boolean,
windowsAnsiColorEnabled: Boolean,
unixOpenTtyToPreserveOutputAfterTermination: Boolean): Process {
val builder = PtyProcessBuilder(command)
.setEnvironment(env)
.setDirectory(directory)
.setInitialColumns(if (options.initialColumns > 0) options.initialColumns else null)
.setInitialRows(if (options.initialRows > 0) options.initialRows else null)
.setConsole(options.consoleMode)
.setCygwin(options.useCygwinLaunch && SystemInfo.isWindows)
.setLogFile(if (app != null && app.isEAP) File(PathManager.getLogPath(), "pty.log") else null)
.setRedirectErrorStream(redirectErrorStream)
.setWindowsAnsiColorEnabled(windowsAnsiColorEnabled)
.setUnixOpenTtyToPreserveOutputAfterTermination(unixOpenTtyToPreserveOutputAfterTermination)
return builder.start()
}
override fun sendWinProcessCtrlC(process: Process): Boolean {
return createWinProcess(process).sendCtrlC()
}
override fun killWinProcessRecursively(process: Process) {
createWinProcess(process).killRecursively();
}
override fun isWinPty(process: Process): Boolean {
return process is WinPtyProcess;
}
override fun winPtyChildProcessId(process: Process): Int? {
return if (process is WinPtyProcess) {
return process.childProcessId
} else {
null
}
}
private fun createWinProcess(process: Process): WinProcess {
return if (process is WinPtyProcess) {
WinProcess(process.pid)
}
else WinProcess(process)
}
}
@@ -13,7 +13,6 @@
<orderEntry type="module" module-name="intellij.platform.core" />
<orderEntry type="library" name="Guava" level="project" />
<orderEntry type="library" name="jna" level="project" />
<orderEntry type="library" name="pty4j" level="project" />
<orderEntry type="library" name="winp" level="project" />
<orderEntry type="library" name="jackson" level="project" />
<orderEntry type="library" name="fastutil-min" level="project" />
@@ -1,6 +1,7 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.configurations;
import com.intellij.execution.process.ProcessService;
import com.intellij.execution.process.PtyCommandLineOptions;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
@@ -10,7 +11,6 @@ import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.util.ArrayUtilRt;
import com.pty4j.PtyProcessBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -22,10 +22,10 @@ import java.util.Map;
/**
* A flavor of GeneralCommandLine to start processes with Pseudo-Terminal (PTY).
*
* <p>
* Warning: PtyCommandLine works with ProcessHandler only in blocking read mode.
* Please make sure that you use appropriate ProcessHandler implementation.
*
* <p>
* Works for Linux, macOS, and Windows.
* On Windows, PTY is emulated by creating an invisible console window (see Pty4j and WinPty implementation).
*/
@@ -163,17 +163,8 @@ public class PtyCommandLine extends GeneralCommandLine {
String directory = workDirectory != null ? workDirectory.getPath() : null;
PtyCommandLineOptions options = myOptionsBuilder.build();
Application app = ApplicationManager.getApplication();
PtyProcessBuilder builder = new PtyProcessBuilder(command)
.setEnvironment(env)
.setDirectory(directory)
.setInitialColumns(options.getInitialColumns() > 0 ? options.getInitialColumns() : null)
.setInitialRows(options.getInitialRows() > 0 ? options.getInitialRows() : null)
.setConsole(options.getConsoleMode())
.setCygwin(options.getUseCygwinLaunch() && SystemInfo.isWindows)
.setLogFile(app != null && app.isEAP() ? new File(PathManager.getLogPath(), "pty.log") : null)
.setRedirectErrorStream(isRedirectErrorStream())
.setWindowsAnsiColorEnabled(myWindowsAnsiColorEnabled)
.setUnixOpenTtyToPreserveOutputAfterTermination(myUnixOpenTtyToPreserveOutputAfterTermination);
return builder.start();
return ProcessService.getInstance()
.startPtyProcess(command, directory, env, options, app, isRedirectErrorStream(), myWindowsAnsiColorEnabled,
myUnixOpenTtyToPreserveOutputAfterTermination);
}
}
@@ -169,7 +169,7 @@ public class KillableProcessHandler extends OSProcessHandler implements Killable
OSProcessUtil.logSkippedActionWithTerminatedProcess(myProcess, "destroy", getCommandLine());
return true;
}
return OSProcessUtil.createWinProcess(myProcess).sendCtrlC();
return ProcessService.getInstance().sendWinProcessCtrlC(myProcess);
}
catch (Throwable e) {
if (!myProcess.isAlive()) {
@@ -216,4 +216,4 @@ public class KillableProcessHandler extends OSProcessHandler implements Killable
((ProcessTreeKiller)getProcess()).killProcessTree();
}
}
}
}
@@ -5,7 +5,6 @@ import com.intellij.execution.process.impl.ProcessListUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.registry.Registry;
import com.pty4j.windows.WinPtyProcess;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -23,8 +22,8 @@ public final class OSProcessUtil {
public static boolean killProcessTree(@NotNull Process process) {
if (SystemInfo.isWindows) {
try {
if (process instanceof WinPtyProcess) {
int pid = ((WinPtyProcess) process).getChildProcessId();
Integer pid = ProcessService.getInstance().winPtyChildProcessId(process);
if (pid != null) {
if (pid == -1) return true;
boolean res = WinProcessManager.kill(pid, true);
process.destroy();
@@ -38,7 +37,7 @@ public final class OSProcessUtil {
logSkippedActionWithTerminatedProcess(process, "killProcessTree", null);
return true;
}
createWinProcess(process).killRecursively();
ProcessService.getInstance().killWinProcessRecursively(process);
return true;
}
}
@@ -135,15 +134,6 @@ public final class OSProcessUtil {
return (int)process.pid();
}
@SuppressWarnings("deprecation")
@NotNull
static WinProcess createWinProcess(@NotNull Process process) {
if (process instanceof WinPtyProcess) {
return new WinProcess(((WinPtyProcess)process).getPid());
}
return new WinProcess(process);
}
@NotNull
private static WinProcess createWinProcess(int pid) {
return new WinProcess(pid);
@@ -0,0 +1,30 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.process;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import java.util.Map;
public interface ProcessService {
Process startPtyProcess(String[] command,
String directory,
Map<String, String> env,
PtyCommandLineOptions options,
Application app,
boolean redirectErrorStream,
boolean windowsAnsiColorEnabled,
boolean unixOpenTtyToPreserveOutputAfterTermination);
boolean sendWinProcessCtrlC(Process process);
void killWinProcessRecursively(Process process);
boolean isWinPty(Process process);
Integer winPtyChildProcessId(Process process);
static ProcessService getInstance() {
return ApplicationManager.getApplication().getService(ProcessService.class);
}
}
@@ -18,6 +18,6 @@
<orderEntry type="module" module-name="intellij.platform.debugger" />
<orderEntry type="library" name="fastutil-min" level="project" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
</component>
</module>
@@ -33,7 +33,7 @@
<orderEntry type="module" module-name="intellij.platform.builtInServer.impl" />
<orderEntry type="library" name="kotlinx-coroutines-jdk8" level="project" />
<orderEntry type="module" module-name="intellij.platform.codeStyle.impl" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
<orderEntry type="library" name="caffeine" level="project" />
<orderEntry type="library" name="microba" level="project" />
</component>
@@ -21,6 +21,6 @@
<orderEntry type="module" module-name="intellij.platform.statistics" />
<orderEntry type="library" name="fastutil-min" level="project" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
</component>
</module>
+1 -1
View File
@@ -40,7 +40,7 @@
<orderEntry type="module" module-name="intellij.platform.codeStyle.impl" />
<orderEntry type="library" name="gson" level="project" />
<orderEntry type="library" name="StreamEx" level="project" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io.impl" />
</component>
<component name="copyright">
<Base>