Skip to content

Commit 4c728a3

Browse files
committed
Factor out ExitCode-to-Result function
1 parent f62dab7 commit 4c728a3

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ class KotlinCompilation {
407407
it.reportOutputFiles = reportOutputFiles
408408
it.reportPerf = reportPerformance
409409
}
410-
411410
/** Performs the 1st and 2nd compilation step to generate stubs and run annotation processors */
412411
private fun stubsAndApt(sourceFiles: List<File>): ExitCode {
413412
if(annotationProcessors.isEmpty()) {
@@ -678,7 +677,7 @@ class KotlinCompilation {
678677
pluginClasspaths.forEach { filepath ->
679678
if (!filepath.exists()) {
680679
error("Plugin $filepath not found")
681-
return Result(ExitCode.INTERNAL_ERROR, classesDir, "")
680+
return makeResult(ExitCode.INTERNAL_ERROR)
682681
}
683682
}
684683

@@ -701,9 +700,7 @@ class KotlinCompilation {
701700
try {
702701
val exitCode = stubsAndApt(sourceFiles)
703702
if (exitCode != ExitCode.OK) {
704-
val messages = internalMessageBuffer.readUtf8()
705-
searchSystemOutForKnownErrors(messages)
706-
return Result(exitCode, classesDir, messages)
703+
return makeResult(exitCode)
707704
}
708705
} finally {
709706
KaptComponentRegistrar.threadLocalParameters.remove()
@@ -712,22 +709,22 @@ class KotlinCompilation {
712709
// step 3: compile Kotlin files
713710
compileKotlin(sourceFiles).let { exitCode ->
714711
if(exitCode != ExitCode.OK) {
715-
val messages = internalMessageBuffer.readUtf8()
716-
searchSystemOutForKnownErrors(messages)
717-
return Result(exitCode, classesDir, messages)
712+
return makeResult(exitCode)
718713
}
719714
}
720715
}
721716

722717
// step 4: compile Java files
723-
compileJava(sourceFiles).let { exitCode ->
724-
val messages = internalMessageBuffer.readUtf8()
718+
return makeResult(compileJava(sourceFiles))
719+
}
725720

726-
if(exitCode != ExitCode.OK)
727-
searchSystemOutForKnownErrors(messages)
721+
private fun makeResult(exitCode: ExitCode): Result {
722+
val messages = internalMessageBuffer.readUtf8()
728723

729-
return Result(exitCode, classesDir, messages)
730-
}
724+
if(exitCode != ExitCode.OK)
725+
searchSystemOutForKnownErrors(messages)
726+
727+
return Result(exitCode, classesDir, messages)
731728
}
732729

733730
private fun commonClasspaths() = mutableListOf<File>().apply {

0 commit comments

Comments
 (0)