Bladeren bron

fix java.lang.Throwable: Synchronous execution on EDT

Seedking 1 jaar geleden
bovenliggende
commit
50fbefa650
1 gewijzigde bestanden met toevoegingen van 27 en 15 verwijderingen
  1. 27 15
      src/main/kotlin/io/xmake/utils/Command.kt

+ 27 - 15
src/main/kotlin/io/xmake/utils/Command.kt

@@ -1,10 +1,15 @@
 package io.xmake.utils
 
 import com.intellij.execution.configurations.GeneralCommandLine
+import com.intellij.execution.process.ProcessNotCreatedException
 import com.intellij.execution.util.ExecUtil
+import com.jetbrains.rd.util.Callable
 import io.xmake.utils.interact.kSystemEnv
 import io.xmake.utils.interact.kLineSeparator
-
+import java.io.FileNotFoundException
+import java.io.IOException
+import java.util.concurrent.Executors
+import java.util.concurrent.Future
 
 /**
  * [ioRunv]
@@ -14,21 +19,28 @@ import io.xmake.utils.interact.kLineSeparator
  * @return a List<String>, the all output of the command
  */
 fun ioRunv(argv: List<String>, workDir: String? = null): List<String> {
-    var ret: List<String> = listOf("")
-    try {
-        val commandLine: GeneralCommandLine = GeneralCommandLine(argv)
-            .withWorkDirectory(workDir)
-            .withCharset(Charsets.UTF_8)
-            .withEnvironment(kSystemEnv)
-            .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
-        commandLine.withEnvironment("COLORTERM", "nocolor")
-        val commandOutput = ExecUtil.execAndGetOutput(commandLine)
-        ret = commandOutput.stdout.split(kLineSeparator)
-    } catch (e: Exception) {
-        e.printStackTrace()
-        return ret
+    val call = Callable {
+        val ret: List<String> = emptyList()
+        try {
+            val commandLine: GeneralCommandLine = GeneralCommandLine(argv)
+                .withWorkDirectory(workDir)
+                .withCharset(Charsets.UTF_8)
+                .withEnvironment(kSystemEnv)
+                .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
+            commandLine.withEnvironment("COLORTERM", "nocolor")
+            val output = ExecUtil.execAndGetOutput(commandLine)
+            output.stdout.split(kLineSeparator)
+        } catch (e: Exception) {
+            e.printStackTrace()
+            ret
+        }
     }
-    return ret
+
+    val executor = Executors.newSingleThreadExecutor()
+    val commandOutput: Future<List<String>> = executor.submit(call)
+    val result = commandOutput.get()
+    executor.shutdown()
+    return result
 }