From 7ed56e46b7c153dde7647368b5381b676f84a41e Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Thu, 28 Sep 2017 11:12:27 +0200 Subject: [PATCH] SONAR-9353 let the built-in quality gate check duplicated lines on new code The built-in quality gate "SonarQube Way" now checks, that the percentage of duplicated lines on new code is less or equal to 3%. --- .../org/sonar/server/qualitygate/RegisterQualityGates.java | 3 +++ .../sonar/server/qualitygate/RegisterQualityGatesTest.java | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java index 8c30643ff65..24f161e79dd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java @@ -28,6 +28,7 @@ import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid; import static org.sonar.api.measures.CoreMetrics.NEW_COVERAGE_KEY; +import static org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY; @@ -85,6 +86,8 @@ public class RegisterQualityGates implements Startable { NEW_MAINTAINABILITY_RATING_KEY, OPERATOR_GREATER_THAN, null, ratingAValue, LEAK_PERIOD); qualityGateConditionsUpdater.createCondition(dbSession, builtin.getId(), NEW_COVERAGE_KEY, OPERATOR_LESS_THAN, null, "80", LEAK_PERIOD); + qualityGateConditionsUpdater.createCondition(dbSession, builtin.getId(), + NEW_DUPLICATED_LINES_DENSITY_KEY, OPERATOR_GREATER_THAN, null, "3", LEAK_PERIOD); qualityGates.setDefault(dbSession, builtin.getId()); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java index b7562a23429..5e3900543d0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java @@ -38,6 +38,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.sonar.api.measures.CoreMetrics.NEW_COVERAGE_KEY; +import static org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY; @@ -68,6 +69,7 @@ public class RegisterQualityGatesTest { MetricDto newSecurity = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_SECURITY_RATING_KEY).setValueType(INT.name()).setHidden(false)); MetricDto newMaintainability = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_MAINTAINABILITY_RATING_KEY).setValueType(PERCENT.name()).setHidden(false)); MetricDto newCoverage = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_COVERAGE_KEY).setValueType(PERCENT.name()).setHidden(false)); + MetricDto newDuplication = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_DUPLICATED_LINES_DENSITY_KEY).setValueType(PERCENT.name()).setHidden(false)); dbSession.commit(); task.start(); @@ -82,7 +84,8 @@ public class RegisterQualityGatesTest { tuple(newReliability.getId().longValue(), OPERATOR_GREATER_THAN, null, "1", 1), tuple(newSecurity.getId().longValue(), OPERATOR_GREATER_THAN, null, "1", 1), tuple(newMaintainability.getId().longValue(), OPERATOR_GREATER_THAN, null, "1", 1), - tuple(newCoverage.getId().longValue(), OPERATOR_LESS_THAN, null, "80", 1)); + tuple(newCoverage.getId().longValue(), OPERATOR_LESS_THAN, null, "80", 1), + tuple(newDuplication.getId().longValue(), OPERATOR_GREATER_THAN, null, "3", 1)); verify(qualityGates).setDefault(any(DbSession.class), anyLong()); task.stop(); -- 2.39.5