From 4f32f0ba2f94c3c4d3a0a8ece3d531d599c95296 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 9 Mar 2017 15:10:18 -0800 Subject: [PATCH] Added parameters to autoGitTag directive. --- .../src/main/kotlin/com/beust/kobalt/misc/Git.kt | 13 +++++++------ .../beust/kobalt/plugin/publish/PublishPlugin.kt | 14 ++++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt index 518250a5..e8fec4fa 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Git.kt @@ -6,10 +6,10 @@ import com.google.inject.Inject import java.io.File class Git @Inject constructor() { - fun maybeTagRelease(project: Project, uploadResult: TaskResult, autoGitTag: Boolean) : TaskResult { + fun maybeTagRelease(project: Project, uploadResult: TaskResult, autoGitTag: Triple) : TaskResult { val result = - if (uploadResult.success && autoGitTag) { - val tagSuccess = tagRelease(project) + if (uploadResult.success && autoGitTag.first) { + val tagSuccess = tagRelease(project, autoGitTag) if (! tagSuccess) { TaskResult(false, "Couldn't tag the project") } else { @@ -21,16 +21,17 @@ class Git @Inject constructor() { return result } - private fun tagRelease(project: Project) : Boolean { + private fun tagRelease(project: Project, autoGitTag: Triple) : Boolean { val success = try { - log(2, "Tagging this release as \"${project.version}\"") + val version = if (autoGitTag.second.isNullOrBlank()) project.version else autoGitTag.second + log(2, "Tagging this release as \"$version\"") val repo = org.eclipse.jgit.storage.file.FileRepositoryBuilder() .setGitDir(File(KFiles.joinDir(project.directory, ".git"))) .readEnvironment() .findGitDir() .build() val git = org.eclipse.jgit.api.Git(repo) - val ref = git.tag().setName(project.version).call() + val ref = git.tag().setName(version).setMessage(autoGitTag.third).call() git.push().setPushTags().call() true } catch(ex: Exception) { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt index 56883401..78753ccc 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -191,13 +191,16 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener data class GithubConfig(val project: Project) { val files = arrayListOf() + var autoGitTag = Triple(true, project.version!!, "") /** * If true, automatically tag this release with the current version number and push that tag to origin when * the uploadGithub task is called. */ @Directive - var autoGitTag: Boolean = false + fun autoGitTag(auto: Boolean = autoGitTag.first, tag: String = project.version!!, message: String = autoGitTag.third) { + autoGitTag = Triple(auto, tag, message) + } @Directive fun file(filePath: String, url: String) { @@ -213,6 +216,9 @@ fun Project.github(init: GithubConfig.() -> Unit): GithubConfig = } data class BintrayConfig(val project: Project) { + val files = arrayListOf>() + var autoGitTag = Triple(true, project.version!!, "") + /** * If true, the uploaded file will be published in your personal space (e.g. https://dl.bintray.com/cbeust/maven). * Once the file is uploaded there, it can be automatically synchronized to JCenter by linking your project to @@ -233,9 +239,9 @@ data class BintrayConfig(val project: Project) { * the uploadBintray task is called. */ @Directive - var autoGitTag: Boolean = true - - val files = arrayListOf>() + fun autoGitTag(auto: Boolean = autoGitTag.first, tag: String = project.version!!, message: String = autoGitTag.third) { + autoGitTag = Triple(auto, tag, message) + } @Directive fun file(filePath: String, url: String) {