Added increment build metadata task.
This commit is contained in:
parent
edae9cc660
commit
a4e47cef0b
3 changed files with 119 additions and 1 deletions
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* SemverIncrementBuildmetaTask.kt
|
||||
*
|
||||
* Copyright (c) 2018, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.thauvin.erik.gradle.semver
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.CacheableTask
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import javax.inject.Inject
|
||||
|
||||
@CacheableTask
|
||||
open class SemverIncrementBuildMetaTask @Inject constructor(
|
||||
private val config: SemverConfig,
|
||||
private val version: Version
|
||||
) : DefaultTask() {
|
||||
init {
|
||||
group = "version"
|
||||
description = "Increments Build Metadata version number."
|
||||
}
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
@Input
|
||||
var buildMeta: String = ""
|
||||
|
||||
@Suppress("unused")
|
||||
@TaskAction
|
||||
fun increment() {
|
||||
if (version.buildMeta != buildMeta) {
|
||||
version.buildMeta = buildMeta
|
||||
project.version = version.semver
|
||||
logger.lifecycle("Version: ${project.version}")
|
||||
SemverPlugin.saveProperties(config, version)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -77,6 +77,7 @@ class SemverPlugin : Plugin<Project> {
|
|||
create("incrementMajor", SemverIncrementTask::class.java, config, version, SemverConfig.DEFAULT_MAJOR_KEY)
|
||||
create("incrementMinor", SemverIncrementTask::class.java, config, version, SemverConfig.DEFAULT_MINOR_KEY)
|
||||
create("incrementPatch", SemverIncrementTask::class.java, config, version, SemverConfig.DEFAULT_PATCH_KEY)
|
||||
create("incrementBuildMeta", SemverIncrementBuildMetaTask::class.java, config, version)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,6 +94,7 @@ class SemverPlugin : Plugin<Project> {
|
|||
FileInputStream(this).reader().use { reader ->
|
||||
Properties().apply {
|
||||
load(reader)
|
||||
|
||||
version.major = getProperty(config.majorKey, Version.DEFAULT_MAJOR)
|
||||
version.minor = getProperty(config.minorKey, Version.DEFAULT_MINOR)
|
||||
version.patch = getProperty(config.patchKey, Version.DEFAULT_PATCH)
|
||||
|
@ -103,6 +105,10 @@ class SemverPlugin : Plugin<Project> {
|
|||
version.buildMetaPrefix =
|
||||
getProperty(config.buildMetaPrefixKey, Version.DEFAULT_BUILDMETA_PREFIX)
|
||||
version.separator = getProperty(config.separatorKey, Version.DEFAULT_SEPARATOR)
|
||||
|
||||
project.tasks.withType(SemverIncrementBuildMetaTask::class.java) {
|
||||
buildMeta = version.buildMeta
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (exists()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue