diff --git a/CHANGELOG.md b/CHANGELOG.md
index 624666c..1e62c73 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
# Diff-Coverage Maven plugin
+## 1.3.0
+
+### Added
+- Per-entity `entityCountThreshold` parameters in `violations` configuration: `entityCountThresholdLines`, `entityCountThresholdBranches`, `entityCountThresholdInstructions`.
+ These override the global `entityCountThreshold` for the respective coverage entity.
+
## 1.2.0
### Added
diff --git a/README.md b/README.md
index 60dcfe6..c4ff1ec 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,12 @@ The plugin does the next steps:
coverage violation checks are skipped.
Useful to avoid failures on small PRs with few changed lines. -->
20
+
+
+ 20
+ 10
+ 15
diff --git a/pom.xml b/pom.xml
index 6ec1051..ea61e53 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
diff-coverage-maven-plugin
${project.groupId}:${project.artifactId}
maven-plugin
- 1.2.0
+ 1.3.0
Diff coverage maven plugin builds code coverage report of new and modified code based on a provided diff
diff --git a/src/it/violation-rule-threshold-check/diffFile.patch b/src/it/violation-rule-threshold-check/diffFile.patch
index 1119d91..d43f310 100644
--- a/src/it/violation-rule-threshold-check/diffFile.patch
+++ b/src/it/violation-rule-threshold-check/diffFile.patch
@@ -1,14 +1,17 @@
-===================================================================
---- a/src/main/java/com/test/Example.java (revision 9e78667391946d3461759f5589b67d3a676d8ce7)
-+++ b/src/main/java/com/test/Example.java (date 1593433398791)
-@@ -5,7 +5,10 @@
+--- a/src/it/violation-rule-threshold-check/src/main/java/com/test/Example.java (revision c683034bc0fb2bd654d7d2b76e5763d2b91fdf24)
++++ b/src/it/violation-rule-threshold-check/src/main/java/com/test/Example.java (date 1774712720505)
+@@ -3,10 +3,10 @@
+ public class Example {
+
public void sayHello(boolean a) {
- if (a) {
- System.out.println("if");
+- if (a) {
+- System.out.println("if");
+- } else {
+- System.out.println("else");
++ if (a) {
++ System.out.println("if");
+ } else {
+ System.out.println("else");
}
-+ System.out.println("return");
+ System.out.println("return");
}
-
- }
diff --git a/src/it/violation-rule-threshold-check/pom.xml b/src/it/violation-rule-threshold-check/pom.xml
index 05066d3..eff9878 100644
--- a/src/it/violation-rule-threshold-check/pom.xml
+++ b/src/it/violation-rule-threshold-check/pom.xml
@@ -47,7 +47,9 @@
true
1.0
- 20
+ 5
+ 3
+ 10
diff --git a/src/it/violation-rule-threshold-check/verify.bsh b/src/it/violation-rule-threshold-check/verify.bsh
index 3847cc1..2582cde 100644
--- a/src/it/violation-rule-threshold-check/verify.bsh
+++ b/src/it/violation-rule-threshold-check/verify.bsh
@@ -1,9 +1,17 @@
import java.io.*;
import org.codehaus.plexus.util.*;
-String expectedIgnoredMsg = "was ignored because threshold=20";
+String expectedLinesIgnoredMsg = "was ignored because threshold=5";
+String expectedBranchesIgnoredMsg = "was ignored because threshold=3";
+String expectedInstrIgnoredMsg = "was ignored because threshold=10";
String buildLog = FileUtils.fileRead( new File( basedir, "build.log" ) );
-if ( !buildLog.contains( expectedIgnoredMsg ) ) {
- throw new RuntimeException( "Expected coverage violations to be ignored due to entityCountThreshold, but message not found: " + expectedIgnoredMsg );
+if ( !buildLog.contains( expectedLinesIgnoredMsg ) ) {
+ throw new RuntimeException( "Expected lines check to be ignored due to entityCountThresholdLines, but message not found: " + expectedLinesIgnoredMsg );
+}
+if ( !buildLog.contains( expectedBranchesIgnoredMsg ) ) {
+ throw new RuntimeException( "Expected branches check to be ignored due to entityCountThresholdBranches, but message not found: " + expectedBranchesIgnoredMsg );
+}
+if ( !buildLog.contains( expectedInstrIgnoredMsg ) ) {
+ throw new RuntimeException( "Expected instr check to be ignored due to entityCountThresholdInstructions, but message not found: " + expectedInstrIgnoredMsg );
}
diff --git a/src/main/kotlin/io/github/surpsg/DiffCoverageConfiguration.kt b/src/main/kotlin/io/github/surpsg/DiffCoverageConfiguration.kt
index 3cb0d5d..7748119 100644
--- a/src/main/kotlin/io/github/surpsg/DiffCoverageConfiguration.kt
+++ b/src/main/kotlin/io/github/surpsg/DiffCoverageConfiguration.kt
@@ -1,5 +1,6 @@
package io.github.surpsg
+import io.github.surpsg.deltacoverage.config.CoverageEntity
import java.io.File
import java.net.URL
@@ -21,10 +22,22 @@ class ViolationsConfiguration(
var minCoverage: Double = MIN_COVERAGE_PROPERTY_DEFAULT,
- var entityCountThreshold: Int = 0
+ var entityCountThreshold: Int = 0,
+ var entityCountThresholdLines: Int = 0,
+ var entityCountThresholdBranches: Int = 0,
+ var entityCountThresholdInstructions: Int = 0,
) {
val entityCountThresholdOrNull: Int?
get() = entityCountThreshold.takeIf { it > 0 }
+
+ fun entityCountThresholdForEntity(entity: CoverageEntity): Int? {
+ val perEntity = when (entity) {
+ CoverageEntity.LINE -> entityCountThresholdLines
+ CoverageEntity.BRANCH -> entityCountThresholdBranches
+ CoverageEntity.INSTRUCTION -> entityCountThresholdInstructions
+ }
+ return perEntity.takeIf { it > 0 } ?: entityCountThresholdOrNull
+ }
}
class Report(
diff --git a/src/main/kotlin/io/github/surpsg/DiffCoverageMojo.kt b/src/main/kotlin/io/github/surpsg/DiffCoverageMojo.kt
index 8c2dffa..675556c 100644
--- a/src/main/kotlin/io/github/surpsg/DiffCoverageMojo.kt
+++ b/src/main/kotlin/io/github/surpsg/DiffCoverageMojo.kt
@@ -117,7 +117,7 @@ class DiffCoverageMojo : AbstractMojo() {
ViolationRule {
coverageEntity = entity
minCoverageRatio = violations.minCoverage
- entityCountThreshold = violations.entityCountThresholdOrNull
+ entityCountThreshold = violations.entityCountThresholdForEntity(entity)
}
}
} else {
@@ -146,7 +146,7 @@ class DiffCoverageMojo : AbstractMojo() {
ViolationRule {
coverageEntity = entity
minCoverageRatio = value
- entityCountThreshold = violations.entityCountThresholdOrNull
+ entityCountThreshold = violations.entityCountThresholdForEntity(entity)
}
}
.toSet()