Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. -->
<entityCountThreshold>20</entityCountThreshold>

<!-- Optional. Per-entity thresholds that override the global entityCountThreshold
for the respective coverage entity. -->
<entityCountThresholdLines>20</entityCountThresholdLines>
<entityCountThresholdBranches>10</entityCountThresholdBranches>
<entityCountThresholdInstructions>15</entityCountThresholdInstructions>
</violations>

<!-- Optional. Exec files include pattern. By default 'build/jacoco.exec' file is used -->
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>diff-coverage-maven-plugin</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
<packaging>maven-plugin</packaging>
<version>1.2.0</version>
<version>1.3.0</version>
<description>
Diff coverage maven plugin builds code coverage report of new and modified code based on a provided diff
</description>
Expand Down
21 changes: 12 additions & 9 deletions src/it/violation-rule-threshold-check/diffFile.patch
Original file line number Diff line number Diff line change
@@ -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");
}

}
4 changes: 3 additions & 1 deletion src/it/violation-rule-threshold-check/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
<violations>
<failOnViolation>true</failOnViolation>
<minCoverage>1.0</minCoverage>
<entityCountThreshold>20</entityCountThreshold>
<entityCountThresholdLines>5</entityCountThresholdLines>
<entityCountThresholdBranches>3</entityCountThresholdBranches>
<entityCountThresholdInstructions>10</entityCountThresholdInstructions>
</violations>

<reports>
Expand Down
14 changes: 11 additions & 3 deletions src/it/violation-rule-threshold-check/verify.bsh
Original file line number Diff line number Diff line change
@@ -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 );
}
15 changes: 14 additions & 1 deletion src/main/kotlin/io/github/surpsg/DiffCoverageConfiguration.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.surpsg

import io.github.surpsg.deltacoverage.config.CoverageEntity
import java.io.File
import java.net.URL

Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/io/github/surpsg/DiffCoverageMojo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class DiffCoverageMojo : AbstractMojo() {
ViolationRule {
coverageEntity = entity
minCoverageRatio = violations.minCoverage
entityCountThreshold = violations.entityCountThresholdOrNull
entityCountThreshold = violations.entityCountThresholdForEntity(entity)
}
}
} else {
Expand Down Expand Up @@ -146,7 +146,7 @@ class DiffCoverageMojo : AbstractMojo() {
ViolationRule {
coverageEntity = entity
minCoverageRatio = value
entityCountThreshold = violations.entityCountThresholdOrNull
entityCountThreshold = violations.entityCountThresholdForEntity(entity)
}
}
.toSet()
Expand Down
Loading