diff --git a/README.md b/README.md index 8b55cab..8ecb58d 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ This plugin it is required to have the spectral CLI installed on your system. Fo install the binary without going through Nodejs. > **Warning** Should you still want to use the spectral package via NodeJs on Windows then -you must check "Use node package on on Windows" in the plugin settings. This is necessary for the node packages to +you must check "Use node package on Windows" in the plugin settings. This is necessary for the node packages to work and will have a performance cost. If you don't have it installed yet make sure to follow this diff --git a/gradle.properties b/gradle.properties index 7b72f91..62522da 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ pluginGroup=com.lupor.spectral-linter-intellij-plugin pluginName=Spectral-Linter pluginRepositoryUrl=https://github.com/lupor/spectral-intellij-plugin -pluginVersion=0.0.9 +pluginVersion=0.0.10 pluginSinceBuild=223 pluginUntilBuild=243.* platformType=IC diff --git a/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/CommandLineExecutor.kt b/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/CommandLineExecutor.kt index 5bcf664..c1ae9d5 100644 --- a/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/CommandLineExecutor.kt +++ b/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/CommandLineExecutor.kt @@ -13,10 +13,12 @@ class CommandLineExecutor { } fun execute(commandLine: GeneralCommandLine, timeout: Duration? = null): ProcessOutput { - val handler = OSProcessHandler(commandLine) + val command = commandLine.commandLineString + val process = commandLine.createProcess() + val handler = OSProcessHandler(process, command, Charsets.UTF_8) val output = ProcessOutput() - logger.debug("Executing command: ${handler.commandLine}") + logger.debug("Executing command: $command") handler.addProcessListener(object : ProcessAdapter() { override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) { @@ -36,7 +38,7 @@ class CommandLineExecutor { if (ended) { logger.debug("Command successfully executed with exit code ${output.exitCode}") - output.exitCode = handler.exitCode!! + output.exitCode = process.exitValue() } else { logger.debug("Command timed out after ${timeout?.toMillis()} ms") handler.destroyProcess() diff --git a/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/SpectralRunner.kt b/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/SpectralRunner.kt index 4267a4b..5f5fcf7 100644 --- a/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/SpectralRunner.kt +++ b/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/SpectralRunner.kt @@ -54,19 +54,23 @@ class SpectralRunner(private val project: Project) { settings: ProjectSettingsState, filePath: String ): GeneralCommandLine { - var commandString = "spectral -r ${settings.ruleset} -f json lint $filePath" + var commandString = "-r ${settings.ruleset} -f json lint $filePath" if (SystemInfo.isWindows && settings.useNodePackageWin) { - commandString = "cmd /c $commandString" + commandString = "cmd /c spectral $commandString" + } else if (SystemInfo.isWindows) { + commandString = "spectral.exe $commandString" + } else { + commandString = "spectral $commandString" } val command = commandString.split(" ") val commandLine = GeneralCommandLine(command[0]) .withParameters(command.drop(1)) .withWorkDirectory(project.basePath) - .withCharset(Charsets.UTF_8) - .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.SYSTEM) + .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE) val commandEnv = mapOf("NODE_OPTIONS" to "--no-warnings") - commandLine.withEnvironment(commandLine.parentEnvironment + commandEnv) + val cleanEnv = mapOf("PATH" to commandLine.parentEnvironment["PATH"]) + commandEnv + commandLine.withEnvironment(cleanEnv) return commandLine } diff --git a/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/settings/SettingsComponent.kt b/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/settings/SettingsComponent.kt index 6efd389..f218b89 100644 --- a/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/settings/SettingsComponent.kt +++ b/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/settings/SettingsComponent.kt @@ -14,7 +14,7 @@ class SettingsComponent { val rulesetInput = JBTextField() val includedFilesInput = JBTextArea() val useFileOverrides = JBCheckBox("Use file level overrides", false) - val useNodePackageWin = JBCheckBox("Use node package on on Windows", false) + val useNodePackageWin = JBCheckBox("Use node package on Windows", false) init { val overrideTooltip = """