From: Simon Brandhof Date: Tue, 28 Jun 2016 07:27:05 +0000 (+0200) Subject: SONAR-7780 table PROJECT_MEASURES should use analysis UUID X-Git-Tag: 6.0-RC1~242 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=87f2df380bc31b616fa9a1b6376b0ff26ee84ccc;p=sonarqube.git SONAR-7780 table PROJECT_MEASURES should use analysis UUID --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureToMeasureDto.java b/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureToMeasureDto.java index bcee6b62bca..718b3e02c87 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureToMeasureDto.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureToMeasureDto.java @@ -22,6 +22,7 @@ package org.sonar.server.computation.measure; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import org.sonar.db.measure.MeasureDto; +import org.sonar.server.computation.analysis.AnalysisMetadataHolder; import org.sonar.server.computation.component.Component; import org.sonar.server.computation.component.DbIdsRepository; import org.sonar.server.computation.component.Developer; @@ -30,9 +31,11 @@ import org.sonar.server.computation.metric.Metric; public class MeasureToMeasureDto { private final DbIdsRepository dbIdsRepository; + private final AnalysisMetadataHolder analysisMetadataHolder; - public MeasureToMeasureDto(DbIdsRepository dbIdsRepository) { + public MeasureToMeasureDto(DbIdsRepository dbIdsRepository, AnalysisMetadataHolder analysisMetadataHolder) { this.dbIdsRepository = dbIdsRepository; + this.analysisMetadataHolder = analysisMetadataHolder; } @Nonnull @@ -40,6 +43,7 @@ public class MeasureToMeasureDto { MeasureDto out = new MeasureDto(); out.setMetricId(metric.getId()); out.setComponentUuid(component.getUuid()); + out.setAnalysisUuid(analysisMetadataHolder.getUuid()); out.setSnapshotId(dbIdsRepository.getSnapshotId(component)); if (measure.hasVariations()) { setVariations(out, measure.getVariations()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java index 42530009c89..59e55e15855 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java @@ -71,6 +71,7 @@ public class MeasureRepositoryImplTest { @Rule public BatchReportReaderRule reportReader = new BatchReportReaderRule(); + private static final String AN_ANALYSIS_UUID = "a1"; private static final String FILE_COMPONENT_KEY = "file cpt key"; private static final ReportComponent FILE_COMPONENT = ReportComponent.builder(Component.Type.FILE, 1).setKey(FILE_COMPONENT_KEY).build(); private static final ReportComponent OTHER_COMPONENT = ReportComponent.builder(Component.Type.FILE, 2).setKey("some other key").build(); @@ -420,6 +421,7 @@ public class MeasureRepositoryImplTest { return new MeasureDto() .setComponentUuid(componentUuid) .setSnapshotId(snapshotId) + .setAnalysisUuid(AN_ANALYSIS_UUID) .setData(SOME_DATA) .setMetricId(metricId); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureToMeasureDtoTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureToMeasureDtoTest.java index ea336c32f8f..b6c9a5d852e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureToMeasureDtoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureToMeasureDtoTest.java @@ -27,6 +27,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.sonar.db.measure.MeasureDto; +import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolderRule; import org.sonar.server.computation.component.Component; import org.sonar.server.computation.component.Developer; import org.sonar.server.computation.component.DumbDeveloper; @@ -51,18 +52,22 @@ public class MeasureToMeasureDtoTest { private static final MetricImpl SOME_DOUBLE_METRIC = new MetricImpl(4, "4", "4", Metric.MetricType.FLOAT); private static final MetricImpl SOME_STRING_METRIC = new MetricImpl(5, "5", "5", Metric.MetricType.STRING); private static final MetricImpl SOME_LEVEL_METRIC = new MetricImpl(6, "6", "6", Metric.MetricType.LEVEL); - - static final Component SOME_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("uuid_1").build(); + private static final String ANALYSIS_UUID = "a1"; + private static final Component SOME_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("uuid_1").build(); @Rule public MutableDbIdsRepositoryRule dbIdsRepository = MutableDbIdsRepositoryRule.create(SOME_COMPONENT); - MeasureToMeasureDto underTest = new MeasureToMeasureDto(dbIdsRepository); + @Rule + public MutableAnalysisMetadataHolderRule analysisMetadataHolder = new MutableAnalysisMetadataHolderRule(); + + MeasureToMeasureDto underTest = new MeasureToMeasureDto(dbIdsRepository, analysisMetadataHolder); @Before public void setUp() throws Exception { dbIdsRepository.setComponentId(SOME_COMPONENT, SOME_COMPONENT_ID); dbIdsRepository.setSnapshotId(SOME_COMPONENT, SOME_SNAPSHOT_ID); + analysisMetadataHolder.setUuid(ANALYSIS_UUID); } @Test(expected = NullPointerException.class) diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java index 2a823ba206f..8c2d769859f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java @@ -30,6 +30,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.rule.RuleDto; +import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; import org.sonar.server.computation.component.Component; import org.sonar.server.computation.component.Developer; @@ -80,6 +81,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { private static final long INTERMEDIATE_1_SNAPSHOT_ID = 4L; private static final long INTERMEDIATE_2_SNAPSHOT_ID = 5L; private static final long LEAF_SNAPSHOT_ID = 6L; + private static final String ANALYSIS_UUID = "a1"; @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); @@ -92,6 +94,9 @@ public class PersistMeasuresStepTest extends BaseStepTest { @Rule public MutableDbIdsRepositoryRule dbIdsRepository = MutableDbIdsRepositoryRule.create(treeRootHolder); + @Rule + public MutableAnalysisMetadataHolderRule analysisMetadataHolder = new MutableAnalysisMetadataHolderRule(); + DbClient dbClient = dbTester.getDbClient(); RuleDto rule; ComponentDto rootDto; @@ -103,7 +108,8 @@ public class PersistMeasuresStepTest extends BaseStepTest { @Before public void setUp() { - underTest = new PersistMeasuresStep(dbClient, metricRepository, new MeasureToMeasureDto(dbIdsRepository), treeRootHolder, measureRepository); + underTest = new PersistMeasuresStep(dbClient, metricRepository, new MeasureToMeasureDto(dbIdsRepository, analysisMetadataHolder), treeRootHolder, measureRepository); + analysisMetadataHolder.setUuid(ANALYSIS_UUID); } private void setupReportComponents() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComputeMeasureVariationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComputeMeasureVariationsStepTest.java index a30a26cd2ac..9966397b101 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComputeMeasureVariationsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComputeMeasureVariationsStepTest.java @@ -51,16 +51,16 @@ import static org.sonar.server.computation.measure.Measure.newMeasureBuilder; public class ReportComputeMeasureVariationsStepTest { - static final Metric ISSUES_METRIC = new MetricImpl(1, "violations", "violations", Metric.MetricType.INT); - static final Metric DEBT_METRIC = new MetricImpl(2, "sqale_index", "sqale_index", Metric.MetricType.WORK_DUR); - static final Metric FILE_COMPLEXITY_METRIC = new MetricImpl(3, "file_complexity", "file_complexity", Metric.MetricType.FLOAT); - static final Metric BUILD_BREAKER_METRIC = new MetricImpl(4, "build_breaker", "build_breaker", Metric.MetricType.BOOL); - static final Metric NEW_DEBT = new MetricImpl(5, "new_debt", "new_debt", Metric.MetricType.WORK_DUR); + private static final Metric ISSUES_METRIC = new MetricImpl(1, "violations", "violations", Metric.MetricType.INT); + private static final Metric DEBT_METRIC = new MetricImpl(2, "sqale_index", "sqale_index", Metric.MetricType.WORK_DUR); + private static final Metric FILE_COMPLEXITY_METRIC = new MetricImpl(3, "file_complexity", "file_complexity", Metric.MetricType.FLOAT); + private static final Metric BUILD_BREAKER_METRIC = new MetricImpl(4, "build_breaker", "build_breaker", Metric.MetricType.BOOL); + private static final Metric NEW_DEBT = new MetricImpl(5, "new_debt", "new_debt", Metric.MetricType.WORK_DUR); + private static final String ANALYSIS_UUID = "a1"; + private static final ComponentDto PROJECT_DTO = ComponentTesting.newProjectDto(); + private static final int PROJECT_REF = 1; + private static final Component PROJECT = ReportComponent.builder(Component.Type.PROJECT, PROJECT_REF).setUuid(PROJECT_DTO.uuid()).build(); - static final ComponentDto PROJECT_DTO = ComponentTesting.newProjectDto(); - - static final int PROJECT_REF = 1; - static final Component PROJECT = ReportComponent.builder(Component.Type.PROJECT, PROJECT_REF).setUuid(PROJECT_DTO.uuid()).build(); @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); @@ -319,7 +319,12 @@ public class ReportComputeMeasureVariationsStepTest { } private static MeasureDto newMeasureDto(int metricId, String componentUuid, long snapshotId, double value) { - return new MeasureDto().setMetricId(metricId).setComponentUuid(componentUuid).setSnapshotId(snapshotId).setValue(value); + return new MeasureDto() + .setMetricId(metricId) + .setComponentUuid(componentUuid) + .setSnapshotId(snapshotId) + .setAnalysisUuid(ANALYSIS_UUID) + .setValue(value); } private static Period newPeriod(int index, SnapshotDto snapshotDto) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java index 4f5cef4e49c..f014d72529b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java @@ -49,14 +49,13 @@ import static org.sonar.db.component.SnapshotTesting.newSnapshotForView; public class ViewsComputeMeasureVariationsStepTest { - static final Metric ISSUES_METRIC = new MetricImpl(1, "violations", "violations", Metric.MetricType.INT); - static final Metric DEBT_METRIC = new MetricImpl(2, "sqale_index", "sqale_index", Metric.MetricType.WORK_DUR); - static final Metric FILE_COMPLEXITY_METRIC = new MetricImpl(3, "file_complexity", "file_complexity", Metric.MetricType.FLOAT); - static final Metric BUILD_BREAKER_METRIC = new MetricImpl(4, "build_breaker", "build_breaker", Metric.MetricType.BOOL); - - static final ComponentDto VIEW_DTO = ComponentTesting.newView(); - - static final Component VIEW = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_DTO.uuid()).build(); + private static final Metric ISSUES_METRIC = new MetricImpl(1, "violations", "violations", Metric.MetricType.INT); + private static final Metric DEBT_METRIC = new MetricImpl(2, "sqale_index", "sqale_index", Metric.MetricType.WORK_DUR); + private static final Metric FILE_COMPLEXITY_METRIC = new MetricImpl(3, "file_complexity", "file_complexity", Metric.MetricType.FLOAT); + private static final Metric BUILD_BREAKER_METRIC = new MetricImpl(4, "build_breaker", "build_breaker", Metric.MetricType.BOOL); + private static final ComponentDto VIEW_DTO = ComponentTesting.newView(); + private static final Component VIEW = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_DTO.uuid()).build(); + private static final String ANALYSIS_UUID = "a1"; @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); @@ -223,7 +222,12 @@ public class ViewsComputeMeasureVariationsStepTest { } private static MeasureDto newMeasureDto(int metricId, String componentUuid, long snapshotId, double value) { - return new MeasureDto().setMetricId(metricId).setComponentUuid(componentUuid).setSnapshotId(snapshotId).setValue(value); + return new MeasureDto() + .setMetricId(metricId) + .setComponentUuid(componentUuid) + .setSnapshotId(snapshotId) + .setAnalysisUuid(ANALYSIS_UUID) + .setValue(value); } private static Period newPeriod(int index, SnapshotDto snapshotDto) { diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest/shared.xml index 289d321734a..9a01b234b33 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest/shared.xml @@ -91,6 +91,7 @@ VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" + analysis_uuid="u1000" text_value="[null]" project_id="[null]" person_id="[null]"/> @@ -99,6 +100,7 @@ VALUE="80" METRIC_ID="2" SNAPSHOT_ID="1000" + analysis_uuid="u1000" text_value="[null]" project_id="[null]" person_id="[null]"/> @@ -108,6 +110,7 @@ VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1001" + analysis_uuid="u1000" text_value="[null]" project_id="[null]" person_id="[null]"/> @@ -116,6 +119,7 @@ VALUE="70" METRIC_ID="2" SNAPSHOT_ID="1001" + analysis_uuid="u1000" text_value="[null]" project_id="[null]" person_id="[null]"/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest/persist_duplication_on_same_file-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest/persist_duplication_on_same_file-result.xml index 68809ddb260..f788fbd156e 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest/persist_duplication_on_same_file-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest/persist_duplication_on_same_file-result.xml @@ -1,11 +1,29 @@ - + measure_data="[null]" + variation_value_1="[null]" + variation_value_2="[null]" + variation_value_3="[null]" + variation_value_4="[null]" + variation_value_5="[null]"/> - + measure_data="[null]" + variation_value_1="[null]" + variation_value_2="[null]" + variation_value_3="[null]" + variation_value_4="[null]" + variation_value_5="[null]"/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest/persist_duplication_on_same_file.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest/persist_duplication_on_same_file.xml index 53ff5efd294..0b498bd98ff 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest/persist_duplication_on_same_file.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistDuplicationMeasuresStepTest/persist_duplication_on_same_file.xml @@ -1,6 +1,17 @@ - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-index-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-index-result.xml index ae4934573a6..3006765aa14 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-index-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-index-result.xml @@ -1,6 +1,18 @@ - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-report-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-report-result.xml index b6a2431d6e8..1cacaf4f14d 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-report-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest/insert-from-report-result.xml @@ -1,6 +1,18 @@ - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_person_measures.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_person_measures.xml index 87064ba708a..bf07feecd84 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_person_measures.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_person_measures.xml @@ -66,6 +66,7 @@ metric_id="1" value="500" snapshot_id="101" + analysis_uuid="u101" person_id="[null]" variation_value_1="[null]" variation_value_2="[null]" @@ -83,6 +84,7 @@ metric_id="1" value="300" snapshot_id="101" + analysis_uuid="u101" person_id="30000" variation_value_1="[null]" variation_value_2="[null]" @@ -99,6 +101,7 @@ metric_id="1" value="200" snapshot_id="101" + analysis_uuid="u101" person_id="40000" variation_value_1="[null]" variation_value_2="[null]" diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_quality_model_measures.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_quality_model_measures.xml index ea433b44e9d..0634b49b664 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_quality_model_measures.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_quality_model_measures.xml @@ -66,6 +66,7 @@ metric_id="1" value="500" snapshot_id="101" + analysis_uuid="u101" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/shared.xml index 1458d4aa9f9..2c8e4c9b202 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/shared.xml @@ -258,6 +258,7 @@ metric_id="1" value="510" snapshot_id="101" + analysis_uuid="u101" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" @@ -273,6 +274,7 @@ metric_id="1" value="510" snapshot_id="102" + analysis_uuid="u101" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" @@ -288,6 +290,7 @@ metric_id="1" value="500" snapshot_id="103" + analysis_uuid="u101" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" @@ -303,6 +306,7 @@ metric_id="1" value="10" snapshot_id="104" + analysis_uuid="u101" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" @@ -319,6 +323,7 @@ metric_id="2" value="[null]" snapshot_id="101" + analysis_uuid="u101" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" @@ -335,6 +340,7 @@ metric_id="3" value="12.3" snapshot_id="101" + analysis_uuid="u101" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" @@ -400,6 +406,7 @@ metric_id="1" value="5000" snapshot_id="110" + analysis_uuid="u110" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" @@ -415,6 +422,7 @@ metric_id="2" value="[null]" snapshot_id="110" + analysis_uuid="u110" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/sort_by_alert.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/sort_by_alert.xml index ce6f4f3c9cb..9b1af0fa97d 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/sort_by_alert.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/sort_by_alert.xml @@ -68,6 +68,7 @@ metric_id="5" value="510" snapshot_id="101" + analysis_uuid="u101" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" @@ -132,6 +133,7 @@ metric_id="5" value="5000" snapshot_id="110" + analysis_uuid="u110" url="[null]" variation_value_1="[null]" variation_value_2="[null]" @@ -197,6 +199,7 @@ metric_id="5" value="5000" snapshot_id="120" + analysis_uuid="u120" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1258_add_analysis_uuid_column_to_measures.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1258_add_analysis_uuid_column_to_measures.rb new file mode 100644 index 00000000000..20544694def --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1258_add_analysis_uuid_column_to_measures.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 6.0 +# +class AddAnalysisUuidColumnToMeasures < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.AddAnalysisUuidColumnToMeasures') + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1259_populate_analysis_uuid_on_measures.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1259_populate_analysis_uuid_on_measures.rb new file mode 100644 index 00000000000..8e4858914f6 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1259_populate_analysis_uuid_on_measures.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 6.0 +# +class PopulateAnalysisUuidOnMeasures < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.PopulateAnalysisUuidOnMeasures') + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1260_clean_measures_with_null_analysis_uuid.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1260_clean_measures_with_null_analysis_uuid.rb new file mode 100644 index 00000000000..7cfe63afcb9 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1260_clean_measures_with_null_analysis_uuid.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 6.0 +# +class CleanMeasuresWithNullAnalysisUuid < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.CleanMeasuresWithNullAnalysisUuid') + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1261_make_analysis_uuid_not_null_on_measures.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1261_make_analysis_uuid_not_null_on_measures.rb new file mode 100644 index 00000000000..2faf467f2d3 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1261_make_analysis_uuid_not_null_on_measures.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 6.0 +# +class MakeAnalysisUuidNotNullOnMeasures < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnMeasures') + end +end diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDto.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDto.java index b8ffe2469cb..7eeb2c77eec 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDto.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDto.java @@ -42,6 +42,7 @@ public class MeasureDto { private String description; private String componentUuid; private Long snapshotId; + private String analysisUuid; private Integer metricId; private Long developerId; @@ -188,6 +189,15 @@ public class MeasureDto { return this; } + public String getAnalysisUuid() { + return analysisUuid; + } + + public MeasureDto setAnalysisUuid(String s) { + this.analysisUuid = s; + return this; + } + /** * @deprecated in 5.5. Does nothing. Kept for compatibility with developer cockpit plugin, version 1.10 */ @@ -240,6 +250,7 @@ public class MeasureDto { .add("description", description) .add("componentUuid", componentUuid) .add("snapshotId", snapshotId) + .add("analysisUuid", analysisUuid) .add("metricId", metricId) .add("developerId", developerId) .add("metricKey", metricKey) diff --git a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java index 09e6fd5afd8..1ab5f63e537 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java +++ b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java @@ -30,7 +30,7 @@ import org.sonar.db.MyBatis; public class DatabaseVersion { - public static final int LAST_VERSION = 1_257; + public static final int LAST_VERSION = 1_261; /** * The minimum supported version which can be upgraded. Lower diff --git a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java index 5dd6b7e55e7..f3a9f918812 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java +++ b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java @@ -86,6 +86,7 @@ import org.sonar.db.version.v56.FixTypeOfRuleTypeOnMysql; import org.sonar.db.version.v60.AddAnalysisUuidColumnToCeActivity; import org.sonar.db.version.v60.AddAnalysisUuidColumnToDuplicationsIndex; import org.sonar.db.version.v60.AddAnalysisUuidColumnToEvents; +import org.sonar.db.version.v60.AddAnalysisUuidColumnToMeasures; import org.sonar.db.version.v60.AddComponentUuidColumnToDuplicationsIndex; import org.sonar.db.version.v60.AddComponentUuidColumnToMeasures; import org.sonar.db.version.v60.AddComponentUuidColumnsToSnapshots; @@ -99,6 +100,7 @@ import org.sonar.db.version.v60.CleanEventsWithoutSnapshotId; import org.sonar.db.version.v60.CleanOrphanRowsInProjects; import org.sonar.db.version.v60.CleanOrphanRowsInResourceIndex; import org.sonar.db.version.v60.CleanOrphanRowsInSnapshots; +import org.sonar.db.version.v60.CleanMeasuresWithNullAnalysisUuid; import org.sonar.db.version.v60.DeleteOrphanDuplicationsIndexRowsWithoutAnalysis; import org.sonar.db.version.v60.DeleteOrphanDuplicationsIndexRowsWithoutComponent; import org.sonar.db.version.v60.DeleteOrphanMeasuresWithoutComponent; @@ -113,6 +115,7 @@ import org.sonar.db.version.v60.DropSnapshotIdColumnsFromDuplicationsIndex; import org.sonar.db.version.v60.DropUnusedMeasuresColumns; import org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnDuplicationsIndex; import org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnEvents; +import org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnMeasures; import org.sonar.db.version.v60.MakeComponentUuidColumnsNotNullOnSnapshots; import org.sonar.db.version.v60.MakeComponentUuidNotNullOnDuplicationsIndex; import org.sonar.db.version.v60.MakeComponentUuidNotNullOnMeasures; @@ -123,6 +126,7 @@ import org.sonar.db.version.v60.MakeUuidPathColumnNotNullOnProjects; import org.sonar.db.version.v60.PopulateAnalysisUuidColumnOnCeActivity; import org.sonar.db.version.v60.PopulateAnalysisUuidOfDuplicationsIndex; import org.sonar.db.version.v60.PopulateAnalysisUuidOnEvents; +import org.sonar.db.version.v60.PopulateAnalysisUuidOnMeasures; import org.sonar.db.version.v60.PopulateComponentUuidColumnsOfSnapshots; import org.sonar.db.version.v60.PopulateComponentUuidOfDuplicationsIndex; import org.sonar.db.version.v60.PopulateComponentUuidOfMeasures; @@ -275,6 +279,13 @@ public class MigrationStepModule extends Module { // PROJECTS.UUID_PATH AddUuidPathColumnToProjects.class, PopulateUuidPathColumnOnProjects.class, - MakeUuidPathColumnNotNullOnProjects.class); + MakeUuidPathColumnNotNullOnProjects.class, + + // PROJECT_MEASURES.ANALYSIS_UUID + AddAnalysisUuidColumnToMeasures.class, + PopulateAnalysisUuidOnMeasures.class, + CleanMeasuresWithNullAnalysisUuid.class, + MakeAnalysisUuidNotNullOnMeasures.class + ); } } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/AddAnalysisUuidColumnToMeasures.java b/sonar-db/src/main/java/org/sonar/db/version/v60/AddAnalysisUuidColumnToMeasures.java new file mode 100644 index 00000000000..f78c80181c9 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/AddAnalysisUuidColumnToMeasures.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.AddColumnsBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class AddAnalysisUuidColumnToMeasures extends DdlChange { + + private static final String TABLE_MEASURES = "project_measures"; + + public AddAnalysisUuidColumnToMeasures(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_MEASURES) + .addColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(true).build()) + .build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/CleanMeasuresWithNullAnalysisUuid.java b/sonar-db/src/main/java/org/sonar/db/version/v60/CleanMeasuresWithNullAnalysisUuid.java new file mode 100644 index 00000000000..2def559c897 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/CleanMeasuresWithNullAnalysisUuid.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.BaseDataChange; +import org.sonar.db.version.MassUpdate; + +public class CleanMeasuresWithNullAnalysisUuid extends BaseDataChange { + + public CleanMeasuresWithNullAnalysisUuid(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select id from project_measures where analysis_uuid is null"); + massUpdate.update("delete from project_measures where id=?"); + massUpdate.rowPluralName("measures"); + massUpdate.execute((row, update) -> { + update.setLong(1, row.getLong(1)); + return true; + }); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnMeasures.java b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnMeasures.java new file mode 100644 index 00000000000..c7c05717cca --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnMeasures.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.AlterColumnsBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class MakeAnalysisUuidNotNullOnMeasures extends DdlChange { + + private static final String TABLE_MEASURES = "project_measures"; + + public MakeAnalysisUuidNotNullOnMeasures(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_MEASURES) + .updateColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) + .build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateAnalysisUuidOnMeasures.java b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateAnalysisUuidOnMeasures.java new file mode 100644 index 00000000000..8393b129fe6 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateAnalysisUuidOnMeasures.java @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.BaseDataChange; +import org.sonar.db.version.MassUpdate; +import org.sonar.db.version.Select; +import org.sonar.db.version.SqlStatement; + +public class PopulateAnalysisUuidOnMeasures extends BaseDataChange { + + public PopulateAnalysisUuidOnMeasures(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select distinct m.snapshot_id, root_snapshots.uuid " + + "from project_measures m " + + "inner join snapshots s on m.snapshot_id=s.id " + + "inner join snapshots root_snapshots on s.root_snapshot_id=root_snapshots.id " + + "where m.analysis_uuid is null"); + massUpdate.update("update project_measures set analysis_uuid=? where snapshot_id=? and analysis_uuid is null"); + massUpdate.rowPluralName("measures"); + massUpdate.execute(this::handle); + } + + private boolean handle(Select.Row row, SqlStatement update) throws SQLException { + long snapshotId = row.getLong(1); + String analysisUuid = row.getString(2); + + update.setString(1, analysisUuid); + update.setLong(2, snapshotId); + + return 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 c256b0b34c7..c98feb9fbcf 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 @@ -8,6 +8,7 @@ pm.person_id as developerId, pm.component_uuid as componentUuid, pm.snapshot_id as snapshotId, + pm.analysis_uuid as analysisUuid, pm.value as value, pm.text_value as textValue, pm.alert_status as alertStatus, @@ -217,18 +218,39 @@ INSERT INTO project_measures ( - value, metric_id, component_uuid, snapshot_id, text_value, alert_status, alert_text, description, - person_id, variation_value_1, variation_value_2, variation_value_3, variation_value_4, - variation_value_5, measure_data) + value, + metric_id, + component_uuid, + snapshot_id, + analysis_uuid, + text_value, + alert_status, + alert_text, + description, + person_id, + variation_value_1, + variation_value_2, + variation_value_3, + variation_value_4, + variation_value_5, + measure_data) VALUES ( - #{value, jdbcType=DOUBLE}, #{metricId, jdbcType=INTEGER}, #{componentUuid, jdbcType=VARCHAR}, + #{value, jdbcType=DOUBLE}, + #{metricId, jdbcType=INTEGER}, + #{componentUuid, jdbcType=VARCHAR}, #{snapshotId, jdbcType=INTEGER}, + #{analysisUuid, jdbcType=VARCHAR}, #{textValue, jdbcType=VARCHAR}, - #{alertStatus, jdbcType=VARCHAR}, #{alertText, jdbcType=VARCHAR}, + #{alertStatus, jdbcType=VARCHAR}, + #{alertText, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, - #{developerId, jdbcType=INTEGER}, #{variation1, jdbcType=DOUBLE}, #{variation2, jdbcType=DOUBLE}, + #{developerId, jdbcType=INTEGER}, + #{variation1, jdbcType=DOUBLE}, + #{variation2, jdbcType=DOUBLE}, #{variation3, jdbcType=DOUBLE}, - #{variation4, jdbcType=DOUBLE}, #{variation5, jdbcType=DOUBLE}, #{dataValue, jdbcType=BINARY} + #{variation4, jdbcType=DOUBLE}, + #{variation5, jdbcType=DOUBLE}, + #{dataValue, jdbcType=BINARY} ) diff --git a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql index ce75f9372b6..0fd0413b98b 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql +++ b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql @@ -464,6 +464,10 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1254'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1255'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1256'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1257'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1258'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1259'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1260'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1261'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482'); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl index 72e3aa398c7..12313c12212 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -199,6 +199,7 @@ CREATE TABLE "PROJECT_MEASURES" ( "VALUE" DOUBLE, "METRIC_ID" INTEGER NOT NULL, "COMPONENT_UUID" VARCHAR(50) NOT NULL, + "ANALYSIS_UUID" VARCHAR(50) NOT NULL, "SNAPSHOT_ID" INTEGER, "TEXT_VALUE" VARCHAR(4000), "ALERT_STATUS" VARCHAR(5), 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 f2c43e9515c..ab4b11eed84 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 @@ -486,6 +486,7 @@ public class MeasureDaoTest { .setValue(value) .setComponentUuid(componentDto.uuid()) .setSnapshotId(snapshotDto.getId()) + .setAnalysisUuid("u1") .setDeveloperId(developerId); dbClient.measureDao().insert(dbSession, measureDto); dbSession.commit(); @@ -498,6 +499,7 @@ public class MeasureDaoTest { underTest.insert(dbSession, new MeasureDto() .setSnapshotId(2L) + .setAnalysisUuid("u2") .setMetricId(3) .setDeveloperId(23L) .setComponentUuid("FILE1") @@ -522,11 +524,13 @@ public class MeasureDaoTest { underTest.insert(dbSession, new MeasureDto() .setSnapshotId(2L) + .setAnalysisUuid("u2") .setMetricId(3) .setComponentUuid("COMPONENT_1") .setValue(2.0d), new MeasureDto() .setSnapshotId(3L) + .setAnalysisUuid("u2") .setMetricId(4) .setComponentUuid("COMPONENT_2") .setValue(4.0d)); diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureTesting.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureTesting.java index fcecfd476b5..9aff2793d0f 100644 --- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureTesting.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureTesting.java @@ -37,6 +37,7 @@ public class MeasureTesting { .setMetricId(metricDto.getId()) .setMetricKey(metricDto.getKey()) .setComponentUuid(snapshot.getComponentUuid()) - .setSnapshotId(snapshot.getId()); + .setSnapshotId(snapshot.getId()) + .setAnalysisUuid(snapshot.getUuid()); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java index a4d75a54649..b72caa7bfba 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java @@ -29,6 +29,6 @@ public class MigrationStepModuleTest { public void verify_count_of_added_MigrationStep_types() { ComponentContainer container = new ComponentContainer(); new MigrationStepModule().configure(container); - assertThat(container.size()).isEqualTo(113); + assertThat(container.size()).isEqualTo(117); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/AddAnalysisUuidColumnToMeasuresTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/AddAnalysisUuidColumnToMeasuresTest.java new file mode 100644 index 00000000000..9f6f288a557 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/AddAnalysisUuidColumnToMeasuresTest.java @@ -0,0 +1,81 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +import static java.lang.String.valueOf; + +public class AddAnalysisUuidColumnToMeasuresTest { + + private static final String TABLE = "project_measures"; + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddAnalysisUuidColumnToMeasuresTest.class, "old_measures.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private AddAnalysisUuidColumnToMeasures underTest = new AddAnalysisUuidColumnToMeasures(db.database()); + + @Test + public void migration_adds_column_to_empty_table() throws SQLException { + underTest.execute(); + + verifyAddedColumn(); + } + + @Test + public void migration_adds_column_to_populated_table() throws SQLException { + for (int i = 0; i < 9; i++) { + db.executeInsert( + TABLE, + "metric_id", valueOf(i), + "value", valueOf(i + 10), + "snapshot_id", valueOf(i + 100), + "component_uuid", valueOf(i + 1_000) + ); + } + db.commit(); + + underTest.execute(); + + verifyAddedColumn(); + } + + @Test + public void migration_is_not_reentrant() throws SQLException { + underTest.execute(); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Fail to execute "); + underTest.execute(); + } + + private void verifyAddedColumn() { + db.assertColumnDefinition(TABLE, "analysis_uuid", Types.VARCHAR, 50, true); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/CleanMeasuresWithNullAnalysisUuidTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/CleanMeasuresWithNullAnalysisUuidTest.java new file mode 100644 index 00000000000..a2d049ccdfe --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/CleanMeasuresWithNullAnalysisUuidTest.java @@ -0,0 +1,90 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import java.util.List; +import java.util.stream.Collectors; +import javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +import static java.lang.String.valueOf; +import static org.assertj.core.api.Assertions.assertThat; + +public class CleanMeasuresWithNullAnalysisUuidTest { + + private static final String TABLE_MEASURES = "project_measures"; + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, CleanMeasuresWithNullAnalysisUuidTest.class, + "in_progress_measures.sql"); + + private CleanMeasuresWithNullAnalysisUuid underTest = new CleanMeasuresWithNullAnalysisUuid(db.database()); + + @Test + public void migration_has_no_effect_on_empty_table() throws SQLException { + underTest.execute(); + + assertThat(db.countRowsOfTable(TABLE_MEASURES)).isEqualTo(0); + } + + @Test + public void migration_deletes_rows_with_null_analysis_uuid() throws SQLException { + insertMeasure(1, "U1"); + insertMeasure(2, "U1"); + insertMeasure(3, null); + db.commit(); + + underTest.execute(); + + assertThat(idsOfRows()).containsOnly(1L, 2L); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertMeasure(1, "U1"); + insertMeasure(2, null); + db.commit(); + + underTest.execute(); + assertThat(idsOfRows()).containsOnly(1L); + + underTest.execute(); + assertThat(idsOfRows()).containsOnly(1L); + } + + private void insertMeasure(long id, @Nullable String analysisUuid) { + db.executeInsert( + TABLE_MEASURES, + "ID", valueOf(id), + "SNAPSHOT_ID", valueOf(id + 10), + "METRIC_ID", valueOf(id + 100), + "VALUE", valueOf(id + 200), + "COMPONENT_UUID", valueOf(id + 300), + "ANALYSIS_UUID", analysisUuid); + } + + private List idsOfRows() { + return db.select("select ID from project_measures").stream().map(map -> (Long) map.get("ID")).collect(Collectors.toList()); + } +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnMeasuresTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnMeasuresTest.java new file mode 100644 index 00000000000..1c6089bbc4c --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnMeasuresTest.java @@ -0,0 +1,89 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import java.sql.Types; +import javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +import static java.lang.String.valueOf; + + +public class MakeAnalysisUuidNotNullOnMeasuresTest { + + private static final String TABLE_MEASURES = "project_measures"; + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, MakeAnalysisUuidNotNullOnMeasuresTest.class, + "in_progress_measures.sql"); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private MakeAnalysisUuidNotNullOnMeasures underTest = new MakeAnalysisUuidNotNullOnMeasures(db.database()); + + @Test + public void migration_makes_analysis_uuid_not_nullable_on_empty_table() throws SQLException { + underTest.execute(); + + verifyColumnDefinitions(); + } + + @Test + public void migration_makes_analysis_uuid_not_nullable_on_populated_table() throws SQLException { + insertMeasure(1, "U1"); + insertMeasure(2, "U2"); + + underTest.execute(); + + verifyColumnDefinitions(); + } + + @Test + public void migration_fails_if_some_uuid_columns_are_null() throws SQLException { + insertMeasure(2, null); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Fail to execute"); + + underTest.execute(); + } + + private void insertMeasure(long id, @Nullable String analysisUuid) { + db.executeInsert( + TABLE_MEASURES, + "ID", valueOf(id), + "SNAPSHOT_ID", valueOf(id + 10), + "METRIC_ID", valueOf(id + 100), + "VALUE", valueOf(id + 200), + "COMPONENT_UUID", valueOf(id + 300), + "ANALYSIS_UUID", analysisUuid); + } + + private void verifyColumnDefinitions() { + db.assertColumnDefinition(TABLE_MEASURES, "analysis_uuid", Types.VARCHAR, 50, false); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateAnalysisUuidOnMeasuresTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateAnalysisUuidOnMeasuresTest.java new file mode 100644 index 00000000000..54c6c68d2f6 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateAnalysisUuidOnMeasuresTest.java @@ -0,0 +1,107 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import java.util.Map; +import javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +import static java.lang.String.valueOf; +import static org.assertj.core.api.Assertions.assertThat; + +public class PopulateAnalysisUuidOnMeasuresTest { + + private static final String TABLE_MEASURES = "project_measures"; + private static final String TABLE_SNAPSHOTS = "snapshots"; + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, PopulateAnalysisUuidOnMeasuresTest.class, + "old_measures.sql"); + + private PopulateAnalysisUuidOnMeasures underTest = new PopulateAnalysisUuidOnMeasures(db.database()); + + @Test + public void migration_has_no_effect_on_empty_tables() throws SQLException { + underTest.execute(); + + assertThat(db.countRowsOfTable(TABLE_MEASURES)).isEqualTo(0); + } + + @Test + public void migration_populates_analysis_uuids() throws SQLException { + insertSnapshot(1, "U1", Qualifiers.PROJECT, 1); + insertSnapshot(2, "U2", Qualifiers.DIRECTORY, 1); + insertSnapshot(3, "U3", Qualifiers.FILE, 1); + insertMeasure(21, 1); + insertMeasure(22, 2); + insertMeasure(23, 3); + db.commit(); + + underTest.execute(); + + verifyAnalysisUuid(21, "U1"); + verifyAnalysisUuid(22, "U1"); + verifyAnalysisUuid(23, "U1"); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertSnapshot(1, "U1", Qualifiers.PROJECT, 1); + insertMeasure(21, 1); + + underTest.execute(); + verifyAnalysisUuid(21, "U1"); + + underTest.execute(); + verifyAnalysisUuid(21, "U1"); + } + + private void verifyAnalysisUuid(int measureId, @Nullable String expectedAnalysisUuid) { + Map rows = db.selectFirst("select analysis_uuid as \"analysisUuid\" from project_measures where id=" + measureId); + assertThat(rows.get("analysisUuid")).isEqualTo(expectedAnalysisUuid); + } + + private String insertSnapshot(long id, String uuid, String qualifier, long rootSnapshotId) { + db.executeInsert( + TABLE_SNAPSHOTS, + "ID", valueOf(id), + "UUID", uuid, + "COMPONENT_UUID", valueOf(id + 10), + "ROOT_COMPONENT_UUID", valueOf(id + 10), + "ROOT_SNAPSHOT_ID", valueOf(rootSnapshotId), + "QUALIFIER", qualifier); + return uuid; + } + + private void insertMeasure(long id, long snapshotId) { + db.executeInsert( + TABLE_MEASURES, + "ID", valueOf(id), + "SNAPSHOT_ID", valueOf(snapshotId), + "METRIC_ID", valueOf(id + 100), + "VALUE", valueOf(id + 200), + "COMPONENT_UUID", valueOf(id + 300)); + } +} diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml index e2080221686..2072fa6c6a3 100644 --- a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml @@ -2,6 +2,7 @@ @@ -144,6 +145,7 @@ VALUE="80" METRIC_ID="2" SNAPSHOT_ID="1000" + analysis_uuid="u1000" person_id="[null]" component_uuid="ABCD"/> @@ -152,6 +154,7 @@ VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1001" + analysis_uuid="u1000" person_id="[null]" component_uuid="BCDE"/> @@ -159,6 +162,7 @@ VALUE="70" METRIC_ID="2" SNAPSHOT_ID="1001" + analysis_uuid="u1000" person_id="[null]" component_uuid="BCDE"/> @@ -167,6 +171,7 @@ VALUE="5" METRIC_ID="1" SNAPSHOT_ID="1002" + analysis_uuid="u1000" person_id="[null]" component_uuid="CDEF"/> @@ -174,6 +179,7 @@ VALUE="60" METRIC_ID="2" SNAPSHOT_ID="1002" + analysis_uuid="u1000" person_id="[null]" component_uuid="CDEF"/> diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml index 90bae067103..260f36f3c49 100644 --- a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml @@ -44,6 +44,7 @@ VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" + analysis_uuid="u1000" person_id="[null]" component_uuid="ABCD"/> @@ -51,6 +52,7 @@ VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" + analysis_uuid="u1000" person_id="20" component_uuid="ABCD"/> @@ -58,6 +60,7 @@ VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" + analysis_uuid="u1000" person_id="21" component_uuid="ABCD"/> diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/select_by_snapshot_and_metric_keys.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/select_by_snapshot_and_metric_keys.xml index 8c287369351..bdd864aa9ee 100644 --- a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/select_by_snapshot_and_metric_keys.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/select_by_snapshot_and_metric_keys.xml @@ -22,6 +22,7 @@ -