Browse Source

SONAR-21455 new_accepted_issues should only be computed in application when all the projects have been reanalyzed

tags/10.4.0.87286
Léo Geoffroy 4 months ago
parent
commit
2f6c01779f

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java View 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) {

+ 12
- 5
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ProjectViewAttributes.java View 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 +
'}';
}
}

+ 9
- 6
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/SumFormula.java View 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

Loading…
Cancel
Save