mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Property changes.
This commit is contained in:
parent
9050a6bb27
commit
bebd088195
6 changed files with 40 additions and 16 deletions
|
@ -25,6 +25,8 @@ open public class Project(
|
|||
|
||||
var testArgs: ArrayList<String> = arrayListOf()
|
||||
|
||||
val projectProperties = ProjectProperties()
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return name == (other as Project).name
|
||||
}
|
||||
|
|
16
src/main/kotlin/com/beust/kobalt/api/ProjectProperties.kt
Normal file
16
src/main/kotlin/com/beust/kobalt/api/ProjectProperties.kt
Normal 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
|
||||
}
|
||||
|
|
@ -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)
|
||||
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
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.beust.kobalt.TaskResult
|
|||
import com.beust.kobalt.api.BasePlugin
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
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.maven.*
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
|
@ -26,7 +26,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
open val jvmCompiler: JvmCompiler) : BasePlugin() {
|
||||
|
||||
companion object {
|
||||
@ExportedProperty
|
||||
@ExportedProjectProperty
|
||||
const val BUILD_DIR = "buildDir"
|
||||
|
||||
const val TASK_CLEAN = "clean"
|
||||
|
@ -46,7 +46,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
|
||||
override fun apply(project: Project, context: KobaltContext) {
|
||||
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")
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,9 +51,8 @@ class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors,
|
|||
configs[project.name]?.let { config ->
|
||||
val java = JavaInfo.create(File(SystemProperties.javaBase)).javaExecutable!!
|
||||
if (config.mainClass != null) {
|
||||
val jarName = context.pluginProperties.get("packaging", PackagingPlugin.JAR_NAME) as String
|
||||
val packages = context.pluginProperties.get("packaging", PackagingPlugin.PACKAGES)
|
||||
as List<PackageConfig>
|
||||
val jarName = project.projectProperties.get(PackagingPlugin.JAR_NAME) as String
|
||||
val packages = project.projectProperties.get(PackagingPlugin.PACKAGES) as List<PackageConfig>
|
||||
val allDeps = arrayListOf(jarName)
|
||||
if (! isFatJar(packages, jarName)) {
|
||||
// If the jar file is not fat, we need to add the transitive closure of all dependencies
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.beust.kobalt.api.Kobalt
|
|||
import com.beust.kobalt.api.KobaltContext
|
||||
import com.beust.kobalt.api.Project
|
||||
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.glob
|
||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||
|
@ -39,13 +39,13 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
companion object {
|
||||
const val PLUGIN_NAME = "packaging"
|
||||
|
||||
@ExportedProperty
|
||||
@ExportedProjectProperty
|
||||
const val LIBS_DIR = "libsDir"
|
||||
|
||||
@ExportedProperty
|
||||
@ExportedProjectProperty
|
||||
const val JAR_NAME = "jarName"
|
||||
|
||||
@ExportedProperty
|
||||
@ExportedProjectProperty
|
||||
const val PACKAGES = "packages"
|
||||
|
||||
const val TASK_ASSEMBLE: String = "assemble"
|
||||
|
@ -58,14 +58,14 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
|
||||
override fun apply(project: Project, context: KobaltContext) {
|
||||
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
|
||||
|
||||
@Task(name = TASK_ASSEMBLE, description = "Package the artifacts", runAfter = arrayOf(JavaPlugin.TASK_COMPILE))
|
||||
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 ->
|
||||
pkg.jars.forEach { generateJar(pkg.project, it) }
|
||||
pkg.wars.forEach { generateWar(pkg.project, it) }
|
||||
|
@ -238,7 +238,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
outStream.close()
|
||||
log(1, " Created $result")
|
||||
|
||||
context.pluginProperties.put(name, JAR_NAME, result.absolutePath)
|
||||
project.projectProperties.put(JAR_NAME, result.absolutePath)
|
||||
|
||||
return result
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
fun taskInstall(project: Project) : TaskResult {
|
||||
val config = installConfigs[project.name]
|
||||
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}")
|
||||
|
||||
val toDir = KFiles.makeDir(config.libDir)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue