mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
kapt work.
This commit is contained in:
parent
814eb57396
commit
a4a044c6b9
7 changed files with 93 additions and 14 deletions
|
@ -79,7 +79,9 @@ class Plugins @Inject constructor (val taskManagerProvider : Provider<TaskManage
|
|||
|
||||
// Collect all the tasks from the task contributors
|
||||
context.pluginInfo.taskContributors.forEach {
|
||||
taskManager.dynamicTasks.addAll(it.tasksFor(context))
|
||||
projects.forEach { project ->
|
||||
taskManager.dynamicTasks.addAll(it.tasksFor(project, context))
|
||||
}
|
||||
}
|
||||
|
||||
// Now that we have collected all static and dynamic tasks, turn them all into plug-in tasks
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.beust.kobalt.internal.TaskResult2
|
|||
* to implement this interface.
|
||||
*/
|
||||
interface ITaskContributor : IContributor {
|
||||
fun tasksFor(context: KobaltContext) : List<DynamicTask>
|
||||
fun tasksFor(project: Project, context: KobaltContext) : List<DynamicTask>
|
||||
}
|
||||
|
||||
class DynamicTask(override val plugin: IPlugin, override val name: String, override val doc: String,
|
||||
|
|
|
@ -63,5 +63,5 @@ class TaskContributor @Inject constructor(val incrementalManagerFactory: Increme
|
|||
}
|
||||
}
|
||||
|
||||
override fun tasksFor(context: KobaltContext) : List<DynamicTask> = dynamicTasks
|
||||
override fun tasksFor(project: Project, context: KobaltContext) : List<DynamicTask> = dynamicTasks
|
||||
}
|
||||
|
|
|
@ -34,10 +34,10 @@ class CompilerUtils @Inject constructor(val files: KFiles,
|
|||
// once and pass them
|
||||
val info = createCompilerActionInfo(project, context, compiler, isTest,
|
||||
sourceDirectories, sourceSuffixes = compiler.sourceSuffixes)
|
||||
val thisResult = compiler.compile(project, context, info)
|
||||
results.add(thisResult)
|
||||
if (!thisResult.success && failedResult == null) {
|
||||
failedResult = thisResult
|
||||
val thisResult = invokeCompiler(project, context, compiler, info)
|
||||
results.addAll(thisResult.successResults)
|
||||
if (failedResult == null) {
|
||||
failedResult = thisResult.failedResult
|
||||
}
|
||||
} else {
|
||||
log(2, "Compiler $compiler not running on ${project.name} since no source files were found")
|
||||
|
@ -46,6 +46,18 @@ class CompilerUtils @Inject constructor(val files: KFiles,
|
|||
return CompilerResult(results, failedResult)
|
||||
}
|
||||
|
||||
fun invokeCompiler(project: Project, context: KobaltContext, compiler: ICompiler, info: CompilerActionInfo)
|
||||
: CompilerResult {
|
||||
val results = arrayListOf<TaskResult>()
|
||||
var failedResult: TaskResult? = null
|
||||
val thisResult = compiler.compile(project, context, info)
|
||||
results.add(thisResult)
|
||||
if (!thisResult.success && failedResult == null) {
|
||||
failedResult = thisResult
|
||||
}
|
||||
return CompilerResult(results, failedResult)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a CompilerActionInfo (all the information that a compiler needs to know) for the given parameters.
|
||||
* Runs all the contributors and interceptors relevant to that task.
|
||||
|
@ -55,7 +67,7 @@ class CompilerUtils @Inject constructor(val files: KFiles,
|
|||
copyResources(project, context, SourceSet.of(isTest))
|
||||
|
||||
val fullClasspath = if (isTest) dependencyManager.testDependencies(project, context)
|
||||
else dependencyManager.dependencies(project, context)
|
||||
else dependencyManager.dependencies(project, context)
|
||||
|
||||
// Remove all the excluded dependencies from the classpath
|
||||
val classpath = fullClasspath.filter {
|
||||
|
@ -66,7 +78,6 @@ class CompilerUtils @Inject constructor(val files: KFiles,
|
|||
else File(project.classesDir(context))
|
||||
buildDirectory.mkdirs()
|
||||
|
||||
|
||||
val initialSourceDirectories = ArrayList<File>(sourceDirectories)
|
||||
// Source directories from the contributors
|
||||
val contributedSourceDirs =
|
||||
|
|
|
@ -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