From 71b7c6d58c1f8ba7a4533308cd828d9ca7511a34 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 09:23:50 -0700 Subject: [PATCH 01/10] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c7d9c3b7..81d87855 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Kobalt - +[](https://teamcity.jetbrains.com/project.html?projectId=OpenSourceProjects_Kobalt&tab=projectOverview) + Kobalt is a universal build system. From 3f1155a280bd2d71a602fdbcf53c4ada8bdfa4f6 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 10:01:49 -0700 Subject: [PATCH 02/10] Better warning. --- .../main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt index 7882cfd0..fa48427e 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt @@ -58,10 +58,12 @@ class CompilerDescription(override val name: String, override val sourceDirecto if (info.sourceFiles.isNotEmpty()) { compiler.compile(project, context, info) } else { - warn("Couldn't find any source files to compile") + warn("$name cdouldn't find any source files to compile") TaskResult() } return result } + + override fun toString() = name + " compiler" } From 66b39aa21357b596aa890127345c3df4023e6df7 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 14:20:30 -0700 Subject: [PATCH 03/10] Log exclusions. --- .../kotlin/com/beust/kobalt/maven/DependencyManager.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index 6913c8ed..9ff45407 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -139,8 +139,14 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, * Should probably make exclusion more generic (full on string) or allow exclusion to be specified * formally by groupId or artifactId. */ - fun isDependencyExcluded(dep: IClasspathDependency, excluded: List) - = excluded.any { excluded -> dep.id.startsWith(excluded.id) } + fun isDependencyExcluded(dep: IClasspathDependency, excluded: List): Boolean { + excluded.any { excluded -> dep.id.startsWith(excluded.id) }.let { result -> + if (result) { + context.logger.log(project?.name ?: "", 2, " Excluding dependency $dep") + } + return result + } + } // Dependencies get reordered by transitiveClosure() but since we just added a bunch of new ones, // we need to reorder them again in case we're adding dependencies that are already present From c2c4d8e254d0b951a101e7cdb1eaa86c5c66bd48 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 14:44:12 -0700 Subject: [PATCH 04/10] Clarify and document. --- .../plugin/packaging/PackagingPlugin.kt | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) 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 ea541efa..2e81d778 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -62,21 +62,28 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana runTask = { taskInstall(project) }) } - val zipToFiles = hashMapOf>() - override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo { val allConfigs = packages.filter { it.project.name == project.name } + val zipToFiles = hashMapOf>() val benchmark = benchmarkMillis { if (true) { + // + // This loop prepares the data so we can calculate input and output checksums for the + // assemble task: + // - Input: Calculate the list of all the included files for every archive (jar/war/zip) and + // store them in the `zipToFiles` map. + // - Output: Calculate all the output archive files into `allFiles` + // + // `zipToFiles` is used again so we can pass that list of included files to the actual execution + // of the task, so we don't have to look for them a second time + // val allIncludedFiles = arrayListOf() val outputArchives = arrayListOf() allConfigs.forEach { packageConfig -> listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives -> archives.forEach { val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it) - val suffixIndex = it.name.lastIndexOf(".") - val suffix = it.name.substring(suffixIndex) val outputFile = jarGenerator.fullArchiveName(project, context, it.name) outputArchives.add(outputFile) allIncludedFiles.addAll(files) @@ -84,7 +91,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } } } - val allFiles = allIncludedFiles.fold(arrayListOf()) { files, includedFile: IncludedFile -> + val inputFiles = allIncludedFiles.fold(arrayListOf()) { files, includedFile: IncludedFile -> val foundFiles = includedFile.allFromFiles(project.directory) val absFiles = foundFiles.map { File(KFiles.joinDir(project.directory, includedFile.from, it.path)) @@ -93,7 +100,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana files } - val inMd5 = Md5.toMd5Directories(allFiles) + val inMd5 = Md5.toMd5Directories(inputFiles) val outMd5 = Md5.toMd5Directories(outputArchives) Pair(inMd5, outMd5) } else { @@ -150,7 +157,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana context.pluginInfo.incrementalAssemblyContributors.forEach { val taskInfo = it.assemble(project, context) val closure = incrementalManagerFactory.create().toIncrementalTaskClosure(TASK_ASSEMBLE, { - p: Project -> taskInfo }, context.variant) + _: Project -> taskInfo }, context.variant) val thisResult = closure.invoke(project) if (! thisResult.success) { // Abort at the first failure @@ -174,24 +181,24 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } // @Task(name = "generateOsgiManifest", alwaysRunAfter = arrayOf(TASK_ASSEMBLE)) - fun generateManifest(project: Project): TaskResult { - val analyzer = Analyzer().apply { - jar = aQute.bnd.osgi.Jar(project.projectProperties.get(Archives.JAR_NAME) as String) - val dependencies = project.compileDependencies + project.compileRuntimeDependencies - dependencyManager.calculateDependencies(project, context, passedDependencies = dependencies).forEach { - addClasspath(it.jarFile.get()) - } - setProperty(Analyzer.BUNDLE_VERSION, project.version) - setProperty(Analyzer.BUNDLE_NAME, project.group) - setProperty(Analyzer.BUNDLE_DESCRIPTION, project.description) - setProperty(Analyzer.IMPORT_PACKAGE, "*") - setProperty(Analyzer.EXPORT_PACKAGE, "*;-noimport:=false;version=" + project.version) - } - - val manifest = analyzer.calcManifest() - manifest.write(System.out) - return TaskResult() - } +// fun generateManifest(project: Project): TaskResult { +// val analyzer = Analyzer().apply { +// jar = aQute.bnd.osgi.Jar(project.projectProperties.get(Archives.JAR_NAME) as String) +// val dependencies = project.compileDependencies + project.compileRuntimeDependencies +// dependencyManager.calculateDependencies(project, context, passedDependencies = dependencies).forEach { +// addClasspath(it.jarFile.get()) +// } +// setProperty(Analyzer.BUNDLE_VERSION, project.version) +// setProperty(Analyzer.BUNDLE_NAME, project.group) +// setProperty(Analyzer.BUNDLE_DESCRIPTION, project.description) +// setProperty(Analyzer.IMPORT_PACKAGE, "*") +// setProperty(Analyzer.EXPORT_PACKAGE, "*;-noimport:=false;version=" + project.version) +// } +// +// val manifest = analyzer.calcManifest() +// manifest.write(System.out) +// return TaskResult() +// } @Task(name = PackagingPlugin.TASK_INSTALL, description = "Install the artifacts", From 8d06df9b8c58544390eb3cd1494b0c9e17e4cf2e Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 15:21:51 -0700 Subject: [PATCH 05/10] Comments. --- .../kobalt/plugin/packaging/PackagingPlugin.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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 2e81d778..0ac6fe18 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -1,6 +1,5 @@ package com.beust.kobalt.plugin.packaging -import aQute.bnd.osgi.Analyzer import com.beust.kobalt.* import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.Directive @@ -73,24 +72,27 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana // assemble task: // - Input: Calculate the list of all the included files for every archive (jar/war/zip) and // store them in the `zipToFiles` map. - // - Output: Calculate all the output archive files into `allFiles` + // - Output: Calculate all the output archive files into `outputFiles` // - // `zipToFiles` is used again so we can pass that list of included files to the actual execution - // of the task, so we don't have to look for them a second time + // `zipToFiles` is used again after this loop so we can pass the list of included files we just + // calculated for all the archives in the actual execution of the task, so we don't have to + // look for them a second time. // val allIncludedFiles = arrayListOf() - val outputArchives = arrayListOf() + val outputFiles = arrayListOf() allConfigs.forEach { packageConfig -> listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives -> archives.forEach { val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it) val outputFile = jarGenerator.fullArchiveName(project, context, it.name) - outputArchives.add(outputFile) + outputFiles.add(outputFile) allIncludedFiles.addAll(files) zipToFiles[it.name] = files } } } + + // Turn the IncludedFiles into actual Files val inputFiles = allIncludedFiles.fold(arrayListOf()) { files, includedFile: IncludedFile -> val foundFiles = includedFile.allFromFiles(project.directory) val absFiles = foundFiles.map { @@ -101,7 +103,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana } val inMd5 = Md5.toMd5Directories(inputFiles) - val outMd5 = Md5.toMd5Directories(outputArchives) + val outMd5 = Md5.toMd5Directories(outputFiles) Pair(inMd5, outMd5) } else { Pair(null, null) From 778db322a5978c78e670a2ab667a34bd3edb5edb Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 15:27:53 -0700 Subject: [PATCH 06/10] Kotlin 1.1.1. --- kobalt/src/Build.kt | 2 +- .../src/main/kotlin/com/beust/kobalt/Constants.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index ad08b98d..865a6d26 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -27,7 +27,7 @@ object Versions { val maven = "3.3.9" val mavenResolver = "1.0.3" val slf4j = "1.7.3" - val kotlin = "1.1.0" + val kotlin = "1.1.1" val aether = "1.0.2.v20150114" } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Constants.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Constants.kt index f6a8ea98..6305f1b1 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Constants.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Constants.kt @@ -8,7 +8,7 @@ object Constants { val BUILD_FILE_NAME = "Build.kt" val BUILD_FILE_DIRECTORY = "kobalt/src" val BUILD_FILE_PATH = KFiles.joinDir(BUILD_FILE_DIRECTORY, BUILD_FILE_NAME) - val KOTLIN_COMPILER_VERSION = "1.1.0" + val KOTLIN_COMPILER_VERSION = "1.1.1" internal val DEFAULT_REPOS = listOf( // "https://maven-central.storage.googleapis.com/", From 99c447805e9d69f1ae2350dc5ebdc9e8540486b8 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 16 Mar 2017 15:28:01 -0700 Subject: [PATCH 07/10] 1.0.13. --- kobalt/wrapper/kobalt-wrapper.properties | 2 +- src/main/resources/kobalt.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index 26487e73..20728f85 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.12 \ No newline at end of file +kobalt.version=1.0.13 \ No newline at end of file diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 067473ac..701a3432 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=1.0.12 +kobalt.version=1.0.13 From 4f32f0ba2f94c3c4d3a0a8ece3d531d599c95296 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 9 Mar 2017 15:10:18 -0800 Subject: [PATCH 08/10] 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) { From c80020c36a93a1aefedd6b37e7a82f8d09c0ce69 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 10 Mar 2017 16:56:24 -0800 Subject: [PATCH 09/10] Added AutoGitTagConfig. --- .../main/kotlin/com/beust/kobalt/misc/Git.kt | 14 ++-- .../kobalt/plugin/publish/PublishPlugin.kt | 66 ++++++++++++------- 2 files changed, 50 insertions(+), 30 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 e8fec4fa..67eb8bef 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: Triple) : TaskResult { + fun maybeTagRelease(project: Project, uploadResult: TaskResult, auto: Boolean, tag: String, message: String) : TaskResult { val result = - if (uploadResult.success && autoGitTag.first) { - val tagSuccess = tagRelease(project, autoGitTag) + if (uploadResult.success && auto) { + val tagSuccess = tagRelease(project, auto, tag, message) if (! tagSuccess) { TaskResult(false, "Couldn't tag the project") } else { @@ -21,9 +21,9 @@ class Git @Inject constructor() { return result } - private fun tagRelease(project: Project, autoGitTag: Triple) : Boolean { + private fun tagRelease(project: Project, auto: Boolean, tag: String, message: String) : Boolean { + val version = if (tag.isNullOrBlank()) project.version else tag val success = try { - 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"))) @@ -31,11 +31,11 @@ class Git @Inject constructor() { .findGitDir() .build() val git = org.eclipse.jgit.api.Git(repo) - val ref = git.tag().setName(version).setMessage(autoGitTag.third).call() + val ref = git.tag().setName(version).setMessage(message).call() git.push().setPushTags().call() true } catch(ex: Exception) { - warn("Couldn't create tag ${project.version}: ${ex.message}", ex) + warn("Couldn't create tag ${version}: ${ex.message}", ex) false } 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 78753ccc..122c536f 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -112,6 +112,7 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener val jcenter = bintrayFactory.create(user, password, org) var success = false val configuration = bintrayConfigurations[project.name] + val autoGitTagConfig = autoGitTagConfigurations[project.name] val messages = arrayListOf() val tmpResult = @@ -133,7 +134,13 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener messages.add(taskResult.errorMessage!!) } } - git.maybeTagRelease(project, TaskResult(), configuration.autoGitTag) + if (autoGitTagConfig != null) { + with(autoGitTagConfig) { + git.maybeTagRelease(project, TaskResult(), auto, tag, message) + } + } else { + TaskResult() + } } else { context.logger.log(project.name, 2, "Couldn't find any jcenter{} configuration, not uploading anything") TaskResult() @@ -153,6 +160,7 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener private fun uploadGithub(project: Project) : TaskResult { val configuration = githubConfigurations[project.name] + val autoGitTagConfig = autoGitTagConfigurations[project.name] // // Upload individual files, if applicable @@ -163,7 +171,13 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener logk(project.name, 2, "Uploading $it tag: ${project.version}") github.uploadRelease(project.name, project.version!!, it) } - git.maybeTagRelease(project, TaskResult(), configuration.autoGitTag) + if (autoGitTagConfig != null) { + with(autoGitTagConfig) { + git.maybeTagRelease(project, TaskResult(), auto, tag, message) + } + } else { + TaskResult() + } } else { warn("Couldn't find any github{} configuration, not uploading anything") TaskResult() @@ -187,20 +201,29 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener fun addGithubConfiguration(projectName: String, config: GithubConfig) { githubConfigurations.put(projectName, config) } + + /** + * Map of project name -> AutoGitTagConfiguration + */ + private val autoGitTagConfigurations = hashMapOf() + fun addAutoGitTagConfiguration(projectName: String, config: AutoGitTagConfig) { + autoGitTagConfigurations.put(projectName, config) + } +} + +data class AutoGitTagConfig(val project: Project) { + @Directive + var auto: Boolean = true + + @Directive + var tag : String = project.version!! + + @Directive + var message : String = "" } 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 - 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) { @@ -215,9 +238,8 @@ fun Project.github(init: GithubConfig.() -> Unit): GithubConfig = (Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addGithubConfiguration(name, config) } -data class BintrayConfig(val project: Project) { +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). @@ -234,15 +256,6 @@ data class BintrayConfig(val project: Project) { @Directive var sign: Boolean = false - /** - * If true, automatically tag this release with the current version number and push that tag to origin when - * the uploadBintray task is called. - */ - @Directive - 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) { files.add(Pair(filePath, url)) @@ -261,3 +274,10 @@ fun Project.bintray(init: BintrayConfig.() -> Unit) = config.init() (Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addBintrayConfiguration(name, config) } + +@Directive +fun Project.autoGitTag(init: AutoGitTagConfig.() -> Unit) = + AutoGitTagConfig(this).also { config -> + config.init() + (Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addAutoGitTagConfiguration(name, config) + } From 49538338a44f86231cfbf2f8733ed8043b93a46f Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 16 Mar 2017 19:22:28 -0700 Subject: [PATCH 10/10] Refactored duplicate code. --- .../kobalt/plugin/publish/PublishPlugin.kt | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) 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 122c536f..5a442893 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -44,6 +44,16 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener return TaskResult() } + private fun autoGitTag(project: Project, uploadResult: TaskResult, config: AutoGitTagConfig?) : TaskResult { + if (config != null) { + with(config) { + return git.maybeTagRelease(project, uploadResult, auto, tag, message) + } + } else { + return TaskResult() + } + } + private fun validateProject(project: Project) { requireNotNull(project.name, { "Project $project should have a name" }) requireNotNull(project.version, { "Project $project should have a version" }) @@ -112,7 +122,6 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener val jcenter = bintrayFactory.create(user, password, org) var success = false val configuration = bintrayConfigurations[project.name] - val autoGitTagConfig = autoGitTagConfigurations[project.name] val messages = arrayListOf() val tmpResult = @@ -134,13 +143,11 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener messages.add(taskResult.errorMessage!!) } } - if (autoGitTagConfig != null) { - with(autoGitTagConfig) { - git.maybeTagRelease(project, TaskResult(), auto, tag, message) - } - } else { - TaskResult() - } + + // + // Tag release, if applicable + // + autoGitTag(project, TaskResult(), autoGitTagConfigurations[project.name]) } else { context.logger.log(project.name, 2, "Couldn't find any jcenter{} configuration, not uploading anything") TaskResult() @@ -160,7 +167,6 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener private fun uploadGithub(project: Project) : TaskResult { val configuration = githubConfigurations[project.name] - val autoGitTagConfig = autoGitTagConfigurations[project.name] // // Upload individual files, if applicable @@ -171,13 +177,11 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener logk(project.name, 2, "Uploading $it tag: ${project.version}") github.uploadRelease(project.name, project.version!!, it) } - if (autoGitTagConfig != null) { - with(autoGitTagConfig) { - git.maybeTagRelease(project, TaskResult(), auto, tag, message) - } - } else { - TaskResult() - } + + // + // Tag release, if applicable + // + autoGitTag(project, TaskResult(), autoGitTagConfigurations[project.name]) } else { warn("Couldn't find any github{} configuration, not uploading anything") TaskResult() @@ -238,7 +242,7 @@ fun Project.github(init: GithubConfig.() -> Unit): GithubConfig = (Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addGithubConfiguration(name, config) } -data class BintrayConfig(val project: Project) { +data class BintrayConfig(val project: Project) { val files = arrayListOf>() /**