Skip to content

Commit 8212e5e

Browse files
committed
Merge remote-tracking branch 'refs/remotes/GavinRay97/GavinRay97-patch-1'
# Conflicts: # core/src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt
2 parents 9f829bf + 84a9a2d commit 8212e5e

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,34 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
354354
args.disableStandardScript = disableStandardScript
355355
}
356356

357+
private fun convertJavacArgumentsListToMap(options: List<String>): Map<String, String> {
358+
val result = mutableMapOf<String, String>()
359+
var i = 0
360+
361+
while (i < options.size) {
362+
val option = options[i]
363+
if (option.startsWith("-") || option.startsWith("--")) {
364+
// Check if the option contains an equal sign
365+
if (option.contains("=")) {
366+
val (key, value) = option.split("=", limit = 2)
367+
result[key] = value
368+
} else {
369+
// Check if the next element is a value for this option
370+
val value = if (i + 1 < options.size && !options[i + 1].startsWith("-")) {
371+
i++ // Increment the index to skip the value in the next iteration
372+
options[i]
373+
} else {
374+
""
375+
}
376+
result[option] = value
377+
}
378+
}
379+
i++
380+
}
381+
382+
return result
383+
}
384+
357385
/** Performs the 1st and 2nd compilation step to generate stubs and run annotation processors */
358386
private fun stubsAndApt(sourceFiles: List<Path>): ExitCode {
359387
if(annotationProcessors.isEmpty()) {
@@ -373,14 +401,16 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
373401

374402
it.mode = AptMode.STUBS_AND_APT
375403

376-
it.flags.apply {
404+
it.javacOptions.putAll(convertJavacArgumentsListToMap(javacArguments))
405+
406+
it.flags.apply {
377407
addAll(kaptFlags)
378408

379409
if (verbose) {
380410
addAll(KaptFlag.MAP_DIAGNOSTIC_LOCATIONS, KaptFlag.VERBOSE)
381411
}
382412
}
383-
}
413+
}
384414

385415
val compilerMessageCollector = PrintingMessageCollector(
386416
internalMessageStream, MessageRenderer.GRADLE_STYLE, verbose

0 commit comments

Comments
 (0)