]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9353 let the built-in quality gate check duplicated lines on new code
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Thu, 28 Sep 2017 09:12:27 +0000 (11:12 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Fri, 29 Sep 2017 13:32:54 +0000 (15:32 +0200)
The built-in quality gate "SonarQube Way" now checks, that the percentage of duplicated lines on new code is less or equal to 3%.

server/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java

index 8c30643ff6573df628e1e59bf711a9c4c68b9b91..24f161e79dd14a0d559790d964af17b3a9ee6227 100644 (file)
@@ -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());
   }
 
index b7562a234296cab6cf56f87726f3430ee49e4a4a..5e3900543d044b6809ec24442b4491d9970d6b75 100644 (file)
@@ -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();