Added the Gradle project directory as the configuration properties file location. Closes #6

This commit is contained in:
Erik C. Thauvin 2019-05-24 01:03:30 -07:00
parent e47f762a6f
commit 6081bdfdd5
6 changed files with 70 additions and 15 deletions

16
.idea/checkstyle-idea.xml generated Normal file
View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CheckStyle-IDEA">
<option name="configuration">
<map>
<entry key="checkstyle-version" value="8.19" />
<entry key="copy-libs" value="true" />
<entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
<entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
<entry key="scan-before-checkin" value="false" />
<entry key="scanscope" value="JavaOnly" />
<entry key="suppress-errors" value="false" />
</map>
</option>
</component>
</project>

View file

@ -6,20 +6,20 @@ plugins {
`maven-publish` `maven-publish`
jacoco jacoco
id("com.github.ben-manes.versions") version "0.21.0" id("com.github.ben-manes.versions") version "0.21.0"
id("com.gradle.build-scan") version "2.2.1" id("com.gradle.build-scan") version "2.3"
id("com.gradle.plugin-publish") version "0.10.1" id("com.gradle.plugin-publish") version "0.10.1"
id("io.gitlab.arturbosch.detekt") version "1.0.0-RC14" id("io.gitlab.arturbosch.detekt") version "1.0.0-RC14"
id("org.jlleitschuh.gradle.ktlint") version "7.3.0" id("org.jmailen.kotlinter") version "1.25.2"
id("org.sonarqube") version "2.7" id("org.sonarqube") version "2.7.1"
} }
version = "1.0.0" version = "1.0.1"
group = "net.thauvin.erik.gradle" group = "net.thauvin.erik.gradle"
var github = "https://github.com/ethauvin/semver-gradle" var github = "https://github.com/ethauvin/semver-gradle"
var packageName = "net.thauvin.erik.gradle.semver" var packageName = "net.thauvin.erik.gradle.semver"
var spek_version = "2.0.2" var spek_version = "2.0.5"
repositories { repositories {
jcenter() jcenter()
@ -56,10 +56,6 @@ tasks {
} }
} }
"check" {
dependsOn("ktlintCheck")
}
"sonarqube" { "sonarqube" {
dependsOn("jacocoTestReport") dependsOn("jacocoTestReport")
} }
@ -81,6 +77,12 @@ detekt {
baseline = project.rootDir.resolve("detekt-baseline.xml") baseline = project.rootDir.resolve("detekt-baseline.xml")
} }
kotlinter {
ignoreFailures = false
reporters = arrayOf("html")
experimentalRules = false
}
sonarqube { sonarqube {
properties { properties {
property("sonar.projectName", "semver-gradle") property("sonar.projectName", "semver-gradle")

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View file

@ -59,7 +59,11 @@ class SemverPlugin : Plugin<Project> {
} }
private fun afterEvaluate(project: 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") { if (project.version != "unspecified") {
project.logger.warn( project.logger.warn(

View file

@ -70,12 +70,12 @@ object Utils {
var isNew = false var isNew = false
val props = Properties() val props = Properties()
file.apply { file.apply {
if (!exists()) { try {
if (!createNewFile()) { if (!exists() && createNewFile()) {
throw GradleException("Unable to create: `$absoluteFile`")
} else {
isNew = true isNew = true
} }
} catch (e: Exception) {
throw GradleException("Unable to create: `$absoluteFile`", e)
} }
if (canReadFile()) { if (canReadFile()) {
FileInputStream(this).reader().use { reader -> FileInputStream(this).reader().use { reader ->

View file

@ -32,11 +32,13 @@
package net.thauvin.erik.gradle.semver package net.thauvin.erik.gradle.semver
import net.thauvin.erik.gradle.semver.Utils.canReadFile import net.thauvin.erik.gradle.semver.Utils.canReadFile
import org.gradle.api.GradleException
import org.spekframework.spek2.Spek import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.gherkin.Feature import org.spekframework.spek2.style.gherkin.Feature
import java.io.File import java.io.File
import java.util.Properties import java.util.Properties
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertNull import kotlin.test.assertNull
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -46,6 +48,7 @@ object UtilsSpec : Spek({
val version = Version() val version = Version()
val config = SemverConfig() val config = SemverConfig()
val propsFile = File("test.properties") val propsFile = File("test.properties")
val propsLocked = File("locked.properties")
lateinit var props: Properties lateinit var props: Properties
Scenario("Save/Load Properties") { Scenario("Save/Load Properties") {
@ -167,5 +170,35 @@ object UtilsSpec : Spek({
assertEquals(version.buildMeta, "007") 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()
}
}
} }
}) })