override fun exec()

in plugin/src/main/kotlin/org/jetbrains/qodana/tasks/QodanaScanTask.kt [79:105]


    override fun exec() {
        setArgs(getArguments())

        executable = (if (useNightly.get()) "nightly" else Installer.getLatestVersion()).let {
            Installer().setup(
                qodanaPath.get(),
                version = it
            )
        }
        environment(QODANA_ENV, QODANA_ENV_NAME)
        environment("PATH", currentPath)
        environment("HOME", currentHome)

        ByteArrayOutputStream().use { os ->
            standardOutput = TeeOutputStream(System.out, os)

            runCatching {
                super.exec()
            }.exceptionOrNull()?.let {
                val message = os.toString().lines().find { line ->
                    line.startsWith("Inspection run is terminating")
                } ?: "Qodana finished with failure. Check logs and Qodana report for more details."

                throw TaskExecutionException(this, GradleException(message, it))
            }
        }
    }