@@ -38,6 +38,7 @@ import java.net.URLClassLoader
3838import java.nio.file.Path
3939import javax.annotation.processing.Processor
4040import javax.tools.*
41+ import kotlin.io.path.absolutePathString
4142
4243data class PluginOption (val pluginId : PluginId , val optionName : OptionName , val optionValue : OptionValue )
4344
@@ -350,7 +351,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
350351 }
351352
352353 /* * Performs the 1st and 2nd compilation step to generate stubs and run annotation processors */
353- private fun stubsAndApt (sourceFiles : List <File >): ExitCode {
354+ private fun stubsAndApt (sourceFiles : List <Path >): ExitCode {
354355 if (annotationProcessors.isEmpty()) {
355356 log(" No services were given. Not running kapt steps." )
356357 return ExitCode .OK
@@ -396,10 +397,10 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
396397 )
397398 )
398399
399- val kotlinSources = sourceFiles.filter(File ::hasKotlinFileExtension)
400- val javaSources = sourceFiles.filter(File ::hasJavaFileExtension)
400+ val kotlinSources = sourceFiles.filter(Path ::hasKotlinFileExtension)
401+ val javaSources = sourceFiles.filter(Path ::hasJavaFileExtension)
401402
402- val sourcePaths = mutableListOf<File >().apply {
403+ val sourcePaths = mutableListOf<Path >().apply {
403404 addAll(javaSources)
404405
405406 if (kotlinSources.isNotEmpty()) {
@@ -414,9 +415,9 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
414415 Java files might generate Kotlin files which then need to be compiled in the
415416 compileKotlin step before the compileJava step). So instead we trick K2JVMCompiler
416417 by just including an empty .kt-File. */
417- add(SourceFile .new(" emptyKotlinFile.kt" , " " ).writeIfNeeded(kaptBaseDir))
418+ add(SourceFile .new(" emptyKotlinFile.kt" , " " ).writeIfNeeded(kaptBaseDir).toPath() )
418419 }
419- }.map(File ::getAbsolutePath ).distinct()
420+ }.map(Path ::absolutePathString ).distinct()
420421
421422 if (! isJdk9OrLater()) {
422423 try {
@@ -446,10 +447,10 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
446447 }
447448
448449 /* * Performs the 3rd compilation step to compile Kotlin source files */
449- private fun compileJvmKotlin (sourceFiles : List <File >): ExitCode {
450- val sources = sourceFiles +
451- kaptKotlinGeneratedDir.listFilesRecursively() +
452- kaptSourceDir.listFilesRecursively()
450+ private fun compileJvmKotlin (sourceFiles : List <Path >): ExitCode {
451+ val sources = sourcesWithPath.map { it.path } +
452+ kaptKotlinGeneratedDir.toPath(). listFilesRecursively() +
453+ kaptSourceDir.toPath(). listFilesRecursively()
453454
454455 return compileKotlin(sources, K2JVMCompiler (), commonK2JVMArgs())
455456 }
@@ -485,9 +486,9 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
485486 }
486487
487488 /* * Performs the 4th compilation step to compile Java source files */
488- private fun compileJava (sourceFiles : List <File >): ExitCode {
489- val javaSources = (sourceFiles + kaptSourceDir.listFilesRecursively())
490- .filterNot< File >( File ::hasKotlinFileExtension)
489+ private fun compileJava (sourceFiles : List <Path >): ExitCode {
490+ val javaSources = (sourceFiles + kaptSourceDir.toPath(). listFilesRecursively())
491+ .filterNot( Path ::hasKotlinFileExtension)
491492
492493 if (javaSources.isEmpty())
493494 return ExitCode .OK
@@ -508,7 +509,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
508509 val isJavac9OrLater = isJavac9OrLater(getJavacVersionString(javacCommand))
509510 val javacArgs = baseJavacArgs(isJavac9OrLater)
510511
511- val javacProc = ProcessBuilder (listOf (javacCommand) + javacArgs + javaSources.map(File ::getAbsolutePath ))
512+ val javacProc = ProcessBuilder (listOf (javacCommand) + javacArgs + javaSources.map(Path ::absolutePathString ))
512513 .directory(workingDir)
513514 .redirectErrorStream(true )
514515 .start()
@@ -558,7 +559,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
558559 OutputStreamWriter (internalMessageStream), javaFileManager,
559560 diagnosticCollector, javacArgs,
560561 /* classes to be annotation processed */ null ,
561- javaSources.map { FileJavaFileObject (it) }
562+ javaSources.map { FileJavaFileObject (it.toFile() ) }
562563 .filter { it.kind == JavaFileObject .Kind .SOURCE }
563564 ).call()
564565
@@ -591,9 +592,6 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
591592 kaptIncrementalDataDir.mkdirs()
592593 kaptKotlinGeneratedDir.mkdirs()
593594
594- // write given sources to working directory
595- val sourceFiles = sources.map { it.writeIfNeeded(sourcesDir) }
596-
597595 pluginClasspaths.forEach { filepath ->
598596 if (! filepath.exists()) {
599597 error(" Plugin $filepath not found" )
@@ -618,7 +616,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
618616 withSystemProperty(" idea.use.native.fs.for.win" , " false" ) {
619617 // step 1 and 2: generate stubs and run annotation processors
620618 try {
621- val exitCode = stubsAndApt(sourceFiles )
619+ val exitCode = stubsAndApt(sourcesWithPath.map { it.path } )
622620 if (exitCode != ExitCode .OK ) {
623621 return makeResult(exitCode)
624622 }
@@ -627,15 +625,15 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
627625 }
628626
629627 // step 3: compile Kotlin files
630- compileJvmKotlin(sourceFiles ).let { exitCode ->
628+ compileJvmKotlin(sourcesWithPath.map { it.path } ).let { exitCode ->
631629 if (exitCode != ExitCode .OK ) {
632630 return makeResult(exitCode)
633631 }
634632 }
635633 }
636634
637635 // step 4: compile Java files
638- return makeResult(compileJava(sourceFiles ))
636+ return makeResult(compileJava(sourcesWithPath.map { it.path } ))
639637 }
640638
641639 private fun makeResult (exitCode : ExitCode ): Result {
0 commit comments