mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Better look up of the compiler jar file.
This commit is contained in:
parent
a83e1f4a7d
commit
82b5c636d0
3 changed files with 32 additions and 5 deletions
|
@ -0,0 +1,21 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* The jar files that Kotlin needs to run.
|
||||
*/
|
||||
class KotlinJarFiles @Inject constructor(val dependencyManager: DependencyManager,
|
||||
val settings: KobaltSettings){
|
||||
private fun getKotlinCompilerJar(name: String): File {
|
||||
val id = "org.jetbrains.kotlin:kotlin-$name:${settings.kobaltCompilerVersion}"
|
||||
val dep = dependencyManager.create(id)
|
||||
return dep.jarFile.get().absoluteFile
|
||||
}
|
||||
|
||||
val stdlib: File get() = getKotlinCompilerJar("stdlib")
|
||||
val runtime: File get() = getKotlinCompilerJar("runtime")
|
||||
val compiler: File get() = getKotlinCompilerJar("compiler-embeddable")
|
||||
}
|
|
@ -5,6 +5,7 @@ import com.beust.kobalt.api.*
|
|||
import com.beust.kobalt.internal.ICompilerAction
|
||||
import com.beust.kobalt.internal.JvmCompiler
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.KotlinJarFiles
|
||||
import com.beust.kobalt.kotlin.ParentLastClassLoader
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.maven.dependency.FileDependency
|
||||
|
@ -34,7 +35,8 @@ class KotlinCompiler @Inject constructor(
|
|||
val dependencyManager: DependencyManager,
|
||||
val executors: KobaltExecutors,
|
||||
val settings: KobaltSettings,
|
||||
val jvmCompiler: JvmCompiler) {
|
||||
val jvmCompiler: JvmCompiler,
|
||||
val kotlinJarFiles: KotlinJarFiles) {
|
||||
|
||||
val compilerAction = object: ICompilerAction {
|
||||
override fun compile(projectName: String?, info: CompilerActionInfo): TaskResult {
|
||||
|
@ -88,7 +90,9 @@ class KotlinCompiler @Inject constructor(
|
|||
log(2, "Calling kotlinc " + allArgs.joinToString(" "))
|
||||
val result : TaskResult =
|
||||
if (true) {
|
||||
val classLoader = ParentLastClassLoader(cp.map { it.toURI().toURL() })
|
||||
val compilerJar = listOf(kotlinJarFiles.compiler.toURI().toURL())
|
||||
|
||||
val classLoader = ParentLastClassLoader(compilerJar)
|
||||
val compiler = classLoader.loadClass("org.jetbrains.kotlin.cli.common.CLICompiler")
|
||||
val compilerMain = compiler.declaredMethods.filter {
|
||||
it.name == "doMainNoExit" && it.parameterTypes.size == 2
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.beust.kobalt.api.annotation.Directive
|
|||
import com.beust.kobalt.internal.BaseJvmPlugin
|
||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.KotlinJarFiles
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.maven.dependency.FileDependency
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
|
@ -19,7 +20,8 @@ import javax.inject.Singleton
|
|||
|
||||
@Singleton
|
||||
class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val dependencyManager: DependencyManager,
|
||||
val settings: KobaltSettings, override val configActor: ConfigActor<KotlinConfig>)
|
||||
val settings: KobaltSettings, override val configActor: ConfigActor<KotlinConfig>,
|
||||
val kotlinJarFiles: KotlinJarFiles)
|
||||
: BaseJvmPlugin<KotlinConfig>(configActor), IDocContributor, IClasspathContributor, ICompilerContributor, IBuildConfigContributor {
|
||||
|
||||
companion object {
|
||||
|
@ -105,8 +107,8 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depen
|
|||
override fun classpathEntriesFor(project: Project?, context: KobaltContext): List<IClasspathDependency> =
|
||||
if (project == null || accept(project)) {
|
||||
// All Kotlin projects automatically get the Kotlin runtime added to their class path
|
||||
listOf(getKotlinCompilerJar("kotlin-stdlib"), getKotlinCompilerJar("kotlin-runtime"))
|
||||
.map { FileDependency(it) }
|
||||
listOf(kotlinJarFiles.stdlib, kotlinJarFiles.runtime)
|
||||
.map { FileDependency(it.absolutePath) }
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue