mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Clean generated directory in AptPlugin.
Fixes https://github.com/cbeust/kobalt/issues/357.
This commit is contained in:
parent
01fc80c904
commit
8f99f81bc0
1 changed files with 16 additions and 54 deletions
|
@ -2,14 +2,12 @@ package com.beust.kobalt.plugin.apt
|
||||||
|
|
||||||
import com.beust.kobalt.api.*
|
import com.beust.kobalt.api.*
|
||||||
import com.beust.kobalt.api.annotation.Directive
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
import com.beust.kobalt.internal.ActorUtils
|
|
||||||
import com.beust.kobalt.internal.CompilerUtils
|
|
||||||
import com.beust.kobalt.maven.DependencyManager
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
import com.beust.kobalt.misc.warn
|
||||||
import com.google.common.collect.ArrayListMultimap
|
import com.google.common.collect.ArrayListMultimap
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@ -21,25 +19,22 @@ import javax.inject.Singleton
|
||||||
* (outputDir, etc...).
|
* (outputDir, etc...).
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, val compilerUtils: CompilerUtils)
|
class AptPlugin @Inject constructor(val dependencyManager: DependencyManager)
|
||||||
: BasePlugin(), ICompilerFlagContributor, ISourceDirectoryContributor, ITaskContributor {
|
: BasePlugin(), ICompilerFlagContributor, ISourceDirectoryContributor {
|
||||||
|
|
||||||
// ISourceDirectoryContributor
|
// ISourceDirectoryContributor
|
||||||
|
|
||||||
|
private fun generatedDir(project: Project, outputDir: String) : File
|
||||||
|
= File(KFiles.joinDir(project.directory, KFiles.KOBALT_BUILD_DIR, outputDir))
|
||||||
|
|
||||||
override fun sourceDirectoriesFor(project: Project, context: KobaltContext): List<File> {
|
override fun sourceDirectoriesFor(project: Project, context: KobaltContext): List<File> {
|
||||||
val result = arrayListOf<File>()
|
val result = arrayListOf<File>()
|
||||||
aptConfigs[project.name]?.let { config ->
|
aptConfigs[project.name]?.let { config ->
|
||||||
result.add(File(
|
result.add(generatedDir(project, config.outputDir))
|
||||||
KFiles.joinDir(project.directory,
|
|
||||||
KFiles.KOBALT_BUILD_DIR,
|
|
||||||
config.outputDir)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kaptConfigs[project.name]?.let { config ->
|
kaptConfigs[project.name]?.let { config ->
|
||||||
result.add(File(
|
result.add(generatedDir(project, config.outputDir))
|
||||||
KFiles.joinDir(project.directory,
|
|
||||||
KFiles.KOBALT_BUILD_DIR,
|
|
||||||
config.outputDir)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -54,47 +49,14 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
||||||
override val name = PLUGIN_NAME
|
override val name = PLUGIN_NAME
|
||||||
|
|
||||||
override fun apply(project: Project, context: KobaltContext) {
|
override fun apply(project: Project, context: KobaltContext) {
|
||||||
}
|
listOf(aptConfigs[project.name]?.outputDir, aptConfigs[project.name]?.outputDir)
|
||||||
|
.filterNotNull()
|
||||||
// ITaskContributor
|
.map { generatedDir(project, it) }
|
||||||
override fun tasksFor(project: Project, context: KobaltContext) : List<DynamicTask> {
|
.forEach {
|
||||||
// val kapt = kaptConfigs[project.name]
|
context.logger.log(project.name, 1, "Deleting " + it.absolutePath)
|
||||||
// if (kapt != null) {
|
val success = it.deleteRecursively()
|
||||||
// return listOf(DynamicTask(this, "kapt", "Run kapt", project = project,
|
if (! success) warn(" Couldn't delete " + it.absolutePath)
|
||||||
// reverseDependsOn = listOf(JvmCompilerPlugin.TASK_COMPILE),
|
|
||||||
// group = AnnotationDefault.GROUP,
|
|
||||||
// closure = { project ->
|
|
||||||
// runApt(project, context)
|
|
||||||
// TaskResult()
|
|
||||||
// }))
|
|
||||||
// } else {
|
|
||||||
return emptyList()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun runApt(project: Project, context: KobaltContext) {
|
|
||||||
val kapt = kaptConfigs[project.name]
|
|
||||||
if (kapt != null) {
|
|
||||||
|
|
||||||
val sourceDir = Files.createTempDirectory("kobalt").toFile()
|
|
||||||
val javaFile = File(sourceDir, "A.java").apply {
|
|
||||||
appendText("class A {}")
|
|
||||||
}
|
}
|
||||||
val compilerContributors = context.pluginInfo.compilerContributors
|
|
||||||
ActorUtils.selectAffinityActors(project, context,
|
|
||||||
context.pluginInfo.compilerContributors)
|
|
||||||
|
|
||||||
val allCompilers = compilerContributors.flatMap { it.compilersFor(project, context) }.sorted()
|
|
||||||
val javaCompiler = allCompilers.filter { it.sourceSuffixes.contains("java") }[0]
|
|
||||||
|
|
||||||
val dependencies = dependencyManager.calculateDependencies(project, context)
|
|
||||||
val info = CompilerActionInfo(sourceDir.absolutePath, dependencies,
|
|
||||||
listOf(javaFile.absolutePath), listOf("java"), File(sourceDir, "generated"),
|
|
||||||
listOf(), listOf(), context.internalContext.forceRecompile)
|
|
||||||
|
|
||||||
val results = compilerUtils.invokeCompiler(project, context, javaCompiler, info)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generated(project: Project, context: KobaltContext, outputDir: String) =
|
private fun generated(project: Project, context: KobaltContext, outputDir: String) =
|
||||||
|
@ -109,7 +71,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
||||||
val result = arrayListOf<String>()
|
val result = arrayListOf<String>()
|
||||||
|
|
||||||
fun addFlags(outputDir: String) {
|
fun addFlags(outputDir: String) {
|
||||||
aptDependencies[project.name]?.let { aptDependencies ->
|
aptDependencies[project.name]?.let {
|
||||||
result.add("-s")
|
result.add("-s")
|
||||||
result.add(generated(project, context, outputDir))
|
result.add(generated(project, context, outputDir))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue