Răsfoiți Sursa

add Error handling and change method name

runVOutAll() -> ioRunv()
Seedking 1 an în urmă
părinte
comite
d031082c9f

+ 2 - 3
src/main/kotlin/io/xmake/project/XMakeDirectoryProjectGenerator.kt

@@ -1,6 +1,5 @@
 package io.xmake.project
 
-import com.intellij.facet.ui.ValidationResult
 import com.intellij.ide.util.projectWizard.AbstractNewProjectStep
 import com.intellij.ide.util.projectWizard.CustomStepProjectGenerator
 import com.intellij.openapi.module.Module
@@ -14,7 +13,7 @@ import io.xmake.icons.XMakeIcons
 import io.xmake.utils.SystemUtils
 import java.io.File
 import javax.swing.Icon
-import io.xmake.utils.runVOutAll
+import io.xmake.utils.ioRunv
 
 
 class XMakeDirectoryProjectGenerator : DirectoryProjectGeneratorBase<XMakeConfigData>(),
@@ -34,7 +33,7 @@ class XMakeDirectoryProjectGenerator : DirectoryProjectGeneratorBase<XMakeConfig
          * @note we muse use ioRunv instead of Runv to read all output, otherwise it will wait forever on windows
          */
         val tmpdir = "$contentEntryPath.dir"
-        runVOutAll(
+        ioRunv(
             listOf(
                 SystemUtils.xmakeProgram,
                 "create",

+ 2 - 2
src/main/kotlin/io/xmake/project/XMakeModuleBuilder.kt

@@ -10,7 +10,7 @@ import com.intellij.openapi.util.Disposer
 import com.intellij.openapi.util.io.FileUtil
 import com.intellij.openapi.vfs.LocalFileSystem
 import io.xmake.utils.SystemUtils
-import io.xmake.utils.runVOutAll
+import io.xmake.utils.ioRunv
 import java.io.File
 
 
@@ -38,7 +38,7 @@ class XMakeModuleBuilder : ModuleBuilder() {
          * @note we muse use ioRunv instead of Runv to read all output, otherwise it will wait forever on windows
          */
         val tmpdir = "$contentEntryPath.dir"
-        runVOutAll(
+        ioRunv(
             listOf(
                 SystemUtils.xmakeProgram,
                 "create",

+ 2 - 2
src/main/kotlin/io/xmake/shared/XMakeConfiguration.kt

@@ -8,7 +8,7 @@ import com.intellij.openapi.components.ProjectComponent
 import com.intellij.openapi.diagnostic.Logger
 import com.intellij.openapi.project.Project
 import io.xmake.utils.SystemUtils
-import io.xmake.utils.runVOutAll
+import io.xmake.utils.ioRunv
 
 @State(name = "XMakeProjectSettings")
 class XMakeConfiguration(// the project
@@ -133,7 +133,7 @@ class XMakeConfiguration(// the project
 
             // make targets
             var targets = arrayOf("default", "all")
-            val results = runVOutAll(
+            val results = ioRunv(
                 listOf(
                     SystemUtils.xmakeProgram,
                     "l",

+ 19 - 12
src/main/kotlin/io/xmake/utils/Command.kt

@@ -4,23 +4,30 @@ import com.intellij.execution.configurations.GeneralCommandLine
 import com.intellij.execution.util.ExecUtil
 import io.xmake.utils.interact.kSystemEnv
 import io.xmake.utils.interact.kLineSeparator
+
+
 /**
- * [runVOutAll]
+ * [ioRunv]
  *
  * @param argv the command arguments
  * @param workDir the working directory
  * @return a List<String>, the all output of the command
  */
-fun runVOutAll(argv: List<String>, workDir: String? = null): List<String> {
-    val ret: List<String>
-    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).stdout
-    ret = commandOutput.split(kLineSeparator)
+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
+    }
     return ret
 }
 
@@ -39,7 +46,7 @@ fun runVOutAll(argv: List<String>, workDir: String? = null): List<String> {
  * Lines are returned as a single string, with each line separated by the system's line separator.
  */
 
-inline fun runVOutLine(argv: List<String>, minLine: Int, maxLine: Int = minLine, workDir: String? = null): String {
+fun ioRunvOutLine(argv: List<String>, minLine: Int, maxLine: Int = minLine, workDir: String? = null): String {
     TODO()
 }