@@ -38,6 +38,7 @@ import java.net.URLClassLoader
38
38
import java.nio.file.Path
39
39
import javax.annotation.processing.Processor
40
40
import javax.tools.*
41
+ import kotlin.io.path.absolutePathString
41
42
42
43
data class PluginOption (val pluginId : PluginId , val optionName : OptionName , val optionValue : OptionValue )
43
44
@@ -350,7 +351,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
350
351
}
351
352
352
353
/* * 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 {
354
355
if (annotationProcessors.isEmpty()) {
355
356
log(" No services were given. Not running kapt steps." )
356
357
return ExitCode .OK
@@ -396,10 +397,10 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
396
397
)
397
398
)
398
399
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)
401
402
402
- val sourcePaths = mutableListOf<File >().apply {
403
+ val sourcePaths = mutableListOf<Path >().apply {
403
404
addAll(javaSources)
404
405
405
406
if (kotlinSources.isNotEmpty()) {
@@ -414,9 +415,9 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
414
415
Java files might generate Kotlin files which then need to be compiled in the
415
416
compileKotlin step before the compileJava step). So instead we trick K2JVMCompiler
416
417
by just including an empty .kt-File. */
417
- add(SourceFile .new(" emptyKotlinFile.kt" , " " ).writeIfNeeded(kaptBaseDir))
418
+ add(SourceFile .new(" emptyKotlinFile.kt" , " " ).writeIfNeeded(kaptBaseDir).toPath() )
418
419
}
419
- }.map(File ::getAbsolutePath ).distinct()
420
+ }.map(Path ::absolutePathString ).distinct()
420
421
421
422
if (! isJdk9OrLater()) {
422
423
try {
@@ -446,10 +447,10 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
446
447
}
447
448
448
449
/* * 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()
453
454
454
455
return compileKotlin(sources, K2JVMCompiler (), commonK2JVMArgs())
455
456
}
@@ -485,9 +486,9 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
485
486
}
486
487
487
488
/* * 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)
491
492
492
493
if (javaSources.isEmpty())
493
494
return ExitCode .OK
@@ -508,7 +509,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
508
509
val isJavac9OrLater = isJavac9OrLater(getJavacVersionString(javacCommand))
509
510
val javacArgs = baseJavacArgs(isJavac9OrLater)
510
511
511
- val javacProc = ProcessBuilder (listOf (javacCommand) + javacArgs + javaSources.map(File ::getAbsolutePath ))
512
+ val javacProc = ProcessBuilder (listOf (javacCommand) + javacArgs + javaSources.map(Path ::absolutePathString ))
512
513
.directory(workingDir)
513
514
.redirectErrorStream(true )
514
515
.start()
@@ -558,7 +559,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
558
559
OutputStreamWriter (internalMessageStream), javaFileManager,
559
560
diagnosticCollector, javacArgs,
560
561
/* classes to be annotation processed */ null ,
561
- javaSources.map { FileJavaFileObject (it) }
562
+ javaSources.map { FileJavaFileObject (it.toFile() ) }
562
563
.filter { it.kind == JavaFileObject .Kind .SOURCE }
563
564
).call()
564
565
@@ -591,9 +592,6 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
591
592
kaptIncrementalDataDir.mkdirs()
592
593
kaptKotlinGeneratedDir.mkdirs()
593
594
594
- // write given sources to working directory
595
- val sourceFiles = sources.map { it.writeIfNeeded(sourcesDir) }
596
-
597
595
pluginClasspaths.forEach { filepath ->
598
596
if (! filepath.exists()) {
599
597
error(" Plugin $filepath not found" )
@@ -618,7 +616,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
618
616
withSystemProperty(" idea.use.native.fs.for.win" , " false" ) {
619
617
// step 1 and 2: generate stubs and run annotation processors
620
618
try {
621
- val exitCode = stubsAndApt(sourceFiles )
619
+ val exitCode = stubsAndApt(sourcesWithPath.map { it.path } )
622
620
if (exitCode != ExitCode .OK ) {
623
621
return makeResult(exitCode)
624
622
}
@@ -627,15 +625,15 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
627
625
}
628
626
629
627
// step 3: compile Kotlin files
630
- compileJvmKotlin(sourceFiles ).let { exitCode ->
628
+ compileJvmKotlin(sourcesWithPath.map { it.path } ).let { exitCode ->
631
629
if (exitCode != ExitCode .OK ) {
632
630
return makeResult(exitCode)
633
631
}
634
632
}
635
633
}
636
634
637
635
// step 4: compile Java files
638
- return makeResult(compileJava(sourceFiles ))
636
+ return makeResult(compileJava(sourcesWithPath.map { it.path } ))
639
637
}
640
638
641
639
private fun makeResult (exitCode : ExitCode ): Result {
0 commit comments