GitOrigin-RevId: 63bfa559d9f993f8a4c68926856e6726bcf7f6c0
This commit is contained in:
Vladimir Krivosheev
2019-10-16 15:34:28 +00:00
committed by intellij-monorepo-bot
parent 88422872d4
commit 29fd8c56f7
5 changed files with 46 additions and 34 deletions
@@ -76,30 +76,36 @@ object ExecUtil {
@JvmStatic
@Throws(ExecutionException::class)
fun execAndGetOutput(commandLine: GeneralCommandLine): ProcessOutput =
CapturingProcessHandler(commandLine).runProcess()
fun execAndGetOutput(commandLine: GeneralCommandLine): ProcessOutput {
return CapturingProcessHandler(commandLine).runProcess()
}
@JvmStatic
@Throws(ExecutionException::class)
fun execAndGetOutput(commandLine: GeneralCommandLine, timeoutInMilliseconds: Int): ProcessOutput =
CapturingProcessHandler(commandLine).runProcess(timeoutInMilliseconds)
@JvmStatic
fun execAndReadLine(commandLine: GeneralCommandLine): String? = try {
readFirstLine(commandLine.createProcess().inputStream, commandLine.charset)
}
catch (e: ExecutionException) {
Logger.getInstance(ExecUtil::class.java).debug(e)
null
fun execAndGetOutput(commandLine: GeneralCommandLine, timeoutInMilliseconds: Int): ProcessOutput {
return CapturingProcessHandler(commandLine).runProcess(timeoutInMilliseconds)
}
@JvmStatic
fun readFirstLine(stream: InputStream, cs: Charset?): String? = try {
BufferedReader(if (cs == null) InputStreamReader(stream) else InputStreamReader(stream, cs)).use { it.readLine() }
fun execAndReadLine(commandLine: GeneralCommandLine): String? {
return try {
readFirstLine(commandLine.createProcess().inputStream, commandLine.charset)
}
catch (e: ExecutionException) {
Logger.getInstance(ExecUtil::class.java).debug(e)
null
}
}
catch (e: IOException) {
Logger.getInstance(ExecUtil::class.java).debug(e)
null
@JvmStatic
fun readFirstLine(stream: InputStream, cs: Charset?): String? {
return try {
BufferedReader(if (cs == null) InputStreamReader(stream) else InputStreamReader(stream, cs)).use { it.readLine() }
}
catch (e: IOException) {
Logger.getInstance(ExecUtil::class.java).debug(e)
null
}
}
/**
@@ -113,8 +119,9 @@ object ExecUtil {
*/
@JvmStatic
@Throws(ExecutionException::class, IOException::class)
fun sudo(commandLine: GeneralCommandLine, prompt: String): Process =
sudoCommand(commandLine, prompt).createProcess()
fun sudo(commandLine: GeneralCommandLine, prompt: String): Process {
return sudoCommand(commandLine, prompt).createProcess()
}
@JvmStatic
@Throws(ExecutionException::class, IOException::class)
@@ -15,7 +15,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class OSProcessUtil {
public final class OSProcessUtil {
private static final Logger LOG = Logger.getInstance(OSProcessUtil.class);
private static String ourPid;
@@ -53,7 +53,8 @@ public class NST {
else {
try {
loadLibrary();
} catch (Throwable e) {
}
catch (Throwable e) {
LOG.error("Failed to load nst library for touchbar: ", e);
}
@@ -64,19 +65,23 @@ public class NST {
if (test == null || test == ID.NIL) {
LOG.error("Failed to create native touchbar object, result is null");
ourNSTLibrary = null;
} else {
}
else {
ourNSTLibrary.releaseTouchBar(test);
LOG.info("nst library works properly, successfully created and released native touchbar object");
}
} catch (Throwable e) {
}
catch (Throwable e) {
LOG.error("nst library was loaded, but can't be used: ", e);
ourNSTLibrary = null;
}
} else {
}
else {
LOG.error("nst library wasn't loaded");
}
}
} catch (Throwable e) {
}
catch (Throwable e) {
LOG.error(e);
}
}
@@ -9,6 +9,7 @@ import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.ide.DataManager;
import com.intellij.ide.impl.ProjectUtil;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
@@ -63,7 +64,7 @@ public final class TouchBarsManager {
return;
}
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
for (Project project : ProjectUtil.getOpenProjects()) {
registerProject(project);
}
@@ -157,12 +158,13 @@ public final class TouchBarsManager {
public static void initialize() {
synchronized (ourLoadNstSync) {
if (isInitialized)
if (isInitialized) {
return;
}
NST.initialize();
{ // calculate isEnabled
// calculate isEnabled
final String appId = Utils.getAppId();
if (appId == null || appId.isEmpty()) {
LOG.debug("can't obtain application id from NSBundle");
@@ -170,7 +172,6 @@ public final class TouchBarsManager {
LOG.info("nst library was loaded, but user enabled fn-keys in touchbar");
isEnabled = false;
}
}
isInitialized = true;
}
@@ -5,17 +5,15 @@ import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.ProcessOutput;
import com.intellij.execution.util.ExecUtil;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.ui.mac.foundation.Foundation;
import com.intellij.ui.mac.foundation.ID;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class Utils {
public final class Utils {
private static final Logger LOG = Logger.getInstance(Utils.class);
private static final String TB_SERVER_PROCESS = SystemInfo.isMacOSHighSierra ? "TouchBarServer" : "TouchBarAgent";
@@ -48,8 +46,9 @@ public class Utils {
}
public static String getAppId() {
final @NotNull Application app = ApplicationManager.getApplication();
if (app.isUnitTestMode()) return null;
if (ApplicationManager.getApplication().isUnitTestMode()) {
return null;
}
String appId;
try (@SuppressWarnings("unused") NSAutoreleaseLock lock = new NSAutoreleaseLock()) {