mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Move Kotlin compiler outside of plugin.
This commit is contained in:
parent
259d4a3cba
commit
3592243bd8
6 changed files with 29 additions and 46 deletions
|
@ -3,8 +3,6 @@ package com.beust.kobalt
|
|||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.plugin.android.AndroidConfig
|
||||
import com.beust.kobalt.plugin.android.AndroidPlugin
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
|
@ -123,18 +121,6 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
return result
|
||||
}
|
||||
|
||||
fun applicationId(androidConfig: AndroidConfig?): String? {
|
||||
val mainId = productFlavor.applicationId ?: androidConfig?.applicationId
|
||||
val result =
|
||||
if (mainId != null) {
|
||||
mainId + (buildType.applicationIdSuffix ?: "")
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate BuildConfig.java if requested. Also look up if any BuildConfig is defined on the current build type,
|
||||
* product flavor or main project, and use them to generate any additional field (in that order to
|
||||
|
@ -144,8 +130,6 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
val buildConfigs = findBuildConfigs(project, this)
|
||||
|
||||
if (buildConfigs.size > 0) {
|
||||
val androidConfig = (Kobalt.findPlugin(AndroidPlugin.PLUGIN_NAME) as AndroidPlugin)
|
||||
.configurationFor(project)
|
||||
val pkg = project.packageName ?: project.group
|
||||
?: throw KobaltException(
|
||||
"packageName needs to be defined on the project in order to generate BuildConfig")
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
import com.beust.kobalt.Plugins
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
import com.beust.kobalt.internal.IProjectInfo
|
||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.plugin.android.AndroidPlugin
|
||||
import com.beust.kobalt.plugin.android.Proguard
|
||||
import java.util.*
|
||||
|
||||
open class Project(
|
||||
|
@ -196,10 +193,10 @@ class BuildTypeConfig(val project: Project?, val name: String) : IBuildConfig {
|
|||
var applicationIdSuffix: String? = null
|
||||
var proguardFile: String? = null
|
||||
|
||||
fun getDefaultProguardFile(name: String) : String {
|
||||
val androidPlugin = Plugins.findPlugin(AndroidPlugin.PLUGIN_NAME) as AndroidPlugin
|
||||
return Proguard(androidPlugin.androidHome(project)).getDefaultProguardFile(name)
|
||||
}
|
||||
// fun getDefaultProguardFile(name: String) : String {
|
||||
// val androidPlugin = Plugins.findPlugin(AndroidPlugin.PLUGIN_NAME) as AndroidPlugin
|
||||
// return Proguard(androidPlugin.androidHome(project)).getDefaultProguardFile(name)
|
||||
// }
|
||||
|
||||
override var buildConfig : BuildConfig? = BuildConfig()
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ import com.beust.kobalt.api.KobaltContext
|
|||
import com.beust.kobalt.api.PluginProperties
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.kotlin.kotlinCompilePrivate
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate
|
||||
import com.google.inject.assistedinject.Assisted
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.beust.kobalt.maven.DependencyManager
|
|||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.countChar
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate
|
||||
import com.beust.kobalt.kotlin.kotlinCompilePrivate
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
import java.nio.charset.Charset
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package com.beust.kobalt.plugin.kotlin;
|
||||
package com.beust.kobalt.kotlin
|
||||
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.app.ParentLastClassLoader
|
||||
import com.beust.kobalt.internal.ICompilerAction
|
||||
import com.beust.kobalt.internal.JvmCompiler
|
||||
import com.beust.kobalt.maven.DepFactory
|
||||
|
@ -11,7 +12,6 @@ import com.beust.kobalt.maven.dependency.FileDependency
|
|||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.app.ParentLastClassLoader
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
|
@ -74,21 +74,21 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo,
|
|||
private fun invokeCompiler(cp: List<File>, allArgs: Array<String>): Boolean {
|
||||
log(2, "Calling kotlinc " + allArgs.joinToString(" "))
|
||||
val result : Boolean =
|
||||
if (true) {
|
||||
val classLoader = ParentLastClassLoader(cp.map { it.toURI().toURL() })
|
||||
val compiler = classLoader.loadClass("org.jetbrains.kotlin.cli.common.CLICompiler")
|
||||
val compilerMain = compiler.declaredMethods.filter {
|
||||
it.name == "doMainNoExit" && it.parameterTypes.size == 2
|
||||
}.get(0)
|
||||
val kCompiler = classLoader.loadClass("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler")
|
||||
val compilerInstance = kCompiler.newInstance()
|
||||
val exitCode = compilerMain.invoke(null, compilerInstance, allArgs)
|
||||
val nameMethod = exitCode.javaClass.getMethod("name")
|
||||
"OK" == nameMethod.invoke(exitCode).toString()
|
||||
} else {
|
||||
val exitCode = CLICompiler.doMainNoExit(K2JVMCompiler(), allArgs)
|
||||
exitCode == ExitCode.OK
|
||||
}
|
||||
if (true) {
|
||||
val classLoader = ParentLastClassLoader(cp.map { it.toURI().toURL() })
|
||||
val compiler = classLoader.loadClass("org.jetbrains.kotlin.cli.common.CLICompiler")
|
||||
val compilerMain = compiler.declaredMethods.filter {
|
||||
it.name == "doMainNoExit" && it.parameterTypes.size == 2
|
||||
}.get(0)
|
||||
val kCompiler = classLoader.loadClass("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler")
|
||||
val compilerInstance = kCompiler.newInstance()
|
||||
val exitCode = compilerMain.invoke(null, compilerInstance, allArgs)
|
||||
val nameMethod = exitCode.javaClass.getMethod("name")
|
||||
"OK" == nameMethod.invoke(exitCode).toString()
|
||||
} else {
|
||||
val exitCode = CLICompiler.doMainNoExit(K2JVMCompiler(), allArgs)
|
||||
exitCode == ExitCode.OK
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -122,10 +122,10 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo,
|
|||
|
||||
executor.shutdown()
|
||||
|
||||
// val classpathList = arrayListOf(
|
||||
// getKotlinCompilerJar("kotlin-stdlib"),
|
||||
// getKotlinCompilerJar("kotlin-compiler-embeddable"))
|
||||
// .map { FileDependency(it) }
|
||||
// val classpathList = arrayListOf(
|
||||
// getKotlinCompilerJar("kotlin-stdlib"),
|
||||
// getKotlinCompilerJar("kotlin-compiler-embeddable"))
|
||||
// .map { FileDependency(it) }
|
||||
|
||||
val dependencies = compileDependencies + otherClasspath.map { FileDependency(it) }
|
||||
val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, outputDir, args)
|
|
@ -6,6 +6,8 @@ import com.beust.kobalt.api.annotation.Directive
|
|||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.internal.JvmCompiler
|
||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||
import com.beust.kobalt.kotlin.KotlinCompiler
|
||||
import com.beust.kobalt.kotlin.kotlinCompilePrivate
|
||||
import com.beust.kobalt.maven.DepFactory
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue