mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Allow plug-ins to contribute multiple compilers.
This commit is contained in:
parent
c2312a8854
commit
c1185fdf96
5 changed files with 84 additions and 49 deletions
|
@ -36,14 +36,24 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
}
|
||||
|
||||
fun sourceDirectories(project: Project, context: KobaltContext) : List<File> {
|
||||
val compilers = ActorUtils.selectAffinityActors(project, context, context.pluginInfo.compilerContributors)
|
||||
val sourceSuffixes = compilers.flatMap { it.sourceSuffixes }
|
||||
val result = sourceSuffixes.flatMap {
|
||||
sourceDirectories(project, it)
|
||||
}.toHashSet()
|
||||
val result = hashSetOf<File>()
|
||||
val compilerContributors = ActorUtils.selectAffinityActors(project, context,
|
||||
context.pluginInfo.compilerContributors)
|
||||
compilerContributors.forEach {
|
||||
it.compilersFor(project, context).forEach { compiler ->
|
||||
val sourceSuffixes = compilerContributors.flatMap { compiler.sourceSuffixes }
|
||||
result.addAll(sourceSuffixes.flatMap {
|
||||
sourceDirectories(project, it)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
return result.toList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Might be used by plug-ins.
|
||||
*/
|
||||
fun resDirectories(project: Project) : List<File> = sourceDirectories(project, "res")
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,18 @@ package com.beust.kobalt.api
|
|||
|
||||
import com.beust.kobalt.TaskResult
|
||||
|
||||
interface ICompilerContributor : IProjectAffinity {
|
||||
interface ICompiler {
|
||||
/**
|
||||
* The suffixes handled by this compiler (without the dot, e.g. "java" or "kt").
|
||||
*/
|
||||
val sourceSuffixes: List<String>
|
||||
|
||||
/**
|
||||
* Run the compilation based on the info.
|
||||
*/
|
||||
fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult
|
||||
}
|
||||
|
||||
interface ICompilerContributor : IProjectAffinity {
|
||||
fun compilersFor(project: Project, context: KobaltContext): List<ICompiler>
|
||||
}
|
||||
|
|
|
@ -165,23 +165,26 @@ open class JvmCompilerPlugin @Inject constructor(
|
|||
}
|
||||
val results = arrayListOf<TaskResult>()
|
||||
|
||||
val compilers = ActorUtils.selectAffinityActors(project, context, context.pluginInfo.compilerContributors)
|
||||
val compilerContributors = ActorUtils.selectAffinityActors(project, context,
|
||||
context.pluginInfo.compilerContributors)
|
||||
|
||||
var failedResult: TaskResult? = null
|
||||
if (compilers.isEmpty()) {
|
||||
if (compilerContributors.isEmpty()) {
|
||||
throw KobaltException("Couldn't find any compiler for project ${project.name}")
|
||||
} else {
|
||||
compilers.forEach { compiler ->
|
||||
if (containsSourceFiles(project, compiler)) {
|
||||
val info = createCompilerActionInfo(project, context, isTest, sourceDirectories,
|
||||
sourceSuffixes = compiler.sourceSuffixes)
|
||||
val thisResult = compiler.compile(project, context, info)
|
||||
results.add(thisResult)
|
||||
if (!thisResult.success && failedResult == null) {
|
||||
failedResult = thisResult
|
||||
compilerContributors.forEach { contributor ->
|
||||
contributor.compilersFor(project, context).forEach { compiler ->
|
||||
if (containsSourceFiles(project, compiler)) {
|
||||
val info = createCompilerActionInfo(project, context, isTest, sourceDirectories,
|
||||
sourceSuffixes = compiler.sourceSuffixes)
|
||||
val thisResult = compiler.compile(project, context, info)
|
||||
results.add(thisResult)
|
||||
if (!thisResult.success && failedResult == null) {
|
||||
failedResult = thisResult
|
||||
}
|
||||
} else {
|
||||
log(2, "Compiler $compiler not running on ${project.name} since no source files were found")
|
||||
}
|
||||
} else {
|
||||
log(2, "Compiler $compiler not running on ${project.name} since no source files were found")
|
||||
}
|
||||
}
|
||||
return if (failedResult != null) failedResult!!
|
||||
|
@ -189,7 +192,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun containsSourceFiles(project: Project, compiler: ICompilerContributor): Boolean {
|
||||
private fun containsSourceFiles(project: Project, compiler: ICompiler): Boolean {
|
||||
project.projectExtra.suffixesFound.forEach {
|
||||
if (compiler.sourceSuffixes.contains(it)) return true
|
||||
}
|
||||
|
@ -211,12 +214,14 @@ open class JvmCompilerPlugin @Inject constructor(
|
|||
fun taskJavadoc(project: Project): TaskResult {
|
||||
val docGenerator = ActorUtils.selectAffinityActor(project, context, context.pluginInfo.docContributors)
|
||||
if (docGenerator != null) {
|
||||
val compilers = ActorUtils.selectAffinityActors(project, context, context.pluginInfo.compilerContributors)
|
||||
val contributors = ActorUtils.selectAffinityActors(project, context, context.pluginInfo.compilerContributors)
|
||||
var result: TaskResult? = null
|
||||
compilers.forEach { compiler ->
|
||||
result = docGenerator.generateDoc(project, context, createCompilerActionInfo(project, context,
|
||||
isTest = false, sourceDirectories = sourceDirectories,
|
||||
sourceSuffixes = compiler.sourceSuffixes))
|
||||
contributors.forEach {
|
||||
it.compilersFor(project, context).forEach { compiler ->
|
||||
result = docGenerator.generateDoc(project, context, createCompilerActionInfo(project, context,
|
||||
isTest = false, sourceDirectories = sourceDirectories,
|
||||
sourceSuffixes = compiler.sourceSuffixes))
|
||||
}
|
||||
}
|
||||
return result!!
|
||||
} else {
|
||||
|
|
|
@ -41,23 +41,28 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
|||
// ICompilerFlagsContributor
|
||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
suffixesBeingCompiled: List<String>) =
|
||||
maybeCompilerArgs(sourceSuffixes, suffixesBeingCompiled,
|
||||
maybeCompilerArgs(compiler.sourceSuffixes, suffixesBeingCompiled,
|
||||
configurationFor(project)?.compilerArgs ?: listOf<String>())
|
||||
|
||||
// ICompilerContributor
|
||||
override val sourceSuffixes = listOf("java")
|
||||
val compiler = object: ICompiler {
|
||||
// ICompilerContributor
|
||||
override val sourceSuffixes = listOf("java")
|
||||
|
||||
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||
val result =
|
||||
if (info.sourceFiles.size > 0) {
|
||||
javaCompiler.compile(project, context, info)
|
||||
} else {
|
||||
warn("Couldn't find any source files to compile")
|
||||
TaskResult()
|
||||
}
|
||||
return result
|
||||
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo): TaskResult {
|
||||
val result =
|
||||
if (info.sourceFiles.size > 0) {
|
||||
javaCompiler.compile(project, context, info)
|
||||
} else {
|
||||
warn("Couldn't find any source files to compile")
|
||||
TaskResult()
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
override fun compilersFor(project: Project, context: KobaltContext) = arrayListOf(compiler)
|
||||
|
||||
// ITestSourceDirectoryContributor
|
||||
override fun testSourceDirectoriesFor(project: Project, context: KobaltContext)
|
||||
= project.sourceDirectoriesTest.map { File(it) }.toList()
|
||||
|
@ -65,7 +70,7 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
|||
// IBuildConfigContributor
|
||||
override fun affinity(project: Project) = if (project.projectExtra.suffixesFound.contains("java")) 1 else 0
|
||||
|
||||
override val buildConfigSuffix = sourceSuffixes[0]
|
||||
override val buildConfigSuffix = compiler.sourceSuffixes[0]
|
||||
|
||||
override fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String,
|
||||
variant: Variant, buildConfigs: List<BuildConfig>): String {
|
||||
|
|
|
@ -39,7 +39,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
|||
// ICompilerFlagsContributor
|
||||
override fun flagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||
suffixesBeingCompiled: List<String>) : List<String> {
|
||||
val result = maybeCompilerArgs(sourceSuffixes, suffixesBeingCompiled,
|
||||
val result = maybeCompilerArgs(compiler.sourceSuffixes, suffixesBeingCompiled,
|
||||
configurationFor(project)?.compilerArgs ?: listOf<String>())
|
||||
return result
|
||||
}
|
||||
|
@ -105,22 +105,26 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
|||
|
||||
// ICompilerContributor
|
||||
|
||||
override val sourceSuffixes = listOf("kt")
|
||||
val compiler = object: ICompiler {
|
||||
override val sourceSuffixes = listOf("kt")
|
||||
|
||||
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||
val result =
|
||||
if (info.sourceFiles.size > 0) {
|
||||
compilePrivate(project, info.dependencies, info.sourceFiles, info.outputDir, info.compilerArgs)
|
||||
} else {
|
||||
warn("Couldn't find any source files")
|
||||
TaskResult()
|
||||
}
|
||||
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo): TaskResult {
|
||||
val result =
|
||||
if (info.sourceFiles.size > 0) {
|
||||
compilePrivate(project, info.dependencies, info.sourceFiles, info.outputDir, info.compilerArgs)
|
||||
} else {
|
||||
warn("Couldn't find any source files")
|
||||
TaskResult()
|
||||
}
|
||||
|
||||
lp(project, "Compilation " + if (result.success) "succeeded" else "failed")
|
||||
return result
|
||||
lp(project, "Compilation " + if (result.success) "succeeded" else "failed")
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
// private val dokkaConfigurations = ArrayListMultimap.create<String, DokkaConfig>()
|
||||
override fun compilersFor(project: Project, context: KobaltContext) = arrayListOf(compiler)
|
||||
|
||||
// private val dokkaConfigurations = ArrayListMultimap.create<String, DokkaConfig>()
|
||||
//
|
||||
// fun addDokkaConfiguration(project: Project, dokkaConfig: DokkaConfig) {
|
||||
// dokkaConfigurations.put(project.name, dokkaConfig)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue