1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

ApplicationPlugin work.

This commit is contained in:
Cedric Beust 2015-11-06 20:07:00 -08:00
parent 7b7f279d68
commit 146905da40
8 changed files with 46 additions and 18 deletions

View file

@ -12,6 +12,12 @@ abstract public class BasePlugin : Plugin {
override fun accept(project: Project) = true
var plugins: Plugins by Delegates.notNull()
var context: KobaltContext by Delegates.notNull()
override fun apply(project: Project, context: KobaltContext) {
this.context = context
}
protected val projects = arrayListOf<ProjectDescription>()
fun addProject(project: Project, dependsOn: Array<out Project>) {

View file

@ -8,7 +8,7 @@ import com.beust.kobalt.misc.KFiles
import java.util.*
open public class Project(
@Directive open var name: String? = null,
@Directive open var name: String,
@Directive open var version: String? = null,
@Directive open var directory: String = ".",
@Directive open var buildDirectory: String? = KFiles.KOBALT_BUILD_DIR,
@ -30,7 +30,7 @@ open public class Project(
}
override fun hashCode(): Int {
return name!!.hashCode()
return name.hashCode()
}
//
@ -91,7 +91,7 @@ open public class Project(
/** Used to disambiguate various name properties */
@Directive
val projectName: String get() = name!!
val projectName: String get() = name
}
public class Sources(val project: Project, val sources: ArrayList<String>) {

View file

@ -43,12 +43,8 @@ abstract class JvmCompilerPlugin @Inject constructor(
log(2, "${project.name}: $s")
}
var context: KobaltContext? = null
override fun apply(project: Project, context: KobaltContext) {
super.apply(project, context)
this.context = context
context.pluginProperties.put(name, BUILD_DIR, project.buildDirectory + File.separator + "classes")
}

View file

@ -40,11 +40,9 @@ fun Project.android(init: AndroidConfig.() -> Unit) : AndroidConfig {
public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler) : BasePlugin(), IClasspathContributor {
override val name = "android"
lateinit var context: KobaltContext
override fun apply(project: Project, context: KobaltContext) {
super.apply(project, context)
log(1, "Applying plug-in Android on project $project")
this.context = context
if (accept(project)) {
project.compileDependencies.add(FileDependency(androidJar(project).toString()))
}

View file

@ -1,14 +1,20 @@
package com.beust.kobalt.plugin.application
import com.beust.kobalt.JavaInfo
import com.beust.kobalt.Plugins
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.api.BasePlugin
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.internal.TaskResult
import com.beust.kobalt.maven.KobaltException
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.RunCommand
import com.beust.kobalt.plugin.packaging.PackagingPlugin
import com.google.inject.Inject
import com.google.inject.Singleton
import java.io.File
@Directive
class ApplicationConfig {
@ -27,8 +33,7 @@ fun Project.application(init: ApplicationConfig.() -> Unit) {
}
@Singleton
class ApplicationPlugin @Inject constructor(val dependencyManager : DependencyManager,
val executors: KobaltExecutors, val localRepo: LocalRepo) : BasePlugin() {
class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors) : BasePlugin() {
companion object {
const val NAME = "application"
@ -36,8 +41,25 @@ class ApplicationPlugin @Inject constructor(val dependencyManager : DependencyMa
override val name = NAME
val configs = hashMapOf<String, ApplicationConfig>()
fun addConfig(project: Project, config: ApplicationConfig) {
println("Adding config $config")
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 ->
val java = JavaInfo.create(File(SystemProperties.javaBase)).javaExecutable!!
if (config != null && config.mainClass != null) {
val jarName = context.pluginProperties.get("packaging", PackagingPlugin.JAR_NAME) as String
val args = listOf("-classpath", jarName) + config.jvmArgs + config.mainClass!!
RunCommand(java.absolutePath).run(args)
} else {
throw KobaltException("No \"mainClass\" specified in the application{} part of project ${project.name}")
}
}
return TaskResult()
}
}

View file

@ -7,7 +7,7 @@ import com.beust.kobalt.misc.toString
public class JavaProject(
@Directive
override var name: String? = null,
override var name: String = "",
@Directive
override var version: String? = null,
/** The absolute directory location of this project */

View file

@ -7,7 +7,7 @@ import com.beust.kobalt.misc.toString
public class KotlinProject(
@Directive
override var name: String? = null,
override var name: String = "",
@Directive
override var version: String? = null,
/** The absolute directory location of this project */
@ -27,5 +27,5 @@ public class KotlinProject(
: Project(name, version, directory, buildDirectory, group, artifactId, packaging, dependencies, ".kt",
projectInfo = KotlinProjectInfo()) {
override public fun toString() = toString("KotlinProject", "name", name!!)
override public fun toString() = toString("KotlinProject", "name", name)
}

View file

@ -44,6 +44,9 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
@ExportedProperty
const val LIBS_DIR = "libsDir"
@ExportedProperty
const val JAR_NAME = "jarName"
const val TASK_ASSEMBLE : String = "assemble"
}
@ -231,6 +234,9 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
outStream.flush()
outStream.close()
log(1, " Created $result")
context.pluginProperties.put(name, JAR_NAME, result.absolutePath)
return result
}