mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Groovy plug-in.
This commit is contained in:
parent
9cea38dedb
commit
b59bf3b8c0
4 changed files with 103 additions and 2 deletions
|
@ -26,7 +26,8 @@ abstract class BaseJvmPlugin<T>(open val configActor: ConfigActor<T>) :
|
||||||
// IBuildConfigContributor
|
// IBuildConfigContributor
|
||||||
|
|
||||||
protected fun sourceFileCount(project: Project)
|
protected fun sourceFileCount(project: Project)
|
||||||
= KFiles.findSourceFiles(project.directory, project.sourceDirectories, sourceSuffixes()).size
|
= KFiles.findSourceFiles(project.directory, project.sourceDirectories, sourceSuffixes()).size +
|
||||||
|
KFiles.findSourceFiles(project.directory, project.sourceDirectoriesTest, sourceSuffixes()).size
|
||||||
|
|
||||||
fun affinity(project: Project) = sourceFileCount(project)
|
fun affinity(project: Project) = sourceFileCount(project)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.beust.kobalt.plugin.groovy
|
||||||
|
|
||||||
|
import com.beust.kobalt.TaskResult
|
||||||
|
import com.beust.kobalt.api.CompilerActionInfo
|
||||||
|
import com.beust.kobalt.api.ICompiler
|
||||||
|
import com.beust.kobalt.api.KobaltContext
|
||||||
|
import com.beust.kobalt.api.Project
|
||||||
|
import com.beust.kobalt.internal.ICompilerAction
|
||||||
|
import com.beust.kobalt.internal.JvmCompiler
|
||||||
|
import com.beust.kobalt.internal.ParallelLogger
|
||||||
|
import com.beust.kobalt.misc.Strings
|
||||||
|
import com.beust.kobalt.misc.log
|
||||||
|
import com.google.inject.Inject
|
||||||
|
import com.google.inject.Singleton
|
||||||
|
import groovy.lang.GroovyClassLoader
|
||||||
|
import org.codehaus.groovy.control.CompilerConfiguration
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class GroovyCompiler @Inject constructor(val kobaltLog: ParallelLogger, val jvmCompiler: JvmCompiler) : ICompiler {
|
||||||
|
|
||||||
|
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||||
|
kobaltLog.log(project.name, 1,
|
||||||
|
" Groovy compiling " + Strings.pluralizeAll(info.sourceFiles.size, "file"))
|
||||||
|
|
||||||
|
val compilerAction = object: ICompilerAction {
|
||||||
|
override fun compile(project: Project?, info: CompilerActionInfo): TaskResult {
|
||||||
|
val groovyClasspath = info.dependencies.map { it.jarFile.get().absolutePath }
|
||||||
|
val compiler = org.codehaus.groovy.tools.Compiler(CompilerConfiguration().apply {
|
||||||
|
targetDirectory = info.outputDir
|
||||||
|
setClasspathList(groovyClasspath)
|
||||||
|
verbose = true
|
||||||
|
debug = true
|
||||||
|
})
|
||||||
|
// Will throw if there are any errors
|
||||||
|
compiler.compile(info.sourceFiles.map(::File).toTypedArray())
|
||||||
|
return TaskResult()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val flags = listOf<String>()
|
||||||
|
return jvmCompiler.doCompile(project, context, compilerAction, info, flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.beust.kobalt.plugin.groovy
|
||||||
|
|
||||||
|
import com.beust.kobalt.api.*
|
||||||
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
|
import com.beust.kobalt.internal.BaseJvmPlugin
|
||||||
|
import java.io.File
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class GroovyPlugin @Inject constructor(val groovyCompiler: GroovyCompiler,
|
||||||
|
override val configActor: ConfigActor<GroovyConfig>)
|
||||||
|
: BaseJvmPlugin<GroovyConfig>(configActor), ICompilerContributor, ISourceDirectoryContributor {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val PLUGIN_NAME = "Groovy"
|
||||||
|
val SOURCE_SUFFIXES = listOf("groovy")
|
||||||
|
}
|
||||||
|
|
||||||
|
override val name = PLUGIN_NAME
|
||||||
|
|
||||||
|
override fun sourceSuffixes() = SOURCE_SUFFIXES
|
||||||
|
|
||||||
|
// IDocContributor
|
||||||
|
override fun affinity(project: Project, context: KobaltContext) = sourceFileCount(project)
|
||||||
|
|
||||||
|
// ICompilerFlagsContributor
|
||||||
|
override fun compilerFlagsFor(project: Project, context: KobaltContext, currentFlags: List<String>,
|
||||||
|
suffixesBeingCompiled: List<String>) =
|
||||||
|
maybeCompilerArgs(compiler.sourceSuffixes, suffixesBeingCompiled,
|
||||||
|
configurationFor(project)?.compilerArgs ?: listOf<String>())
|
||||||
|
|
||||||
|
// ICompilerContributor
|
||||||
|
val compiler = CompilerDescription(PLUGIN_NAME, "groovy", SOURCE_SUFFIXES, groovyCompiler)
|
||||||
|
|
||||||
|
// ISourceDirectoryContributor
|
||||||
|
override fun sourceDirectoriesFor(project: Project, context: KobaltContext)
|
||||||
|
= listOf(File("src/main/groovy", "src/test/groovy"))
|
||||||
|
|
||||||
|
override fun compilersFor(project: Project, context: KobaltContext)
|
||||||
|
= if (sourceFileCount(project) > 0) listOf(compiler) else emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
class GroovyConfig(val project: Project) {
|
||||||
|
val compilerArgs = arrayListOf<String>()
|
||||||
|
fun args(vararg options: String) = compilerArgs.addAll(options)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
fun Project.groovyCompiler(init: GroovyConfig.() -> Unit) = let {
|
||||||
|
val config = GroovyConfig(it)
|
||||||
|
config.init()
|
||||||
|
(Kobalt.findPlugin(GroovyPlugin.PLUGIN_NAME) as GroovyPlugin).addConfiguration(this, config)
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
<name>kobalt</name>
|
<name>kobalt</name>
|
||||||
<factory-class-name>com.beust.kobalt.internal.GuiceFactory</factory-class-name>
|
<factory-class-name>com.beust.kobalt.internal.GuiceFactory</factory-class-name>
|
||||||
<plugin-actors>
|
<plugin-actors>
|
||||||
<!-- Classes within this tag are instantiated and the introspected by Kobalt. Whenever they -->
|
<!-- Classes within this tag are instantiated and then introspected by Kobalt. Whenever they -->
|
||||||
<!-- are found to implement one of IPluginActor's interfaces, they are added as such -->
|
<!-- are found to implement one of IPluginActor's interfaces, they are added as such -->
|
||||||
<class-name>com.beust.kobalt.plugin.java.JavaPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.java.JavaPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.plugin.application.ApplicationPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.application.ApplicationPlugin</class-name>
|
||||||
|
@ -12,6 +12,7 @@
|
||||||
<class-name>com.beust.kobalt.plugin.packaging.PackagingPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.packaging.PackagingPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.plugin.publish.PublishPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.publish.PublishPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.plugin.apt.AptPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.apt.AptPlugin</class-name>
|
||||||
|
<class-name>com.beust.kobalt.plugin.groovy.GroovyPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.internal.JvmCompilerPlugin</class-name>
|
<class-name>com.beust.kobalt.internal.JvmCompilerPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.internal.BuildListeners</class-name>
|
<class-name>com.beust.kobalt.internal.BuildListeners</class-name>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue