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

Property changes.

This commit is contained in:
Cedric Beust 2015-11-15 09:48:48 -08:00
parent 9050a6bb27
commit bebd088195
6 changed files with 40 additions and 16 deletions

View file

@ -25,6 +25,8 @@ open public class Project(
var testArgs: ArrayList<String> = arrayListOf() var testArgs: ArrayList<String> = arrayListOf()
val projectProperties = ProjectProperties()
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
return name == (other as Project).name return name == (other as Project).name
} }

View file

@ -0,0 +1,16 @@
package com.beust.kobalt.api
/**
* Plugins can add and read properties from the project by using this class, found on the Project class.
* Keys stored in this map by plug-ins should be annotated with @ExportedProjectProperty.
*/
class ProjectProperties {
private val properties = hashMapOf<String, Any>()
fun put(key: String, value: Any) = properties.put(key, value)
fun get(key: String) = properties[key]
fun getString(key: String) = get(key) as String
}

View file

@ -21,7 +21,14 @@ annotation class Task(val name: String,
) )
/** /**
* Plugins that export properties should annotated those with this annotation so they can be documented. * Plugins that export properties should annotate those with this annotation so they can be documented.
*/ */
@Retention(AnnotationRetention.RUNTIME) @Retention(AnnotationRetention.RUNTIME)
annotation class ExportedProperty annotation class ExportedPluginProperty
/**
* Plugins that export properties on the Project instance should annotate those with this annotation so
* they can be documented.
*/
@Retention(AnnotationRetention.RUNTIME)
annotation class ExportedProjectProperty

View file

@ -4,7 +4,7 @@ import com.beust.kobalt.TaskResult
import com.beust.kobalt.api.BasePlugin import com.beust.kobalt.api.BasePlugin
import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.ExportedProperty import com.beust.kobalt.api.annotation.ExportedProjectProperty
import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.maven.* import com.beust.kobalt.maven.*
import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KFiles
@ -26,7 +26,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
open val jvmCompiler: JvmCompiler) : BasePlugin() { open val jvmCompiler: JvmCompiler) : BasePlugin() {
companion object { companion object {
@ExportedProperty @ExportedProjectProperty
const val BUILD_DIR = "buildDir" const val BUILD_DIR = "buildDir"
const val TASK_CLEAN = "clean" const val TASK_CLEAN = "clean"
@ -46,7 +46,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
override fun apply(project: Project, context: KobaltContext) { override fun apply(project: Project, context: KobaltContext) {
super.apply(project, context) super.apply(project, context)
context.pluginProperties.put(name, BUILD_DIR, project.buildDirectory + File.separator + "classes") project.projectProperties.put(BUILD_DIR, project.buildDirectory + File.separator + "classes")
} }
/** /**

View file

@ -51,9 +51,8 @@ class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors,
configs[project.name]?.let { config -> configs[project.name]?.let { config ->
val java = JavaInfo.create(File(SystemProperties.javaBase)).javaExecutable!! val java = JavaInfo.create(File(SystemProperties.javaBase)).javaExecutable!!
if (config.mainClass != null) { if (config.mainClass != null) {
val jarName = context.pluginProperties.get("packaging", PackagingPlugin.JAR_NAME) as String val jarName = project.projectProperties.get(PackagingPlugin.JAR_NAME) as String
val packages = context.pluginProperties.get("packaging", PackagingPlugin.PACKAGES) val packages = project.projectProperties.get(PackagingPlugin.PACKAGES) as List<PackageConfig>
as List<PackageConfig>
val allDeps = arrayListOf(jarName) val allDeps = arrayListOf(jarName)
if (! isFatJar(packages, jarName)) { if (! isFatJar(packages, jarName)) {
// If the jar file is not fat, we need to add the transitive closure of all dependencies // If the jar file is not fat, we need to add the transitive closure of all dependencies

View file

@ -9,7 +9,7 @@ import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.ExportedProperty import com.beust.kobalt.api.annotation.ExportedProjectProperty
import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.glob import com.beust.kobalt.glob
import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.JvmCompilerPlugin
@ -39,13 +39,13 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
companion object { companion object {
const val PLUGIN_NAME = "packaging" const val PLUGIN_NAME = "packaging"
@ExportedProperty @ExportedProjectProperty
const val LIBS_DIR = "libsDir" const val LIBS_DIR = "libsDir"
@ExportedProperty @ExportedProjectProperty
const val JAR_NAME = "jarName" const val JAR_NAME = "jarName"
@ExportedProperty @ExportedProjectProperty
const val PACKAGES = "packages" const val PACKAGES = "packages"
const val TASK_ASSEMBLE: String = "assemble" const val TASK_ASSEMBLE: String = "assemble"
@ -58,14 +58,14 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
override fun apply(project: Project, context: KobaltContext) { override fun apply(project: Project, context: KobaltContext) {
super.apply(project, context) super.apply(project, context)
context.pluginProperties.put(name, LIBS_DIR, libsDir(project)) project.projectProperties.put(LIBS_DIR, libsDir(project))
} }
private fun libsDir(project: Project) = KFiles.makeDir(buildDir(project).path, "libs").path private fun libsDir(project: Project) = KFiles.makeDir(buildDir(project).path, "libs").path
@Task(name = TASK_ASSEMBLE, description = "Package the artifacts", runAfter = arrayOf(JavaPlugin.TASK_COMPILE)) @Task(name = TASK_ASSEMBLE, description = "Package the artifacts", runAfter = arrayOf(JavaPlugin.TASK_COMPILE))
fun taskAssemble(project: Project) : TaskResult { fun taskAssemble(project: Project) : TaskResult {
context.pluginProperties.put(PLUGIN_NAME, PACKAGES, packages) project.projectProperties.put(PACKAGES, packages)
packages.filter { it.project.name == project.name }.forEach { pkg -> packages.filter { it.project.name == project.name }.forEach { pkg ->
pkg.jars.forEach { generateJar(pkg.project, it) } pkg.jars.forEach { generateJar(pkg.project, it) }
pkg.wars.forEach { generateWar(pkg.project, it) } pkg.wars.forEach { generateWar(pkg.project, it) }
@ -238,7 +238,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
outStream.close() outStream.close()
log(1, " Created $result") log(1, " Created $result")
context.pluginProperties.put(name, JAR_NAME, result.absolutePath) project.projectProperties.put(JAR_NAME, result.absolutePath)
return result return result
} }
@ -253,7 +253,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
fun taskInstall(project: Project) : TaskResult { fun taskInstall(project: Project) : TaskResult {
val config = installConfigs[project.name] val config = installConfigs[project.name]
if (config != null) { if (config != null) {
val buildDir = context.pluginProperties.getString(PLUGIN_NAME, LIBS_DIR) val buildDir = project.projectProperties.getString(LIBS_DIR)
log(1, "Installing from $buildDir to ${config.libDir}") log(1, "Installing from $buildDir to ${config.libDir}")
val toDir = KFiles.makeDir(config.libDir) val toDir = KFiles.makeDir(config.libDir)