Extract throwGradleExceptionIfError

This commit is contained in:
Alexey Tsvetkov
2016-12-07 15:32:14 +03:00
parent 5a846f94fc
commit 232b40eb36
3 changed files with 18 additions and 18 deletions
@@ -34,14 +34,6 @@ open class KaptTask : AbstractCompile() {
return FileUtil.isAncestor(destinationDir, this, /* strict = */ false)
}
private fun processCompilerExitCode(exitCode: ExitCode) {
when (exitCode) {
ExitCode.COMPILATION_ERROR -> throw GradleException("Annotation processing error. See log for more details")
ExitCode.INTERNAL_ERROR -> throw GradleException("Annotation processing internal error. See log for more details")
else -> {}
}
}
@TaskAction
override fun compile() {
/** Delete everything inside the [destinationDir] */
@@ -59,8 +51,9 @@ open class KaptTask : AbstractCompile() {
kotlinCompileTask.parentKotlinOptionsImpl?.updateArguments(args)
KotlinJvmOptionsImpl().updateArguments(args)
processCompilerExitCode(compileJvmNotIncrementally(compiler, logger,
val exitCode = compileJvmNotIncrementally(compiler, logger,
sourceRoots.kotlinSourceFiles, sourceRoots.javaSourceRoots, compileClasspath,
destinationDir, args))
destinationDir, args)
throwGradleExceptionIfError(exitCode)
}
}
@@ -222,14 +222,7 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
cleanupOnError()
}
when (exitCode) {
ExitCode.COMPILATION_ERROR -> throw GradleException("Compilation error. See log for more details")
ExitCode.INTERNAL_ERROR -> throw GradleException("Internal compiler error. See log for more details")
ExitCode.SCRIPT_EXECUTION_ERROR -> throw GradleException("Script execution error. See log for more details")
ExitCode.OK -> {
logger.kotlinInfo("Compilation succeeded")
}
}
throwGradleExceptionIfError(exitCode)
}
private fun handleKaptProperties() {
@@ -0,0 +1,14 @@
package org.jetbrains.kotlin.gradle.tasks
import org.gradle.api.GradleException
import org.jetbrains.kotlin.cli.common.ExitCode
fun throwGradleExceptionIfError(exitCode: ExitCode) {
when (exitCode) {
ExitCode.COMPILATION_ERROR -> throw GradleException("Compilation error. See log for more details")
ExitCode.INTERNAL_ERROR -> throw GradleException("Internal compiler error. See log for more details")
ExitCode.SCRIPT_EXECUTION_ERROR -> throw GradleException("Script execution error. See log for more details")
ExitCode.OK -> {}
else -> throw IllegalStateException("Unexpected exit code: $exitCode")
}
}