Added the Gradle project directory as the configuration properties file location. Closes #6
This commit is contained in:
parent
e47f762a6f
commit
6081bdfdd5
6 changed files with 70 additions and 15 deletions
|
@ -59,7 +59,11 @@ class SemverPlugin : Plugin<Project> {
|
|||
}
|
||||
|
||||
private fun afterEvaluate(project: Project) {
|
||||
val propsFile = File(config.properties)
|
||||
val propsFile = if (File(config.properties).isAbsolute) {
|
||||
File(config.properties)
|
||||
} else {
|
||||
File("${project.projectDir}${File.separator}${config.properties}")
|
||||
}
|
||||
|
||||
if (project.version != "unspecified") {
|
||||
project.logger.warn(
|
||||
|
|
|
@ -70,12 +70,12 @@ object Utils {
|
|||
var isNew = false
|
||||
val props = Properties()
|
||||
file.apply {
|
||||
if (!exists()) {
|
||||
if (!createNewFile()) {
|
||||
throw GradleException("Unable to create: `$absoluteFile`")
|
||||
} else {
|
||||
try {
|
||||
if (!exists() && createNewFile()) {
|
||||
isNew = true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
throw GradleException("Unable to create: `$absoluteFile`", e)
|
||||
}
|
||||
if (canReadFile()) {
|
||||
FileInputStream(this).reader().use { reader ->
|
||||
|
|
|
@ -32,11 +32,13 @@
|
|||
package net.thauvin.erik.gradle.semver
|
||||
|
||||
import net.thauvin.erik.gradle.semver.Utils.canReadFile
|
||||
import org.gradle.api.GradleException
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.gherkin.Feature
|
||||
import java.io.File
|
||||
import java.util.Properties
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
|
@ -46,6 +48,7 @@ object UtilsSpec : Spek({
|
|||
val version = Version()
|
||||
val config = SemverConfig()
|
||||
val propsFile = File("test.properties")
|
||||
val propsLocked = File("locked.properties")
|
||||
lateinit var props: Properties
|
||||
|
||||
Scenario("Save/Load Properties") {
|
||||
|
@ -167,5 +170,35 @@ object UtilsSpec : Spek({
|
|||
assertEquals(version.buildMeta, "007")
|
||||
}
|
||||
}
|
||||
|
||||
Scenario("Save to locked properties") {
|
||||
Given("the locked properties") {
|
||||
propsLocked.createNewFile()
|
||||
propsLocked.setReadOnly()
|
||||
config.properties = propsLocked.name
|
||||
}
|
||||
|
||||
Then("saving the locked properties file") {
|
||||
assertFailsWith<GradleException> {
|
||||
Utils.saveProperties(config, version)
|
||||
}
|
||||
propsLocked.delete()
|
||||
}
|
||||
}
|
||||
|
||||
Scenario("Load locked properties") {
|
||||
lateinit var locked: File
|
||||
|
||||
Given("the locked location") {
|
||||
locked = File("locked")
|
||||
}
|
||||
|
||||
Then("loading locked properties") {
|
||||
assertFailsWith<GradleException> {
|
||||
Utils.loadProperties(File(locked, propsLocked.name))
|
||||
}
|
||||
locked.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue