Kapt: Support symlinked Java source files (KT-26817)
This commit is contained in:
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.kapt3.base
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.kapt3.base.util.KaptLogger
|
import org.jetbrains.kotlin.kapt3.base.util.KaptLogger
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
class KaptPaths(
|
class KaptPaths(
|
||||||
val projectBaseDir: File?,
|
val projectBaseDir: File?,
|
||||||
@@ -23,11 +24,10 @@ class KaptPaths(
|
|||||||
|
|
||||||
fun collectJavaSourceFiles(): List<File> {
|
fun collectJavaSourceFiles(): List<File> {
|
||||||
return (javaSourceRoots + stubsOutputDir)
|
return (javaSourceRoots + stubsOutputDir)
|
||||||
.map { it.canonicalFile }
|
.sortedBy { Files.isSymbolicLink(it.toPath()) } // Get non-symbolic paths first
|
||||||
.distinct()
|
.flatMap { root -> root.walk().filter { it.isFile && it.extension == "java" }.toList() }
|
||||||
.flatMap { root ->
|
.sortedBy { Files.isSymbolicLink(it.toPath()) } // This time is for .java files
|
||||||
root.walk().filter { it.isFile && it.extension == "java" }.toList()
|
.distinctBy { it.canonicalPath }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.kapt.base.test
|
||||||
|
|
||||||
|
import junit.framework.TestCase
|
||||||
|
import org.jetbrains.kotlin.kapt3.base.KaptPaths
|
||||||
|
import org.junit.Test
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
|
class KaptPathsTest : TestCase() {
|
||||||
|
@Test
|
||||||
|
fun testSymbolicLinks() {
|
||||||
|
val tempDir = Files.createTempDirectory("kapt-test").toFile()
|
||||||
|
try {
|
||||||
|
fun File.writeJavaClass() = apply {
|
||||||
|
parentFile.mkdirs()
|
||||||
|
writeText("public class $nameWithoutExtension {}")
|
||||||
|
}
|
||||||
|
|
||||||
|
val outputDir = File(tempDir, "stubs").apply { mkdir() }
|
||||||
|
val otherDir = File(tempDir, "other").apply { mkdir() }
|
||||||
|
val javaRootDir = File(tempDir, "java").apply { mkdir() }
|
||||||
|
|
||||||
|
val simpleJava = File(tempDir, "Simple.java").writeJavaClass()
|
||||||
|
val otherJava = File(otherDir, "Other.java").writeJavaClass()
|
||||||
|
val notJava = File(otherDir, "NotJava.not").writeJavaClass()
|
||||||
|
File(javaRootDir, "JavaRoot.java").writeJavaClass()
|
||||||
|
|
||||||
|
val symlinkToOtherJava = Files.createSymbolicLink(File(tempDir, "Other.java").toPath(), otherJava.toPath()).toFile()
|
||||||
|
val symlinkToNotJava = Files.createSymbolicLink(File(tempDir, "NotJava.java").toPath(), notJava.toPath()).toFile()
|
||||||
|
val symlinkToJavaRootDir = Files.createSymbolicLink(File(tempDir, "java2").toPath(), javaRootDir.toPath()).toFile()
|
||||||
|
|
||||||
|
val javaRoots = listOf(simpleJava, symlinkToOtherJava, symlinkToNotJava, symlinkToJavaRootDir, javaRootDir)
|
||||||
|
|
||||||
|
val paths = KaptPaths(
|
||||||
|
projectBaseDir = null,
|
||||||
|
compileClasspath = emptyList(),
|
||||||
|
annotationProcessingClasspath = emptyList(),
|
||||||
|
javaSourceRoots = javaRoots,
|
||||||
|
sourcesOutputDir = outputDir,
|
||||||
|
classFilesOutputDir = outputDir,
|
||||||
|
stubsOutputDir = outputDir,
|
||||||
|
incrementalDataOutputDir = null
|
||||||
|
)
|
||||||
|
|
||||||
|
val javaSourceFiles = paths.collectJavaSourceFiles()
|
||||||
|
|
||||||
|
fun assertContains(path: String) {
|
||||||
|
val available by lazy { javaSourceFiles.joinToString { it.toRelativeString(tempDir) } }
|
||||||
|
assertTrue("Can't find path $path\nAvailable: $available",
|
||||||
|
javaSourceFiles.any { it.toRelativeString(tempDir) == path })
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(4, javaSourceFiles.size)
|
||||||
|
assertContains("Simple.java")
|
||||||
|
assertContains("Other.java")
|
||||||
|
assertContains("NotJava.java")
|
||||||
|
assertContains("java/JavaRoot.java")
|
||||||
|
} finally {
|
||||||
|
tempDir.deleteRecursively()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user