mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Retrolambda plug-in.
This commit is contained in:
parent
60206309ad
commit
bb130c128c
2 changed files with 73 additions and 0 deletions
|
@ -0,0 +1,72 @@
|
||||||
|
package com.beust.kobalt.plugin.retrolambda
|
||||||
|
|
||||||
|
import com.beust.kobalt.Plugins
|
||||||
|
import com.beust.kobalt.TaskResult
|
||||||
|
import com.beust.kobalt.api.ConfigPlugin
|
||||||
|
import com.beust.kobalt.api.IClasspathContributor
|
||||||
|
import com.beust.kobalt.api.Project
|
||||||
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
|
import com.beust.kobalt.api.annotation.Task
|
||||||
|
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||||
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
|
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||||
|
import com.beust.kobalt.misc.RunCommand
|
||||||
|
import com.google.inject.Inject
|
||||||
|
import com.google.inject.Singleton
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run Retrolambda on the classes right after "compile". This plug-in automatically downloads and uses
|
||||||
|
* the most recent retrolambda.jar and it can be configured with the `retrolambda{}` directive.
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
class RetrolambdaPlugin @Inject constructor(val dependencyManager: DependencyManager)
|
||||||
|
: ConfigPlugin<RetrolambdaConfig>(), IClasspathContributor {
|
||||||
|
|
||||||
|
override val name = PLUGIN_NAME
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val PLUGIN_NAME = "Retrolambda"
|
||||||
|
const val ID = "net.orfjackal.retrolambda:retrolambda:"
|
||||||
|
val JAR = MavenDependency.create(ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun entriesFor(project: Project?) = listOf(JAR)
|
||||||
|
|
||||||
|
@Task(name = "retrolambda", description = "Run Retrolambda",
|
||||||
|
alwaysRunAfter = arrayOf(JvmCompilerPlugin.TASK_COMPILE))
|
||||||
|
fun taskRetrolambda(project: Project): TaskResult {
|
||||||
|
val config = configurationFor(project)
|
||||||
|
val result = if (config != null) {
|
||||||
|
val classpath = dependencyManager.transitiveClosure(project.compileDependencies).map {
|
||||||
|
it.jarFile.get()
|
||||||
|
}.joinToString(File.separator)
|
||||||
|
|
||||||
|
val args = listOf(
|
||||||
|
"-Dretrolambda.inputDir=" + project.classesDir(context),
|
||||||
|
"-Dretrolambda.classpath=" + classpath,
|
||||||
|
"-Dretrolambda.bytecodeVersion=${config.byteCodeVersion}",
|
||||||
|
"-jar", JAR.jarFile.get().path)
|
||||||
|
|
||||||
|
val result = RunCommand("java").apply {
|
||||||
|
directory = File(project.directory)
|
||||||
|
}.run(args)
|
||||||
|
TaskResult(result == 0)
|
||||||
|
} else {
|
||||||
|
TaskResult()
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RetrolambdaConfig(var byteCodeVersion: Int = 50) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
fun Project.retrolambda(init: RetrolambdaConfig.() -> Unit) = let {
|
||||||
|
RetrolambdaConfig().apply {
|
||||||
|
init()
|
||||||
|
(Plugins.findPlugin(RetrolambdaPlugin.PLUGIN_NAME) as RetrolambdaPlugin).addConfiguration(it, this)
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.retrolambda.RetrolambdaPlugin</class-name>
|
||||||
|
|
||||||
<!-- These classes manage -init for Java and Kotlin -->
|
<!-- These classes manage -init for Java and Kotlin -->
|
||||||
<class-name>com.beust.kobalt.plugin.java.JavaBuildGenerator</class-name>
|
<class-name>com.beust.kobalt.plugin.java.JavaBuildGenerator</class-name>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue