]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21455 new_accepted_issues should only be computed in application when all the...
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Fri, 26 Jan 2024 15:36:48 +0000 (16:36 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 31 Jan 2024 20:03:36 +0000 (20:03 +0000)
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ProjectViewAttributes.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/SumFormula.java

index 5aa74cf95ad63f447051b524c203ed1f0bc3ad23..2ef2270e9839ab2fb6562abe186e871641b1c083 100644 (file)
@@ -470,7 +470,7 @@ public class ViewsPersistComponentsStepIT extends BaseStepTest {
       .setUuid(PROJECT_VIEW_1_UUID)
       .setName(PROJECT_VIEW_1_NAME)
       .setDescription("project view description is not persisted")
-      .setProjectViewAttributes(new ProjectViewAttributes(project.uuid(), project.getKey(), analysisDate, null));
+      .setProjectViewAttributes(new ProjectViewAttributes(project.uuid(), project.getKey(), analysisDate, true, null));
   }
 
   private void persistComponents(ComponentDto... componentDtos) {
index 40c093fd6c48a4f7eca0409048389a68c37c5a52..1175514128b55e8d80e4bcb4948aa083a5909995 100644 (file)
@@ -31,12 +31,14 @@ public class ProjectViewAttributes {
   private final String originalKey;
   @CheckForNull
   private final Long analysisDate;
+  private final boolean hasNewCodePeriod;
   private final String branchName;
 
-  public ProjectViewAttributes(String uuid, String originalKey, @Nullable Long analysisDate, @Nullable String branchName) {
+  public ProjectViewAttributes(String uuid, String originalKey, @Nullable Long analysisDate, boolean hasNewCodePeriod, @Nullable String branchName) {
     this.uuid = requireNonNull(uuid, "uuid can't be null");
     this.originalKey = requireNonNull(originalKey, "originalKey can't be null");
     this.analysisDate = analysisDate;
+    this.hasNewCodePeriod = hasNewCodePeriod;
     this.branchName = branchName;
   }
 
@@ -57,12 +59,17 @@ public class ProjectViewAttributes {
     return originalKey;
   }
 
+  public boolean hasNewCodePeriod() {
+    return hasNewCodePeriod;
+  }
+
   @Override
   public String toString() {
     return "ProjectViewAttributes{" +
-      ", uuid='" + uuid + '\'' +
-      ", branchName='" + branchName + '\'' +
-      ", analysisDate=" + analysisDate +
-      '}';
+           ", uuid='" + uuid + '\'' +
+           ", branchName='" + branchName + '\'' +
+           ", hasNewCodePeriod=" + branchName +
+           ", analysisDate=" + analysisDate +
+           '}';
   }
 }
index 876ccc15db4af9a041bb27a6e8c2c97f24d3c727..7e738c37cd2d1a6bdc3031229daec3ad8045c199 100644 (file)
@@ -61,8 +61,9 @@ public abstract class SumFormula<T extends SumCounter<U, T>, U extends Number> i
     @Override
     public Optional<Measure> createMeasure(IntSumCounter counter, CreateMeasureContext context) {
       Optional<Integer> valueOptional = counter.getValue();
-      if (shouldCreateMeasure(context, valueOptional)) {
-        return Optional.of(Measure.newMeasureBuilder().create(valueOptional.get()));
+      Integer value = valueOptional.orElse(null);
+      if (shouldCreateMeasure(context, value)) {
+        return Optional.of(Measure.newMeasureBuilder().create(value));
       }
       return Optional.empty();
     }
@@ -89,15 +90,17 @@ public abstract class SumFormula<T extends SumCounter<U, T>, U extends Number> i
     @Override
     public Optional<Measure> createMeasure(LongSumCounter counter, CreateMeasureContext context) {
       Optional<Long> valueOptional = counter.getValue();
-      if (shouldCreateMeasure(context, valueOptional)) {
-        return Optional.of(Measure.newMeasureBuilder().create(valueOptional.get()));
+      Long value = valueOptional.orElse(null);
+      if (shouldCreateMeasure(context, value)) {
+
+        return Optional.of(Measure.newMeasureBuilder().create(value));
       }
       return Optional.empty();
     }
   }
 
-  private static <T extends Number> boolean shouldCreateMeasure(CreateMeasureContext context, Optional<T> value) {
-    return value.isPresent() && CrawlerDepthLimit.LEAVES.isDeeperThan(context.getComponent().getType());
+  protected static <T extends Number> boolean shouldCreateMeasure(CreateMeasureContext context, @Nullable T value) {
+    return value != null && CrawlerDepthLimit.LEAVES.isDeeperThan(context.getComponent().getType());
   }
 
   @Override