mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
More plug-ins under ConfigPlugin.
This commit is contained in:
parent
c8cdaeda27
commit
802325c16a
4 changed files with 21 additions and 42 deletions
|
@ -1,12 +1,12 @@
|
|||
package com.beust.kobalt.plugin.android
|
||||
|
||||
import com.beust.kobalt.OperatingSystem
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.homeDir
|
||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.maven.FileDependency
|
||||
import com.beust.kobalt.maven.IClasspathDependency
|
||||
import com.beust.kobalt.maven.MavenId
|
||||
|
@ -32,7 +32,7 @@ class AndroidConfig(var compileSdkVersion : String = "23",
|
|||
fun Project.android(init: AndroidConfig.() -> Unit) : AndroidConfig {
|
||||
val pd = AndroidConfig()
|
||||
pd.init()
|
||||
(Kobalt.findPlugin("android") as AndroidPlugin).setConfiguration(this, pd)
|
||||
(Kobalt.findPlugin("android") as AndroidPlugin).addConfiguration(this, pd)
|
||||
return pd
|
||||
}
|
||||
|
||||
|
@ -41,10 +41,10 @@ val Project.isAndroid : Boolean
|
|||
|
||||
@Singleton
|
||||
public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
||||
: BasePlugin(), IClasspathContributor, IRepoContributor {
|
||||
: ConfigPlugin<AndroidConfig>(), IClasspathContributor, IRepoContributor {
|
||||
override val name = "android"
|
||||
|
||||
fun isAndroid(project: Project) = configurations[project.name] != null
|
||||
fun isAndroid(project: Project) = configurationFor(project) != null
|
||||
|
||||
override fun apply(project: Project, context: KobaltContext) {
|
||||
super.apply(project, context)
|
||||
|
@ -58,19 +58,15 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
|||
(Kobalt.findPlugin("java") as JvmCompilerPlugin).addCompilerArgs("-target", "1.6", "-source", "1.6")
|
||||
}
|
||||
|
||||
val configurations = hashMapOf<String, AndroidConfig>()
|
||||
|
||||
fun setConfiguration(p: Project, config: AndroidConfig) {
|
||||
configurations.put(p.name, config)
|
||||
}
|
||||
|
||||
override fun accept(project: Project) = configurations.containsKey(project.name)
|
||||
override fun accept(project: Project) = isAndroid(project)
|
||||
|
||||
val flavor = "debug"
|
||||
|
||||
fun compileSdkVersion(project: Project) = configurations[project.name]?.compileSdkVersion
|
||||
fun compileSdkVersion(project: Project) = configurationFor(project)?.compileSdkVersion
|
||||
|
||||
fun buildToolsVersion(project: Project): String {
|
||||
val version = configurations[project.name]?.buildToolsVersion
|
||||
val version = configurationFor(project)?.buildToolsVersion
|
||||
if (OperatingSystem.current().isWindows() && version == "21.1.2")
|
||||
return "build-tools-$version"
|
||||
else
|
||||
|
@ -80,7 +76,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
|||
fun androidHomeNoThrows(project: Project?): String? {
|
||||
var result = System.getenv("ANDROID_HOME")
|
||||
if (project != null) {
|
||||
configurations[project.name]?.androidHome?.let {
|
||||
configurationFor(project)?.androidHome?.let {
|
||||
result = it
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +131,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
|||
private fun generateR(project: Project, generated: Path, aapt: String, resDir: String) {
|
||||
val compileSdkVersion = compileSdkVersion(project)
|
||||
val androidJar = Paths.get(androidHome(project), "platforms", "android-$compileSdkVersion", "android.jar")
|
||||
val applicationId = configurations[project.name]?.applicationId!!
|
||||
val applicationId = configurationFor(project)?.applicationId!!
|
||||
val manifestDir = Paths.get(project.directory, "app", "src", "main").toString()
|
||||
val manifest = Paths.get(manifestDir, "AndroidManifest.xml")
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.beust.kobalt.plugin.application
|
||||
|
||||
import com.beust.kobalt.*
|
||||
import com.beust.kobalt.api.BasePlugin
|
||||
import com.beust.kobalt.api.ConfigPlugin
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
import com.beust.kobalt.api.annotation.Task
|
||||
|
@ -26,13 +26,13 @@ class ApplicationConfig {
|
|||
fun Project.application(init: ApplicationConfig.() -> Unit) {
|
||||
ApplicationConfig().let { config ->
|
||||
config.init()
|
||||
(Plugins.findPlugin(ApplicationPlugin.NAME) as ApplicationPlugin).addConfig(this, config)
|
||||
(Plugins.findPlugin(ApplicationPlugin.NAME) as ApplicationPlugin).addConfiguration(this, config)
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors,
|
||||
val dependencyManager: DependencyManager) : BasePlugin() {
|
||||
val dependencyManager: DependencyManager) : ConfigPlugin<ApplicationConfig>() {
|
||||
|
||||
companion object {
|
||||
const val NAME = "application"
|
||||
|
@ -40,15 +40,9 @@ class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors,
|
|||
|
||||
override val name = NAME
|
||||
|
||||
val configs = hashMapOf<String, ApplicationConfig>()
|
||||
|
||||
fun addConfig(project: Project, config: ApplicationConfig) {
|
||||
configs.put(project.name, config)
|
||||
}
|
||||
|
||||
@Task(name = "run", description = "Run the main class", runAfter = arrayOf("assemble"))
|
||||
fun taskRun(project: Project): TaskResult {
|
||||
configs[project.name]?.let { config ->
|
||||
configurationFor(project)?.let { config ->
|
||||
val java = JavaInfo.create(File(SystemProperties.javaBase)).javaExecutable!!
|
||||
if (config.mainClass != null) {
|
||||
val jarName = project.projectProperties.get(PackagingPlugin.JAR_NAME) as String
|
||||
|
|
|
@ -18,7 +18,7 @@ import javax.inject.Singleton
|
|||
*/
|
||||
@Singleton
|
||||
public class AptPlugin @Inject constructor(val depFactory: DepFactory, val executors: KobaltExecutors)
|
||||
: BasePlugin(), ICompilerFlagContributor {
|
||||
: ConfigPlugin<AptConfig>(), ICompilerFlagContributor {
|
||||
companion object {
|
||||
const val TASK_APT: String = "runApt"
|
||||
const val NAME = "apt"
|
||||
|
@ -26,16 +26,10 @@ public class AptPlugin @Inject constructor(val depFactory: DepFactory, val execu
|
|||
|
||||
override val name = NAME
|
||||
|
||||
private val configs = hashMapOf<String, AptConfig>()
|
||||
|
||||
fun addAptConfig(project: Project, config: AptConfig) {
|
||||
configs.put(project.name, config)
|
||||
}
|
||||
|
||||
// ICompilerFlagContributor
|
||||
override fun flagsFor(project: Project) : List<String> {
|
||||
val result = arrayListOf<String>()
|
||||
configs[project.name]?.let { config ->
|
||||
configurationFor(project)?.let { config ->
|
||||
aptDependencies.get(key = project.name)?.let { aptDependency ->
|
||||
val dependencyJarFile = JarFinder.byId(aptDependency)
|
||||
result.add("-processorpath")
|
||||
|
@ -61,7 +55,7 @@ class AptConfig(var outputDir: String = "generated/sources/apt")
|
|||
public fun Project.apt(init: AptConfig.() -> Unit) {
|
||||
AptConfig().let {
|
||||
it.init()
|
||||
(Kobalt.findPlugin(AptPlugin.NAME) as AptPlugin).addAptConfig(this, it)
|
||||
(Kobalt.findPlugin(AptPlugin.NAME) as AptPlugin).addConfiguration(this, it)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.beust.kobalt.IFileSpec
|
|||
import com.beust.kobalt.IFileSpec.FileSpec
|
||||
import com.beust.kobalt.IFileSpec.Glob
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.api.BasePlugin
|
||||
import com.beust.kobalt.api.ConfigPlugin
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
import com.beust.kobalt.api.Project
|
||||
|
@ -34,7 +34,7 @@ import javax.inject.Singleton
|
|||
|
||||
@Singleton
|
||||
class PackagingPlugin @Inject constructor(val dependencyManager : DependencyManager,
|
||||
val executors: KobaltExecutors, val localRepo: LocalRepo) : BasePlugin() {
|
||||
val executors: KobaltExecutors, val localRepo: LocalRepo) : ConfigPlugin<InstallConfig>() {
|
||||
|
||||
companion object {
|
||||
const val PLUGIN_NAME = "packaging"
|
||||
|
@ -252,7 +252,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
@Task(name = PackagingPlugin.TASK_INSTALL, description = "Install the artifacts",
|
||||
runAfter = arrayOf(PackagingPlugin.TASK_ASSEMBLE))
|
||||
fun taskInstall(project: Project) : TaskResult {
|
||||
val config = installConfigs[project.name]
|
||||
val config = configurationFor(project)
|
||||
if (config != null) {
|
||||
val buildDir = project.projectProperties.getString(LIBS_DIR)
|
||||
log(1, "Installing from $buildDir to ${config.libDir}")
|
||||
|
@ -265,18 +265,13 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
|
||||
return TaskResult()
|
||||
}
|
||||
|
||||
private val installConfigs = hashMapOf<String, InstallConfig>()
|
||||
|
||||
fun addInstallConfig(project: Project, config: InstallConfig) =
|
||||
installConfigs.put(project.name, config)
|
||||
}
|
||||
|
||||
@Directive
|
||||
fun Project.install(init: InstallConfig.() -> Unit) {
|
||||
InstallConfig().let {
|
||||
it.init()
|
||||
(Kobalt.findPlugin(PackagingPlugin.PLUGIN_NAME) as PackagingPlugin).addInstallConfig(this, it)
|
||||
(Kobalt.findPlugin(PackagingPlugin.PLUGIN_NAME) as PackagingPlugin).addConfiguration(this, it)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue