From: Julien Lancelot Date: Fri, 25 Nov 2016 16:02:08 +0000 (+0100) Subject: SONAR-8089 Add missing condition on snapshots.islast=true X-Git-Tag: 6.2-RC2~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1412%2Fhead;p=sonarqube.git SONAR-8089 Add missing condition on snapshots.islast=true --- diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml index 61b1268b219..9b5900bba35 100644 --- a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml @@ -112,6 +112,7 @@ + and analysis.islast=${_true} and pm.metric_id in #{metricId} diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java index beddaf6c737..9878b64a49f 100644 --- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java @@ -413,6 +413,40 @@ public class MeasureDaoTest { verifyMeasures(project, MeasureTreeQuery.builder().setQualifiers(asList(FILE, UNIT_TEST_FILE)).setStrategy(LEAVES), "M2", "M3", "M6"); } + @Test + public void select_tree_by_query_use_only_latest_analysis() { + ComponentDto project = db.components().insertProject(); + ComponentDto file1 = db.components().insertComponent(newFileDto(project).setUuid("C1").setName("File One")); + db.components().insertComponent(newFileDto(project).setUuid("C2").setName("File Two").setQualifier(UNIT_TEST_FILE)); + insertAnalysis(LAST_ANALYSIS_UUID, project.uuid(), true); + insertAnalysis(OTHER_ANALYSIS_UUID, project.uuid(), false); + db.components().indexAllComponents(); + + // project + insertMeasure("PROJECT_M1", LAST_ANALYSIS_UUID, project.uuid(), NCLOC_METRIC_ID); + insertMeasure("PROJECT_M2", OTHER_ANALYSIS_UUID, project.uuid(), NCLOC_METRIC_ID); + // component C1 + insertMeasure("M2", LAST_ANALYSIS_UUID, "C1", NCLOC_METRIC_ID); + insertMeasure("M3", LAST_ANALYSIS_UUID, "C1", COVERAGE_METRIC_ID); + insertMeasure("M4", OTHER_ANALYSIS_UUID, "C1", COVERAGE_METRIC_ID); + // component C2 + insertMeasure("M5", LAST_ANALYSIS_UUID, "C2", NCLOC_METRIC_ID); + insertMeasure("M6", OTHER_ANALYSIS_UUID, "C2", NCLOC_METRIC_ID); + db.commit(); + + // Children measures of project + verifyMeasures(project, MeasureTreeQuery.builder().setStrategy(CHILDREN), "PROJECT_M1", "M2", "M3", "M5"); + + // Children measure on file => only measures from itself + verifyMeasures(file1, MeasureTreeQuery.builder().setStrategy(CHILDREN), "M2", "M3"); + + // Leaves measures of project + verifyMeasures(project, MeasureTreeQuery.builder().setStrategy(LEAVES), "PROJECT_M1", "M2", "M3", "M5"); + + // Leaves measure on file + verifyMeasures(file1, MeasureTreeQuery.builder().setStrategy(LEAVES), "M2", "M3"); + } + private Optional selectSingle(MeasureQuery.Builder query) { return underTest.selectSingle(db.getSession(), query.build()); }