Added default constructor to increment task.
This commit is contained in:
parent
d1bdd82353
commit
acbd394d2d
2 changed files with 17 additions and 37 deletions
|
@ -31,31 +31,29 @@
|
||||||
*/
|
*/
|
||||||
package net.thauvin.erik.gradle.semver
|
package net.thauvin.erik.gradle.semver
|
||||||
|
|
||||||
import net.thauvin.erik.gradle.semver.SemverPlugin.Types
|
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.tasks.Input
|
|
||||||
import org.gradle.api.tasks.TaskAction
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
open class SemverIncrementTask : DefaultTask() {
|
open class SemverIncrementTask @Inject constructor(
|
||||||
|
private val config: SemverConfig,
|
||||||
|
private val version: Version,
|
||||||
|
private val type: String)
|
||||||
|
: DefaultTask() {
|
||||||
init {
|
init {
|
||||||
group = "version"
|
group = "version"
|
||||||
|
description = "Increments ${type.capitalize()} version number."
|
||||||
}
|
}
|
||||||
|
|
||||||
@Input
|
|
||||||
lateinit var config: SemverConfig
|
|
||||||
|
|
||||||
@Input
|
|
||||||
lateinit var version: Version
|
|
||||||
|
|
||||||
@Input
|
|
||||||
lateinit var type: Types
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun increment() {
|
fun increment() {
|
||||||
version.increment(isMajor = type == Types.MAJOR, isMinor = type == Types.MINOR, isPatch = type == Types.PATCH)
|
version.increment(
|
||||||
|
isMajor = type == SemverConfig.DEFAULT_MAJOR_KEY,
|
||||||
|
isMinor = type == SemverConfig.DEFAULT_MINOR_KEY,
|
||||||
|
isPatch = type == SemverConfig.DEFAULT_PATCH_KEY)
|
||||||
project.version = version.semver
|
project.version = version.semver
|
||||||
logger.warn("Version: ${project.version}")
|
logger.lifecycle("Version: ${project.version}")
|
||||||
SemverPlugin.saveProperties(config, version)
|
SemverPlugin.saveProperties(config, version)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -43,9 +43,6 @@ class SemverPlugin : Plugin<Project> {
|
||||||
private var version = Version()
|
private var version = Version()
|
||||||
private lateinit var config: SemverConfig
|
private lateinit var config: SemverConfig
|
||||||
|
|
||||||
enum class Types {
|
|
||||||
MAJOR, MINOR, PATCH
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun saveProperties(config: SemverConfig, version: Version) {
|
fun saveProperties(config: SemverConfig, version: Version) {
|
||||||
|
@ -72,25 +69,10 @@ class SemverPlugin : Plugin<Project> {
|
||||||
project!!.afterEvaluate(this::afterEvaluate)
|
project!!.afterEvaluate(this::afterEvaluate)
|
||||||
config = project.extensions.create("semver", SemverConfig::class.java)
|
config = project.extensions.create("semver", SemverConfig::class.java)
|
||||||
|
|
||||||
project.tasks.create("incrementMajor", SemverIncrementTask::class.java) {
|
project.tasks.apply {
|
||||||
description = "Increments Major version number."
|
create("incrementMajor", SemverIncrementTask::class.java, config, version, SemverConfig.DEFAULT_MAJOR_KEY)
|
||||||
config = this@SemverPlugin.config
|
create("incrementMinor", SemverIncrementTask::class.java, config, version, SemverConfig.DEFAULT_MINOR_KEY)
|
||||||
version = this@SemverPlugin.version
|
create("incrementPatch", SemverIncrementTask::class.java, config, version, SemverConfig.DEFAULT_PATCH_KEY)
|
||||||
type = Types.MAJOR
|
|
||||||
}
|
|
||||||
|
|
||||||
project.tasks.create("incrementMinor", SemverIncrementTask::class.java) {
|
|
||||||
description = "Increments Minor version number."
|
|
||||||
config = this@SemverPlugin.config
|
|
||||||
version = this@SemverPlugin.version
|
|
||||||
type = Types.MINOR
|
|
||||||
}
|
|
||||||
|
|
||||||
project.tasks.create("incrementPatch", SemverIncrementTask::class.java) {
|
|
||||||
description = "Increments Patch version number."
|
|
||||||
config = this@SemverPlugin.config
|
|
||||||
version = this@SemverPlugin.version
|
|
||||||
type = Types.PATCH
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +81,7 @@ class SemverPlugin : Plugin<Project> {
|
||||||
project.logger.warn("Please specify the version in ${config.properties} and remove it from ${project.buildFile.name}")
|
project.logger.warn("Please specify the version in ${config.properties} and remove it from ${project.buildFile.name}")
|
||||||
}
|
}
|
||||||
File(config.properties).apply {
|
File(config.properties).apply {
|
||||||
|
project.logger.info("[${SemverPlugin::class.simpleName}] Attempting to read properties from: `${this.absoluteFile}`.")
|
||||||
if (canRead()) {
|
if (canRead()) {
|
||||||
FileInputStream(this).use { fis ->
|
FileInputStream(this).use { fis ->
|
||||||
Properties().apply {
|
Properties().apply {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue