Skip to content

Commit 88e61c3

Browse files
committed
Add properties to get only specific types of generated files from the result
1 parent 0a46eb6 commit 88e61c3

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

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

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -314,23 +314,41 @@ class KotlinCompilation {
314314
}
315315

316316
/** Result of the compilation */
317-
class Result(
317+
inner class Result(
318+
/** The exit code of the compilation */
318319
val exitCode: ExitCode,
319-
/**
320-
* The class, resource and intermediate source files generated during the compilation.
321-
* Does not include stub files and kapt incremental data.
322-
*/
323-
val generatedFiles: Collection<File>,
324-
/** The directory where only the final output class and resources files will be */
325-
val outputDirectory: File,
326320
/** Messages that were printed by the compilation */
327321
val messages: String
328322
) {
329323
/** class loader to load the compile classes */
330324
val classLoader = URLClassLoader(arrayOf(outputDirectory.toURI().toURL()),
331325
this::class.java.classLoader)
332-
}
333326

327+
/** The directory where only the final output class and resources files will be */
328+
val outputDirectory: File get() = classesDir
329+
330+
/**
331+
* Intermediate source and resource files generated by the annotation processor that
332+
* will be compiled in the next steps.
333+
*/
334+
val sourcesGeneratedByAnnotationProcessor: List<File>
335+
= kaptSourceDir.listFilesRecursively() + kaptKotlinGeneratedDir.listFilesRecursively()
336+
337+
/**
338+
* Compiled class and resource files that are the final result of the compilation.
339+
*/
340+
val compiledClassAndResourceFiles: List<File> = outputDirectory.listFilesRecursively()
341+
342+
/** Stub files generated by kapt */
343+
val generatedStubFiles: List<File> = kaptStubsDir.listFilesRecursively()
344+
345+
/**
346+
* The class, resource and intermediate source files generated during the compilation.
347+
* Does not include stub files and kapt incremental data.
348+
*/
349+
val generatedFiles: Collection<File>
350+
= sourcesGeneratedByAnnotationProcessor + compiledClassAndResourceFiles + generatedStubFiles
351+
}
334352

335353
// setup common arguments for the two kotlinc calls
336354
private fun commonK2JVMArgs() = K2JVMCompilerArguments().also { it ->
@@ -730,12 +748,7 @@ class KotlinCompilation {
730748
if(exitCode != ExitCode.OK)
731749
searchSystemOutForKnownErrors(messages)
732750

733-
val classAndResFiles = classesDir.listFilesRecursively()
734-
val kaptGeneratedKotlinFiles = kaptKotlinGeneratedDir.listFilesRecursively()
735-
val kaptGeneratedJavaFiles = kaptSourceDir.listFilesRecursively()
736-
val generatedFiles = classAndResFiles + kaptGeneratedJavaFiles + kaptGeneratedKotlinFiles
737-
738-
return Result(exitCode, generatedFiles, classesDir, messages)
751+
return Result(exitCode, messages)
739752
}
740753

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

0 commit comments

Comments
 (0)