diff --git a/src/main/kotlin/com/beust/kobalt/api/Project.kt b/src/main/kotlin/com/beust/kobalt/api/Project.kt index e49f047d..7630d815 100644 --- a/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -25,6 +25,8 @@ open public class Project( var testArgs: ArrayList = arrayListOf() + val projectProperties = ProjectProperties() + override fun equals(other: Any?): Boolean { return name == (other as Project).name } diff --git a/src/main/kotlin/com/beust/kobalt/api/ProjectProperties.kt b/src/main/kotlin/com/beust/kobalt/api/ProjectProperties.kt new file mode 100644 index 00000000..88f263b3 --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/api/ProjectProperties.kt @@ -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() + + fun put(key: String, value: Any) = properties.put(key, value) + + fun get(key: String) = properties[key] + + fun getString(key: String) = get(key) as String +} + diff --git a/src/main/kotlin/com/beust/kobalt/api/annotation/Annotations.kt b/src/main/kotlin/com/beust/kobalt/api/annotation/Annotations.kt index 7ca7edc4..dfc853f8 100644 --- a/src/main/kotlin/com/beust/kobalt/api/annotation/Annotations.kt +++ b/src/main/kotlin/com/beust/kobalt/api/annotation/Annotations.kt @@ -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 \ No newline at end of file +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 diff --git a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index 40accc71..06bba05b 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -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") } /** diff --git a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt index 746f6376..58f8e0ca 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt @@ -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 + val jarName = project.projectProperties.get(PackagingPlugin.JAR_NAME) as String + val packages = project.projectProperties.get(PackagingPlugin.PACKAGES) as List 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 diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt index e1e76086..1e79bf76 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -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)