Skip to content

Commit 382b574

Browse files
committed
Add tests with 100% branch and mutant coverage
1 parent 116514f commit 382b574

File tree

77 files changed

+7475
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+7475
-83
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ plugins {
2121
net.kautler.jars
2222
net.kautler.antlr
2323
net.kautler.osgi
24+
net.kautler.tests
25+
net.kautler.codenarc
2426
net.kautler.pmd
2527
net.kautler.spotbugs
2628
net.kautler.java9

buildSrc/build.gradle.kts

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2020

2121
plugins {
2222
`kotlin-dsl`
23-
id("com.github.ben-manes.versions") version "0.22.0"
23+
id("com.github.ben-manes.versions") version "0.25.0"
2424
}
2525

2626
buildscript {
@@ -30,7 +30,7 @@ buildscript {
3030
jcenter()
3131
}
3232
dependencies {
33-
classpath("com.fasterxml.jackson.core:jackson-databind:2.9.9.3")
33+
classpath("com.fasterxml.jackson.core:jackson-databind:2.10.0")
3434
}
3535
}
3636

@@ -43,18 +43,20 @@ repositories {
4343
}
4444

4545
dependencies {
46-
implementation(gradlePlugin("com.github.ben-manes.versions:0.22.0"))
46+
implementation(gradlePlugin("com.github.ben-manes.versions:0.25.0"))
4747
implementation(gradlePlugin("org.ajoberstar.grgit:3.1.1"))
4848
implementation(gradlePlugin("com.github.spotbugs:2.0.0"))
4949
implementation(gradlePlugin("biz.aQute.bnd.builder:4.2.0"))
50-
implementation(gradlePlugin("de.marcphilipp.nexus-publish:0.3.1"))
51-
implementation(gradlePlugin("io.codearte.nexus-staging:0.21.0"))
50+
implementation(gradlePlugin("de.marcphilipp.nexus-publish:0.4.0"))
51+
implementation(gradlePlugin("io.codearte.nexus-staging:0.21.1"))
5252
implementation(gradlePlugin("net.researchgate.release:2.8.1"))
5353
implementation(gradlePlugin("net.wooga.github:1.4.0"))
54-
implementation("com.fasterxml.jackson.core:jackson-databind:2.9.9.3")
55-
implementation("com.github.javaparser:javaparser-core:3.14.11")
54+
implementation(gradlePlugin("info.solidsoft.pitest:1.4.5"))
55+
implementation("com.fasterxml.jackson.core:jackson-databind:2.10.0")
56+
implementation("com.github.javaparser:javaparser-core:3.14.159265359")
5657
implementation("org.kohsuke:github-api:1.95")
57-
implementation("net.sf.saxon:Saxon-HE:9.9.1-4")
58+
implementation("net.sf.saxon:Saxon-HE:9.9.1-5")
59+
implementation("org.pitest:pitest:1.4.10")
5860
}
5961

6062
kotlinDslPluginOptions {
@@ -70,26 +72,22 @@ tasks.withType<KotlinCompile>().configureEach {
7072
tasks.dependencyUpdates {
7173
checkForGradleUpdate = false
7274

73-
resolutionStrategy {
74-
componentSelection {
75-
all {
76-
if (Regex("""(?i)[.-](?:${listOf(
77-
"alpha",
78-
"beta",
79-
"rc",
80-
"cr",
81-
"m",
82-
"preview",
83-
"test",
84-
"pr",
85-
"pre",
86-
"b",
87-
"ea"
88-
).joinToString("|")})[.\d-]*""").containsMatchIn(candidate.version)) {
89-
reject("preliminary release")
90-
}
91-
}
92-
}
75+
rejectVersionIf {
76+
val preliminaryReleaseRegex = Regex("""(?i)[.-](?:${listOf(
77+
"alpha",
78+
"beta",
79+
"rc",
80+
"cr",
81+
"m",
82+
"preview",
83+
"test",
84+
"pr",
85+
"pre",
86+
"b",
87+
"ea"
88+
).joinToString("|")})[.\d-]*""")
89+
preliminaryReleaseRegex.containsMatchIn(candidate.version)
90+
&& !preliminaryReleaseRegex.containsMatchIn(currentVersion)
9391
}
9492

9593
outputFormatter = closureOf<Result> {

buildSrc/src/main/kotlin/net/kautler/PropertyExtension.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,25 @@
1616

1717
package net.kautler
1818

19+
import org.gradle.api.provider.ListProperty
1920
import org.gradle.api.provider.Property
21+
import org.gradle.api.provider.Provider
22+
import org.gradle.api.provider.SetProperty
2023

2124
@Suppress("UnstableApiUsage")
2225
operator fun <T> Property<T>.invoke(value: T) = set(value)
26+
27+
@Suppress("UnstableApiUsage")
28+
operator fun <T> Property<T>.invoke(valueProvider: Provider<out T>) = set(valueProvider)
29+
30+
@Suppress("UnstableApiUsage")
31+
operator fun <T> ListProperty<T>.invoke(value: Iterable<T>) = set(value)
32+
33+
@Suppress("UnstableApiUsage")
34+
operator fun <T> ListProperty<T>.invoke(valueProvider: Provider<out Iterable<T>>) = set(valueProvider)
35+
36+
@Suppress("UnstableApiUsage")
37+
operator fun <T> SetProperty<T>.invoke(value: Iterable<T>) = set(value)
38+
39+
@Suppress("UnstableApiUsage")
40+
operator fun <T> SetProperty<T>.invoke(valueProvider: Provider<out Iterable<T>>) = set(valueProvider)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2019 Bjoern Kautler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.kautler
18+
19+
plugins {
20+
java
21+
codenarc
22+
}
23+
24+
val versions: Map<String, String> by project
25+
26+
codenarc {
27+
toolVersion = versions["codenarc"] ?: error("codenarc version is missing")
28+
// customized copy from http://codenarc.sourceforge.net/StarterRuleSet-AllRulesByCategory.groovy.txt
29+
// update with new rules when version is updated (previous version: 1.4)
30+
config = resources.text.fromFile("config/codenarc/codenarc.groovy")
31+
}
32+
33+
tasks.withType<CodeNarc>().configureEach {
34+
val sourceSetName = name.replaceFirst("^codenarc".toRegex(), "").decapitalize()
35+
@Suppress("UnstableApiUsage")
36+
compilationClasspath = sourceSets[sourceSetName].let {
37+
it.runtimeClasspath + it.compileClasspath + project.configurations[it.compileOnlyConfigurationName]
38+
}
39+
40+
@Suppress("UnstableApiUsage")
41+
reports.xml.isEnabled = true
42+
}

buildSrc/src/main/kotlin/net/kautler/java.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ tasks.withType<JavaCompile>().configureEach {
5454
// delay this action to get the correct version for later configured compile tasks
5555
afterEvaluate {
5656
tasks.withType<JavaCompile>().configureEach {
57-
if (JavaVersion.current().isJava9Compatible) {
57+
// there is a bug in Java 9 that prevents usage of --release
58+
// https://bugs.openjdk.java.net/browse/JDK-8139607
59+
if (JavaVersion.current().isJava10Compatible) {
5860
options.compilerArgs.apply {
5961
add("--release")
6062
add(toVersion(targetCompatibility).majorVersion)

buildSrc/src/main/kotlin/net/kautler/javadoc.gradle.kts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ tasks.withType<Javadoc>().configureEach {
5151
links!!.apply {
5252
val versions: Map<String, String> by project
5353
if (java.targetCompatibility != VERSION_1_8) {
54-
throw ConfigurationException("JavaDoc URL for JRE needs to be adapted to new target compatibility ${java.targetCompatibility}")
54+
throw ConfigurationException("JavaDoc URL for JRE needs to be adapted to new target compatibility ${java.targetCompatibility}")
5555
}
5656
add("https://docs.oracle.com/javase/8/docs/api/")
57-
add("https://www.javadoc.io/page/javax.enterprise/cdi-api/${versions["cdi"]}/")
58-
add("https://www.javadoc.io/page/javax.inject/javax.inject/${versions["javax.inject"]}/")
59-
add("https://www.javadoc.io/page/org.javacord/javacord-api/${versions["javacord"]}/")
57+
add("https://static.javadoc.io/javax.enterprise/cdi-api/${versions["cdi"]}/")
58+
add("https://static.javadoc.io/javax.inject/javax.inject/${versions["javax.inject"]}/")
59+
add("https://static.javadoc.io/org.javacord/javacord-api/${versions["javacord"]}/")
6060
}
6161
isUse = true
6262
isVersion = true
@@ -67,7 +67,8 @@ tasks.withType<Javadoc>().configureEach {
6767
if (javaToolChain.isJava9Compatible) {
6868
addBooleanOption("html5", true)
6969
addStringOption("-release", java.targetCompatibility.majorVersion)
70-
if (javaToolChain.isJava11Compatible) {
70+
//TODO: Replace second part with !javaToolChain.isJava13Compatible when supported by Gradle
71+
if (javaToolChain.isJava11Compatible && (javaToolChain.ordinal < 12)) {
7172
addBooleanOption("-no-module-directories", true)
7273
}
7374
} else {

buildSrc/src/main/kotlin/net/kautler/pmd.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ pmd {
2727
// necessary due to https://github.com/gradle/gradle/issues/8514
2828
ruleSets.clear()
2929
ruleSetConfig = resources.text.fromFile("config/pmd/pmd.xml")
30+
incrementalAnalysis(true)
3031
}
3132

32-
tasks.withType<Pmd>().configureEach {
33+
tasks.named<Pmd>("pmdMain") {
3334
exclude("net/kautler/command/usage/UsageBaseListener.java")
3435
exclude("net/kautler/command/usage/UsageBaseVisitor.java")
3536
exclude("net/kautler/command/usage/UsageLexer.java")

buildSrc/src/main/kotlin/net/kautler/publishing.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ val finishMilestone by tasks.registering {
293293
}
294294
}
295295

296+
tasks.beforeReleaseBuild {
297+
dependsOn(tasks.named("pitest"))
298+
}
299+
296300
tasks.publish {
297301
dependsOn(tasks.closeRepository)
298302
}

buildSrc/src/main/kotlin/net/kautler/spotbugs.gradle.kts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import javax.xml.transform.stream.StreamResult
2424
import javax.xml.transform.stream.StreamSource
2525

2626
plugins {
27+
`java-base`
2728
id("com.github.spotbugs")
2829
}
2930

@@ -41,15 +42,12 @@ spotbugs {
4142
val spotbugsStylesheets by configurations.registering { isTransitive = false }
4243

4344
dependencies {
44-
"spotbugsStylesheets"("com.github.spotbugs:spotbugs:4.0.0-beta3")
45+
"spotbugsStylesheets"("com.github.spotbugs:spotbugs:4.0.0-beta4")
4546
spotbugsPlugins("com.h3xstream.findsecbugs:findsecbugs-plugin:${versions["findsecbugs"]}")
4647
spotbugsPlugins("com.mebigfatguy.sb-contrib:sb-contrib:${versions["sb-contrib"]}")
4748
}
4849

49-
//TODO: tasks.register cannot be used within configureEach
50-
// replace the following after the task supports multiple output formats natively
51-
//tasks.withType<SpotBugsTask>().configureEach {
52-
tasks.withType<SpotBugsTask> spotBugsTask@{
50+
tasks.named<SpotBugsTask>("spotbugsMain") {
5351
val excludedClasses = listOf(
5452
"UsageBaseListener",
5553
"UsageBaseVisitor",
@@ -65,6 +63,18 @@ tasks.withType<SpotBugsTask> spotBugsTask@{
6563
}
6664
}
6765
}
66+
}
67+
68+
//TODO: replace the HTML report task after the task supports multiple output formats natively
69+
// and change "all" to "configureEach"
70+
tasks.withType<SpotBugsTask>().all {
71+
//TODO: Remove this after upgrading Spotbugs to 4.0.0+ which supports Java 13
72+
enabled = JavaVersion.current().ordinal < 12
73+
74+
val sourceSetName = name.removePrefix("spotbugs").decapitalize()
75+
classpath += sourceSets[sourceSetName].let {
76+
it.compileClasspath + project.configurations[it.compileOnlyConfigurationName]
77+
}
6878

6979
reports {
7080
xml.isWithMessages = true
@@ -73,8 +83,6 @@ tasks.withType<SpotBugsTask> spotBugsTask@{
7383
}
7484

7585
finalizedBy(tasks.register("${name}HtmlReport") {
76-
dependsOn(this@spotBugsTask)
77-
7886
val stylesheet = reports.html.let { it as CustomizableHtmlReport }.stylesheet!!
7987
// work-around for https://github.com/gradle/gradle/issues/9648
8088
//inputs.file(stylesheet.asFile()).withPropertyName("spotbugsStylesheet").withPathSensitivity(NONE)

0 commit comments

Comments
 (0)