Apt working dir is now outside the Kotlin classes directory
This commit is contained in:
+13
-12
@@ -33,16 +33,17 @@ public class AnnotationProcessingManager(private val task: KotlinCompile) {
|
||||
|
||||
private companion object {
|
||||
val JAVA_FQNAME_PATTERN = "^([\\p{L}_$][\\p{L}\\p{N}_$]*\\.)*[\\p{L}_$][\\p{L}\\p{N}_$]*$".toRegex()
|
||||
val WRAPPERS_DIRECTORY = "wrappers"
|
||||
val ANNOTATIONS_FILENAME = "annotations.txt"
|
||||
}
|
||||
|
||||
fun getAnnotationFile(outputDirFile: String): File {
|
||||
val aptDir = File(outputDirFile, "0apt")
|
||||
aptDir.mkdirs()
|
||||
return File(aptDir, ANNOTATIONS_FILENAME)
|
||||
fun getAnnotationFile(): File {
|
||||
val aptWorkingDir = task.kotlinAptWorkingDir!!
|
||||
aptWorkingDir.mkdirs()
|
||||
return File(aptWorkingDir, "$WRAPPERS_DIRECTORY/$ANNOTATIONS_FILENAME")
|
||||
}
|
||||
|
||||
fun afterKotlinCompile(outputDirFile: File) {
|
||||
fun afterKotlinCompile() {
|
||||
val extraProperties = task.getExtensions().getExtraProperties()
|
||||
|
||||
val javaTask = try {
|
||||
@@ -54,20 +55,20 @@ public class AnnotationProcessingManager(private val task: KotlinCompile) {
|
||||
}
|
||||
|
||||
val aptFiles = task.aptFiles
|
||||
val aptWorkingDir = task.kotlinAptWorkingDir
|
||||
val aptOutputDir = task.kotlinAptOutputDir
|
||||
|
||||
if (javaTask == null || aptFiles.isEmpty() || aptOutputDir == null) return
|
||||
if (javaTask == null || aptFiles.isEmpty() || aptWorkingDir == null || aptOutputDir == null) return
|
||||
|
||||
val aptDir = File(outputDirFile, "0apt")
|
||||
val annotationDeclarationsFile = File(aptDir, ANNOTATIONS_FILENAME)
|
||||
val annotationDeclarationsFile = File(aptWorkingDir, ANNOTATIONS_FILENAME)
|
||||
|
||||
generateJavaHackFile(aptDir, javaTask)
|
||||
generateJavaHackFile(aptWorkingDir, javaTask)
|
||||
|
||||
javaTask.appendClasspath(aptFiles)
|
||||
|
||||
val annotationProcessorFqNames = lookupAnnotationProcessors(aptFiles)
|
||||
generateAnnotationProcessorStubs(aptDir, javaTask, annotationProcessorFqNames)
|
||||
|
||||
generateAnnotationProcessorStubs(aptWorkingDir, javaTask, annotationProcessorFqNames)
|
||||
|
||||
addGeneratedSourcesOutputToCompilerArgs(javaTask, aptOutputDir)
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ public class AnnotationProcessingManager(private val task: KotlinCompile) {
|
||||
}
|
||||
|
||||
private fun generateAnnotationProcessorStubs(aptDir: File, javaTask: JavaCompile, apFqNames: Set<String>) {
|
||||
val stubOutputDir = File(aptDir, "wrappers")
|
||||
val stubOutputDir = File(aptDir, "$WRAPPERS_DIRECTORY")
|
||||
|
||||
generateKotlinAptAnnotation(stubOutputDir)
|
||||
|
||||
|
||||
+3
-2
@@ -107,6 +107,7 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
||||
|
||||
public var aptFiles: Set<File> = emptySet()
|
||||
public var kotlinAptOutputDir: File? = null
|
||||
public var kotlinAptWorkingDir: File? = null
|
||||
|
||||
val srcDirsSources = HashSet<SourceDirectorySet>()
|
||||
|
||||
@@ -133,7 +134,7 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
||||
val pluginOptions = arrayListOf(*basePluginOptions)
|
||||
|
||||
if (aptFiles.isNotEmpty()) {
|
||||
val annotationDeclarationsFile = annotationProcessingManager.getAnnotationFile(args.destination)
|
||||
val annotationDeclarationsFile = annotationProcessingManager.getAnnotationFile()
|
||||
if (annotationDeclarationsFile.exists()) annotationDeclarationsFile.delete()
|
||||
pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:output=" + annotationDeclarationsFile)
|
||||
}
|
||||
@@ -173,7 +174,7 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
||||
FileUtils.copyDirectory(outputDirFile, getDestinationDir())
|
||||
}
|
||||
|
||||
annotationProcessingManager.afterKotlinCompile(outputDirFile)
|
||||
annotationProcessingManager.afterKotlinCompile()
|
||||
}
|
||||
|
||||
// override setSource to track source directory sets
|
||||
|
||||
+9
-5
@@ -167,8 +167,7 @@ class Kotlin2JvmSourceSetProcessor(
|
||||
kotlinTask.setProperty("aptFiles", aptConfiguration.resolve())
|
||||
}
|
||||
|
||||
val aptOutputDir = project.setAptOutputDirForSourceSet(kotlinTask, sourceSet.getName())
|
||||
sourceSet.getJava().add(project.files(aptOutputDir))
|
||||
project.setAptDirsForSourceSet(kotlinTask, sourceSet.getName())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +416,7 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
|
||||
|
||||
kotlinTask.setProperty("aptFiles", aptFiles)
|
||||
|
||||
val aptOutputDir = project.setAptOutputDirForSourceSet(kotlinTask, variantDataName)
|
||||
val aptOutputDir = project.setAptDirsForSourceSet(kotlinTask, variantDataName)
|
||||
variantData.addJavaSourceFoldersToModel(aptOutputDir)
|
||||
|
||||
kotlinTask doFirst {
|
||||
@@ -528,10 +527,15 @@ open class GradleUtils(val scriptHandler: ScriptHandler, val project: ProjectInt
|
||||
public fun resolveJsLibrary(): File = resolveDependencies(kotlinJsLibraryCoordinates()).first()
|
||||
}
|
||||
|
||||
private fun Project.setAptOutputDirForSourceSet(kotlinTask: AbstractCompile, sourceSetName: String): File {
|
||||
val aptOutputDir = file(File(getBuildDir(), "generated/source/kotlinApt"))
|
||||
private fun Project.setAptDirsForSourceSet(kotlinTask: AbstractCompile, sourceSetName: String): File {
|
||||
val aptOutputDir = File(getBuildDir(), "generated/source/kotlinApt")
|
||||
val aptOutputDirForVariant = File(aptOutputDir, sourceSetName)
|
||||
kotlinTask.setProperty("kotlinAptOutputDir", aptOutputDirForVariant)
|
||||
|
||||
val aptWorkingDir = File(getBuildDir(), "tmp/kotlinApt")
|
||||
val aptWorkingDirForVariant = File(aptWorkingDir, sourceSetName)
|
||||
kotlinTask.setProperty("kotlinAptWorkingDir", aptWorkingDirForVariant)
|
||||
|
||||
return aptOutputDirForVariant
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user