diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-11-25 11:39:03 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-11-25 11:39:41 +0100 |
commit | 36d3e10c63ac339321cd4e1b6ae3efebdd5c4d9c (patch) | |
tree | 940dfe2df77877075061d0541a70dd02246d5f3f /sonar-batch | |
parent | b03036b4ddc0ed7cf42c26433450ddbf8e56a1a3 (diff) | |
download | sonarqube-36d3e10c63ac339321cd4e1b6ae3efebdd5c4d9c.tar.gz sonarqube-36d3e10c63ac339321cd4e1b6ae3efebdd5c4d9c.zip |
SONAR-5866 Add coverage data into file_sources table + migration
Diffstat (limited to 'sonar-batch')
5 files changed, 29 insertions, 17 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java index d2d27beb498..13b644577f8 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java @@ -194,13 +194,18 @@ public class SourcePersister implements ScanPersister { Map<Integer, String> authorsByLine = getLineMetric(file, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY); Map<Integer, String> revisionsByLine = getLineMetric(file, CoreMetrics.SCM_REVISIONS_BY_LINE_KEY); Map<Integer, String> datesByLine = getLineMetric(file, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY); + Map<Integer, String> hitsByLine = getLineMetric(file, CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY); + Map<Integer, String> condByLine = getLineMetric(file, CoreMetrics.CONDITIONS_BY_LINE_KEY); + Map<Integer, String> coveredCondByLine = getLineMetric(file, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY); SyntaxHighlightingData highlighting = loadHighlighting(file); String[] highlightingPerLine = computeHighlightingPerLine(file, highlighting); ByteArrayOutputStream output = new ByteArrayOutputStream(); CsvWriter csv = CsvWriter.of(new OutputStreamWriter(output, UTF_8)); for (int lineIdx = 1; lineIdx <= file.lines(); lineIdx++) { - csv.values(revisionsByLine.get(lineIdx), authorsByLine.get(lineIdx), datesByLine.get(lineIdx), highlightingPerLine[lineIdx - 1], + csv.values(revisionsByLine.get(lineIdx), authorsByLine.get(lineIdx), datesByLine.get(lineIdx), + hitsByLine.get(lineIdx), condByLine.get(lineIdx), coveredCondByLine.get(lineIdx), + highlightingPerLine[lineIdx - 1], CharMatcher.anyOf(BOM).removeFrom(lines.get(lineIdx - 1))); } csv.close(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java index 7452dc2995e..b2fde847b13 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java @@ -112,7 +112,8 @@ public class SourcePersisterTest extends AbstractDaoTestCase { String relativePathSame = "src/same.java"; java.io.File sameFile = new java.io.File(basedir, relativePathSame); FileUtils.write(sameFile, "unchanged\ncontent"); - DefaultInputFile inputFileNew = new DefaultInputFile(PROJECT_KEY, relativePathSame).setLines(2).setAbsolutePath(sameFile.getAbsolutePath()); + DefaultInputFile inputFileNew = new DefaultInputFile(PROJECT_KEY, relativePathSame).setLines(2).setAbsolutePath(sameFile.getAbsolutePath()) + .setLineHashes(new String[] {"foo", "bar"}); when(inputPathCache.all()).thenReturn(Arrays.<InputPath>asList(inputFileNew)); mockResourceCache(relativePathSame, PROJECT_KEY, "uuidsame"); @@ -143,9 +144,9 @@ public class SourcePersisterTest extends AbstractDaoTestCase { assertThat(fileSourceDto.getCreatedAt()).isEqualTo(DateUtils.parseDateTime("2014-10-10T16:44:02+0200").getTime()); assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now.getTime()); assertThat(fileSourceDto.getData()).isEqualTo( - ",,,,changed\r\n,,,,content\r\n"); + ",,,,,,,changed\r\n,,,,,,,content\r\n"); assertThat(fileSourceDto.getLineHashes()).isEqualTo("foo\nbar"); - assertThat(fileSourceDto.getDataHash()).isEqualTo("e41cca9c51ff853c748f708f39dfc035"); + assertThat(fileSourceDto.getDataHash()).isEqualTo("54f7fa51128a7ee577a476974c56568c"); } @Test @@ -187,14 +188,14 @@ public class SourcePersisterTest extends AbstractDaoTestCase { assertThat(fileSourceDto.getCreatedAt()).isEqualTo(now.getTime()); assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now.getTime()); assertThat(fileSourceDto.getData()).isEqualTo( - ",,,,foo\r\n,,,,bar\r\n,,,,biz\r\n"); + ",,,,,,,foo\r\n,,,,,,,bar\r\n,,,,,,,biz\r\n"); assertThat(fileSourceDto.getLineHashes()).isEqualTo("foo\nbar\nbee"); - assertThat(fileSourceDto.getDataHash()).isEqualTo("0c43ed6418d690ee0ffc3e43e6660967"); + assertThat(fileSourceDto.getDataHash()).isEqualTo("419c2b162018f6bbeb04fc0500d7852d"); } @Test - public void testPersistNewFileWithScmAndHighlighting() throws Exception { + public void testPersistNewFileWithScmAndCoverageAndHighlighting() throws Exception { setupData("file_sources"); Date now = DateUtils.parseDateTime("2014-10-29T16:44:02+0100"); when(system2.newDate()).thenReturn(now); @@ -217,6 +218,12 @@ public class SourcePersisterTest extends AbstractDaoTestCase { .thenReturn(Arrays.asList(new Measure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE, "1=2014-10-11T16:44:02+0100;2=2014-10-12T16:44:02+0100;3=2014-10-13T16:44:02+0100"))); when(measureCache.byMetric(PROJECT_KEY + ":" + relativePathNew, CoreMetrics.SCM_REVISIONS_BY_LINE_KEY)) .thenReturn(Arrays.asList(new Measure(CoreMetrics.SCM_REVISIONS_BY_LINE, "1=123;2=234;3=345"))); + when(measureCache.byMetric(PROJECT_KEY + ":" + relativePathNew, CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY)) + .thenReturn(Arrays.asList(new Measure(CoreMetrics.COVERAGE_LINE_HITS_DATA, "1=1;3=0"))); + when(measureCache.byMetric(PROJECT_KEY + ":" + relativePathNew, CoreMetrics.CONDITIONS_BY_LINE_KEY)) + .thenReturn(Arrays.asList(new Measure(CoreMetrics.CONDITIONS_BY_LINE, "1=4"))); + when(measureCache.byMetric(PROJECT_KEY + ":" + relativePathNew, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY)) + .thenReturn(Arrays.asList(new Measure(CoreMetrics.COVERED_CONDITIONS_BY_LINE, "1=2"))); SyntaxHighlightingData highlighting = new SyntaxHighlightingDataBuilder() .registerHighlightingRule(0, 3, TypeOfText.ANNOTATION) @@ -233,10 +240,10 @@ public class SourcePersisterTest extends AbstractDaoTestCase { assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now.getTime()); assertThat(fileSourceDto.getLineHashes()).isEqualTo("foo\nbar\nbee"); assertThat(fileSourceDto.getData()).isEqualTo( - "123,julien,2014-10-11T16:44:02+0100,\"0,3,a\",foo\r\n" - + "234,simon,2014-10-12T16:44:02+0100,\"0,1,cd\",bar\r\n" - + "345,julien,2014-10-13T16:44:02+0100,\"0,9,c\",biz\r\n"); - assertThat(fileSourceDto.getDataHash()).isEqualTo("a2aaee165e33957a67331fb9f869e0f1"); + "123,julien,2014-10-11T16:44:02+0100,1,4,2,\"0,3,a\",foo\r\n" + + "234,simon,2014-10-12T16:44:02+0100,,,,\"0,1,cd\",bar\r\n" + + "345,julien,2014-10-13T16:44:02+0100,0,,,\"0,9,c\",biz\r\n"); + assertThat(fileSourceDto.getDataHash()).isEqualTo("66cf8a9176f59672044663f48a19989c"); } @Test diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/file_sources.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/file_sources.xml index a4e8ed467b3..027ae4be0ae 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/file_sources.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/file_sources.xml @@ -1,8 +1,8 @@ <dataset> <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame" - data=",,,,unchanged ,,,,content " + data=",,,,,,,unchanged ,,,,,,,content " line_hashes="8d7b3d6b83c0a517eac07e1aac94b773 9a0364b9e99bb480dd25e1f0284c8555" - data_hash="ee716d4ed9faae16eb9167714442a3bc" + data_hash="5de921a62f62af2ba05afe1cfe067f31" created_at="1412952242000" updated_at="1412952242000" /> </dataset> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistDontTouchUnchanged-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistDontTouchUnchanged-result.xml index 98dd81f73df..5c26c579b79 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistDontTouchUnchanged-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistDontTouchUnchanged-result.xml @@ -1,9 +1,9 @@ <dataset> <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame" - data=",,,,unchanged ,,,,content " + data=",,,,,,,unchanged ,,,,,,,content " line_hashes="8d7b3d6b83c0a517eac07e1aac94b773 9a0364b9e99bb480dd25e1f0284c8555" - data_hash="ee716d4ed9faae16eb9167714442a3bc" + data_hash="5de921a62f62af2ba05afe1cfe067f31" created_at="1412952242000" updated_at="1412952242000" /> </dataset> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistEmptyFile-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistEmptyFile-result.xml index cd844a149d8..8ba809e7ed7 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistEmptyFile-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/testPersistEmptyFile-result.xml @@ -1,8 +1,8 @@ <dataset> <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame" - data=",,,,unchanged ,,,,content " + data=",,,,,,,unchanged ,,,,,,,content " line_hashes="8d7b3d6b83c0a517eac07e1aac94b773 9a0364b9e99bb480dd25e1f0284c8555" - data_hash="ee716d4ed9faae16eb9167714442a3bc" + data_hash="5de921a62f62af2ba05afe1cfe067f31" created_at="1412952242000" updated_at="1412952242000" /> <file_sources id="102" project_uuid="projectUuid" file_uuid="uuidempty" data="[null]" |