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
|
||||
|
||||
import net.thauvin.erik.gradle.semver.SemverPlugin.Types
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.Input
|
||||
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 {
|
||||
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")
|
||||
@TaskAction
|
||||
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
|
||||
logger.warn("Version: ${project.version}")
|
||||
logger.lifecycle("Version: ${project.version}")
|
||||
SemverPlugin.saveProperties(config, version)
|
||||
}
|
||||
}
|
|
@ -43,9 +43,6 @@ class SemverPlugin : Plugin<Project> {
|
|||
private var version = Version()
|
||||
private lateinit var config: SemverConfig
|
||||
|
||||
enum class Types {
|
||||
MAJOR, MINOR, PATCH
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun saveProperties(config: SemverConfig, version: Version) {
|
||||
|
@ -72,25 +69,10 @@ class SemverPlugin : Plugin<Project> {
|
|||
project!!.afterEvaluate(this::afterEvaluate)
|
||||
config = project.extensions.create("semver", SemverConfig::class.java)
|
||||
|
||||
project.tasks.create("incrementMajor", SemverIncrementTask::class.java) {
|
||||
description = "Increments Major version number."
|
||||
config = this@SemverPlugin.config
|
||||
version = this@SemverPlugin.version
|
||||
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
|
||||
project.tasks.apply {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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}")
|
||||
}
|
||||
File(config.properties).apply {
|
||||
|
||||
project.logger.info("[${SemverPlugin::class.simpleName}] Attempting to read properties from: `${this.absoluteFile}`.")
|
||||
if (canRead()) {
|
||||
FileInputStream(this).use { fis ->
|
||||
Properties().apply {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue