Fixes and more implemenation.
This commit is contained in:
parent
644c712cc7
commit
f821bd0f03
1 changed files with 35 additions and 16 deletions
|
@ -129,7 +129,7 @@ class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor<Proper
|
||||||
var offset = 0
|
var offset = 0
|
||||||
|
|
||||||
try {
|
try {
|
||||||
offset = Integer.parseInt(value)
|
offset = entry.value!!.toInt()
|
||||||
if (entry.operation == Operations.SUBTRACT) {
|
if (entry.operation == Operations.SUBTRACT) {
|
||||||
offset *= -1
|
offset *= -1
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,8 @@ class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor<Proper
|
||||||
cal.add(calendarFields.getOrDefault(entry.unit, Calendar.DATE), offset)
|
cal.add(calendarFields.getOrDefault(entry.unit, Calendar.DATE), offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.setProperty(entry.key, fmt.format(cal.time))
|
||||||
|
|
||||||
return TaskResult()
|
return TaskResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,10 +153,16 @@ class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor<Proper
|
||||||
|
|
||||||
intValue = fmt.parse(if (value.isBlank()) "0" else value).toInt()
|
intValue = fmt.parse(if (value.isBlank()) "0" else value).toInt()
|
||||||
|
|
||||||
if (entry.operation == Operations.ADD) {
|
if (entry.operation != Operations.SET) {
|
||||||
intValue += 1
|
var opValue = 1
|
||||||
} else if (entry.operation == Operations.SUBTRACT) {
|
if (entry.value != null) {
|
||||||
intValue -= 1
|
opValue = fmt.parse(entry.value).toInt()
|
||||||
|
}
|
||||||
|
if (entry.operation == Operations.ADD) {
|
||||||
|
intValue += opValue
|
||||||
|
} else if (entry.operation == Operations.SUBTRACT) {
|
||||||
|
intValue -= opValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.setProperty(entry.key, fmt.format(intValue))
|
p.setProperty(entry.key, fmt.format(intValue))
|
||||||
|
@ -173,7 +181,9 @@ class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor<Proper
|
||||||
if (entry.operation == Operations.SET) {
|
if (entry.operation == Operations.SET) {
|
||||||
p.setProperty(entry.key, value)
|
p.setProperty(entry.key, value)
|
||||||
} else if (entry.operation == Operations.ADD) {
|
} else if (entry.operation == Operations.ADD) {
|
||||||
p.setProperty(entry.key, value + p.getProperty(entry.key, ""))
|
if (entry.value != null) {
|
||||||
|
p.setProperty(entry.key, value + entry.value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TaskResult()
|
return TaskResult()
|
||||||
|
@ -183,16 +193,25 @@ class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor<Proper
|
||||||
var result: String? = null
|
var result: String? = null
|
||||||
|
|
||||||
if (operation == Operations.SET) {
|
if (operation == Operations.SET) {
|
||||||
if (newValue != null && default != null) {
|
if (newValue != null && default == null) {
|
||||||
result = newValue
|
result = newValue
|
||||||
}
|
}
|
||||||
|
if (default != null) {
|
||||||
|
if (newValue == null && value != null) {
|
||||||
|
result = value
|
||||||
|
}
|
||||||
|
|
||||||
if (newValue != null && default != null && value != null) {
|
if (newValue == null && value == null) {
|
||||||
result = value
|
result = default
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newValue != null && default != null && value == null) {
|
if (newValue != null && value != null) {
|
||||||
result = default
|
result = newValue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newValue != null && value == null) {
|
||||||
|
result = default
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = value ?: default
|
result = value ?: default
|
||||||
|
@ -223,7 +242,7 @@ data class Entry(
|
||||||
var key: String = "",
|
var key: String = "",
|
||||||
var value: String? = null,
|
var value: String? = null,
|
||||||
var default: String? = null,
|
var default: String? = null,
|
||||||
var type: Enum<Types> = Types.STRING,
|
var type: Types = Types.STRING,
|
||||||
var operation: Enum<Operations> = Operations.SET,
|
var operation: Enum<Operations> = Operations.SET,
|
||||||
var pattern: String = "",
|
var pattern: String = "",
|
||||||
var unit: Units = Units.DAY)
|
var unit: Units = Units.DAY)
|
||||||
|
@ -231,7 +250,7 @@ data class Entry(
|
||||||
@Directive
|
@Directive
|
||||||
class PropertyFileConfig {
|
class PropertyFileConfig {
|
||||||
var file: String = ""
|
var file: String = ""
|
||||||
var comment: String = ""
|
var comment: String = "PropertyFile Plugin for Kobalt"
|
||||||
val entries = arrayListOf<Entry>()
|
val entries = arrayListOf<Entry>()
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
|
@ -239,7 +258,7 @@ class PropertyFileConfig {
|
||||||
key: String = "",
|
key: String = "",
|
||||||
value: String? = null,
|
value: String? = null,
|
||||||
default: String? = null,
|
default: String? = null,
|
||||||
type: Enum<Types> = Types.STRING,
|
type: Types = Types.STRING,
|
||||||
operation: Enum<Operations> = Operations.SET,
|
operation: Enum<Operations> = Operations.SET,
|
||||||
pattern: String = "",
|
pattern: String = "",
|
||||||
unit: Units = Units.DAY) {
|
unit: Units = Units.DAY) {
|
||||||
|
@ -249,7 +268,7 @@ class PropertyFileConfig {
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@Directive
|
@Directive
|
||||||
fun Project.propertyfile(init: PropertyFileConfig.() -> Unit) {
|
fun Project.propertyFile(init: PropertyFileConfig.() -> Unit) {
|
||||||
PropertyFileConfig().let { config ->
|
PropertyFileConfig().let { config ->
|
||||||
config.init()
|
config.init()
|
||||||
(Plugins.findPlugin(PropertyFilePlugin.NAME) as PropertyFilePlugin).addConfiguration(this, config)
|
(Plugins.findPlugin(PropertyFilePlugin.NAME) as PropertyFilePlugin).addConfiguration(this, config)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue