mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
kapt work.
This commit is contained in:
parent
814eb57396
commit
a4a044c6b9
7 changed files with 93 additions and 14 deletions
|
@ -127,6 +127,6 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<Applica
|
|||
}
|
||||
|
||||
//ITaskContributor
|
||||
override fun tasksFor(context: KobaltContext): List<DynamicTask> = taskContributor.dynamicTasks
|
||||
override fun tasksFor(project: Project, context: KobaltContext): List<DynamicTask> = taskContributor.dynamicTasks
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,16 @@ package com.beust.kobalt.plugin.apt
|
|||
|
||||
import com.beust.kobalt.api.*
|
||||
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.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.google.common.collect.ArrayListMultimap
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.util.*
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
|
@ -18,8 +22,10 @@ import javax.inject.Singleton
|
|||
* (outputDir, etc...).
|
||||
*/
|
||||
@Singleton
|
||||
class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, val configActor: ConfigActor<AptConfig>)
|
||||
: BasePlugin(), ICompilerFlagContributor, ISourceDirectoryContributor, IConfigActor<AptConfig> by configActor {
|
||||
class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, val configActor: ConfigActor<AptConfig>,
|
||||
val compilerUtils: CompilerUtils)
|
||||
: BasePlugin(), ICompilerFlagContributor, ISourceDirectoryContributor, ITaskContributor,
|
||||
IConfigActor<AptConfig> by configActor {
|
||||
|
||||
// ISourceDirectoryContributor
|
||||
|
||||
|
@ -45,6 +51,51 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
|||
|
||||
override val name = PLUGIN_NAME
|
||||
|
||||
override fun apply(project: Project, context: KobaltContext) {
|
||||
}
|
||||
|
||||
// ITaskContributor
|
||||
override fun tasksFor(project: Project, context: KobaltContext) : List<DynamicTask> {
|
||||
// val kapt = kaptConfigs[project.name]
|
||||
// if (kapt != null) {
|
||||
// return listOf(DynamicTask(this, "kapt", "Run kapt", project = project,
|
||||
// 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())
|
||||
|
||||
val results = compilerUtils.invokeCompiler(project, context, javaCompiler, info)
|
||||
println("RESULTS: $results")
|
||||
}
|
||||
}
|
||||
|
||||
private fun generated(project: Project, context: KobaltContext, outputDir: String) =
|
||||
KFiles.joinAndMakeDir(project.directory, project.buildDirectory, outputDir,
|
||||
context.variant.toIntermediateDir())
|
||||
|
@ -55,6 +106,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
|||
if (!suffixesBeingCompiled.contains("java")) return emptyList()
|
||||
|
||||
val result = arrayListOf<String>()
|
||||
|
||||
configurationFor(project)?.let { config ->
|
||||
aptDependencies[project.name]?.let { aptDependencies ->
|
||||
result.add("-s")
|
||||
|
@ -70,12 +122,16 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
|||
fun addAptDependency(dependencies: Dependencies, it: String) {
|
||||
aptDependencies.put(dependencies.project.name, it)
|
||||
}
|
||||
|
||||
private val kaptConfigs: HashMap<String, KaptConfig> = hashMapOf()
|
||||
|
||||
fun addKaptConfig(project: Project, kapt: KaptConfig) = kaptConfigs.put(project.name, kapt)
|
||||
}
|
||||
|
||||
class AptConfig(var outputDir: String = "generated/source/apt")
|
||||
|
||||
@Directive
|
||||
public fun Project.apt(init: AptConfig.() -> Unit) {
|
||||
fun Project.apt(init: AptConfig.() -> Unit) {
|
||||
AptConfig().let {
|
||||
it.init()
|
||||
(Kobalt.findPlugin(AptPlugin.PLUGIN_NAME) as AptPlugin).addConfiguration(this, it)
|
||||
|
@ -88,3 +144,13 @@ fun Dependencies.apt(vararg dep: String) {
|
|||
(Kobalt.findPlugin(AptPlugin.PLUGIN_NAME) as AptPlugin).addAptDependency(this, it)
|
||||
}
|
||||
}
|
||||
|
||||
class KaptConfig(var outputDir: String = "generated/source/apt")
|
||||
|
||||
@Directive
|
||||
fun Project.kapt(init: KaptConfig.() -> Unit) {
|
||||
KaptConfig().let {
|
||||
it.init()
|
||||
(Kobalt.findPlugin(AptPlugin.PLUGIN_NAME) as AptPlugin).addKaptConfig(this, it)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
}
|
||||
|
||||
//ITaskContributor
|
||||
override fun tasksFor(context: KobaltContext): List<DynamicTask> = taskContributor.dynamicTasks
|
||||
override fun tasksFor(project: Project, context: KobaltContext): List<DynamicTask> = taskContributor.dynamicTasks
|
||||
}
|
||||
|
||||
@Directive
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue