From f3741d7e1fd83961c038f71338f986f35a22720d Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 25 Jan 2017 15:16:02 +0100 Subject: [PATCH] SONAR-8701 Store number of lines of files in compute engine Component --- .../component/ComponentRootBuilder.java | 3 +- .../component/FileAttributes.java | 12 +++- .../component/ComponentImplTest.java | 4 +- .../component/ComponentRootBuilderTest.java | 61 +++++++++++++------ .../component/ReportComponent.java | 2 +- ...IntegrateCrossProjectDuplicationsTest.java | 6 +- .../commonrule/CommentDensityRuleTest.java | 6 +- .../commonrule/CommonRuleEngineImplTest.java | 6 +- .../issue/commonrule/CoverageRuleTest.java | 6 +- .../commonrule/DuplicatedBlockRuleTest.java | 6 +- .../issue/commonrule/SkippedTestRuleTest.java | 6 +- .../issue/commonrule/TestErrorRuleTest.java | 6 +- .../MaintainabilityMeasuresVisitorTest.java | 8 +-- ...NewMaintainabilityMeasuresVisitorTest.java | 12 ++-- ...yAndSecurityRatingMeasuresVisitorTest.java | 4 +- ...yAndSecurityRatingMeasuresVisitorTest.java | 4 +- .../source/LastCommitVisitorTest.java | 4 +- .../step/BuildComponentTreeStepTest.java | 3 +- .../step/ComputeQProfileMeasureStepTest.java | 8 +-- ...ProjectDuplicationsRepositoryStepTest.java | 6 +- .../step/PersistTestsStepTest.java | 6 +- .../step/ReportCoverageMeasuresStepTest.java | 2 +- ...tLanguageDistributionMeasuresStepTest.java | 10 +-- .../ReportNewCoverageMeasuresStepTest.java | 6 +- .../step/ReportPersistComponentsStepTest.java | 4 +- .../step/ReportSizeMeasuresStepTest.java | 6 +- .../step/ReportUnitTestMeasuresStepTest.java | 6 +- .../src/main/protobuf/scanner_report.proto | 2 +- 28 files changed, 125 insertions(+), 90 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ComponentRootBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ComponentRootBuilder.java index 885500e7f8e6..dc2b3cfc8e7b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ComponentRootBuilder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ComponentRootBuilder.java @@ -191,7 +191,8 @@ static FileAttributes createFileAttributes(ScannerReport.Component component) { return new FileAttributes( component.getIsTest(), - trimToNull(component.getLanguage())); + trimToNull(component.getLanguage()), + component.getLines()); } @VisibleForTesting diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/FileAttributes.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/FileAttributes.java index 43e6101220a7..a096500c92ce 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/FileAttributes.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/FileAttributes.java @@ -23,6 +23,8 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import static com.google.common.base.Preconditions.checkArgument; + /** * The attributes specific to a Component of type {@link org.sonar.server.computation.task.projectanalysis.component.Component.Type#FILE}. */ @@ -31,10 +33,13 @@ public class FileAttributes { private final boolean unitTest; @CheckForNull private final String languageKey; + private final int lines; - public FileAttributes(boolean unitTest, @Nullable String languageKey) { + public FileAttributes(boolean unitTest, @Nullable String languageKey, int lines) { this.unitTest = unitTest; this.languageKey = languageKey; + checkArgument(lines > 0, "Lines has not been set for this file"); + this.lines = lines; } public boolean isUnitTest() { @@ -46,11 +51,16 @@ public String getLanguageKey() { return languageKey; } + public int getLines() { + return lines; + } + @Override public String toString() { return "FileAttributes{" + "languageKey='" + languageKey + '\'' + ", unitTest=" + unitTest + + ", lines=" + lines + '}'; } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ComponentImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ComponentImplTest.java index 1d8c00655195..e9d745e50c16 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ComponentImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ComponentImplTest.java @@ -105,7 +105,7 @@ public void getFileAttributes_throws_ISE_if_BatchComponent_does_not_have_type_FI @Test public void isUnitTest_returns_true_if_IsTest_is_set_in_BatchComponent() { - ComponentImpl component = buildSimpleComponent(FILE, "file").setFileAttributes(new FileAttributes(true, null)).build(); + ComponentImpl component = buildSimpleComponent(FILE, "file").setFileAttributes(new FileAttributes(true, null, 1)).build(); assertThat(component.getFileAttributes().isUnitTest()).isTrue(); } @@ -113,7 +113,7 @@ public void isUnitTest_returns_true_if_IsTest_is_set_in_BatchComponent() { @Test public void isUnitTest_returns_value_of_language_of_BatchComponent() { String languageKey = "some language key"; - ComponentImpl component = buildSimpleComponent(FILE, "file").setFileAttributes(new FileAttributes(false, languageKey)).build(); + ComponentImpl component = buildSimpleComponent(FILE, "file").setFileAttributes(new FileAttributes(false, languageKey, 1)).build(); assertThat(component.getFileAttributes().getLanguageKey()).isEqualTo(languageKey); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ComponentRootBuilderTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ComponentRootBuilderTest.java index bae25d174830..7a39a042ccc5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ComponentRootBuilderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ComponentRootBuilderTest.java @@ -28,6 +28,7 @@ import java.util.function.Function; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.rules.ExternalResource; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; @@ -68,6 +69,9 @@ public class ComponentRootBuilderTest { private static final String PROJECT_UUID = "project uuid"; private static final String DEFAULT_VERSION = "not provided"; + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @Rule public ScannerComponentProvider scannerComponentProvider = new ScannerComponentProvider(); @@ -139,7 +143,7 @@ public void name_of_module_directory_and_file_contains_branch_when_non_empty() { ScannerReport.Component project = newBuilder().setType(PROJECT).setRef(1).addChildRef(2).build(); scannerComponentProvider.add(newBuilder().setRef(2).setType(MODULE).setKey(MODULE_KEY).addChildRef(3)); scannerComponentProvider.add(newBuilder().setRef(3).setType(DIRECTORY).setPath(DIRECTORY_PATH).addChildRef(4)); - scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setPath(FILE_PATH)); + scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setPath(FILE_PATH).setLines(1)); String branch = "BRANCH"; ComponentRootBuilder builder = new ComponentRootBuilder(branch, SIMPLE_UUID_GENERATOR, scannerComponentProvider, NO_COMPONENT_DTO_FOR_PROJECT, NO_BASEANALYSIS); @@ -163,7 +167,7 @@ public void name_of_module_directory_and_file_is_key_of_Scanner_Component_when_n ScannerReport.Component project = newBuilder().setType(PROJECT).setRef(1).addChildRef(2).build(); scannerComponentProvider.add(newBuilder().setRef(2).setType(MODULE).setKey(MODULE_KEY).addChildRef(3)); scannerComponentProvider.add(newBuilder().setRef(3).setType(DIRECTORY).setPath(DIRECTORY_PATH).addChildRef(4)); - scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setPath(FILE_PATH)); + scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setPath(FILE_PATH).setLines(1)); Component root = underTest.build(project, PROJECT_KEY); assertThat(root.getKey()).isEqualTo(PROJECT_KEY); @@ -180,7 +184,7 @@ public void name_of_module_directory_and_file_is_key_of_Scanner_Component_when_n ScannerReport.Component project = newBuilder().setType(PROJECT).setRef(1).setName("").addChildRef(2).build(); scannerComponentProvider.add(newBuilder().setRef(2).setType(MODULE).setKey(MODULE_KEY).setName("").addChildRef(3)); scannerComponentProvider.add(newBuilder().setRef(3).setType(DIRECTORY).setPath(DIRECTORY_PATH).setName("").addChildRef(4)); - scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setPath(FILE_PATH).setName("")); + scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setPath(FILE_PATH).setName("").setLines(1)); Component root = underTest.build(project, PROJECT_KEY); assertThat(root.getKey()).isEqualTo(PROJECT_KEY); @@ -202,14 +206,14 @@ public void name_of_module_directory_and_files_includes_name_of_closest_module() scannerComponentProvider.add(newBuilder().setRef(22).setType(DIRECTORY).setPath("directory in module 1").addChildRef(36)); scannerComponentProvider.add(newBuilder().setRef(23).setType(DIRECTORY).setPath("directory in module 2").addChildRef(37)); scannerComponentProvider.add(newBuilder().setRef(24).setType(DIRECTORY).setPath("directory in module 3").addChildRef(38)); - scannerComponentProvider.add(newBuilder().setRef(31).setType(FILE).setPath("file in project")); - scannerComponentProvider.add(newBuilder().setRef(32).setType(FILE).setPath("file in module 1")); - scannerComponentProvider.add(newBuilder().setRef(33).setType(FILE).setPath("file in module 2")); - scannerComponentProvider.add(newBuilder().setRef(34).setType(FILE).setPath("file in module 3")); - scannerComponentProvider.add(newBuilder().setRef(35).setType(FILE).setPath("file in directory in project")); - scannerComponentProvider.add(newBuilder().setRef(36).setType(FILE).setPath("file in directory in module 1")); - scannerComponentProvider.add(newBuilder().setRef(37).setType(FILE).setPath("file in directory in module 2")); - scannerComponentProvider.add(newBuilder().setRef(38).setType(FILE).setPath("file in directory in module 3")); + scannerComponentProvider.add(newBuilder().setRef(31).setType(FILE).setPath("file in project").setLines(1)); + scannerComponentProvider.add(newBuilder().setRef(32).setType(FILE).setPath("file in module 1").setLines(1)); + scannerComponentProvider.add(newBuilder().setRef(33).setType(FILE).setPath("file in module 2").setLines(1)); + scannerComponentProvider.add(newBuilder().setRef(34).setType(FILE).setPath("file in module 3").setLines(1)); + scannerComponentProvider.add(newBuilder().setRef(35).setType(FILE).setPath("file in directory in project").setLines(1)); + scannerComponentProvider.add(newBuilder().setRef(36).setType(FILE).setPath("file in directory in module 1").setLines(1)); + scannerComponentProvider.add(newBuilder().setRef(37).setType(FILE).setPath("file in directory in module 2").setLines(1)); + scannerComponentProvider.add(newBuilder().setRef(38).setType(FILE).setPath("file in directory in module 3").setLines(1)); Component root = underTest.build(project, PROJECT_KEY); Map componentsByRef = indexComponentByRef(root); @@ -337,7 +341,7 @@ public void uuid_is_value_from_uuid_supplier_for_project_module_directory_and_fi ScannerReport.Component project = newBuilder().setType(PROJECT).setRef(1).addChildRef(2).build(); scannerComponentProvider.add(newBuilder().setRef(2).setType(MODULE).setKey(MODULE_KEY).addChildRef(3)); scannerComponentProvider.add(newBuilder().setRef(3).setType(DIRECTORY).setPath(DIRECTORY_PATH).addChildRef(4)); - scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setPath(FILE_PATH)); + scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setPath(FILE_PATH).setLines(1)); Component root = underTest.build(project, PROJECT_KEY); Map componentByRef = indexComponentByRef(root); @@ -353,7 +357,7 @@ public void description_of_project_module_directory_and_file_is_null_when_unset_ ScannerReport.Component project = newBuilder().setType(PROJECT).setRef(1).addChildRef(2).build(); scannerComponentProvider.add(newBuilder().setRef(2).setType(MODULE).addChildRef(3)); scannerComponentProvider.add(newBuilder().setRef(3).setType(DIRECTORY).addChildRef(4)); - scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE)); + scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setLines(1)); Component root = underTest.build(project, PROJECT_KEY); Map componentByRef = indexComponentByRef(root); @@ -368,7 +372,7 @@ public void description_of_project_module_directory_and_file_is_null_when_empty_ ScannerReport.Component project = newBuilder().setType(PROJECT).setRef(1).setDescription("").addChildRef(2).build(); scannerComponentProvider.add(newBuilder().setRef(2).setType(MODULE).setDescription("").addChildRef(3)); scannerComponentProvider.add(newBuilder().setRef(3).setType(DIRECTORY).setDescription("").addChildRef(4)); - scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setDescription("")); + scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setLines(1).setDescription("")); Component root = underTest.build(project, PROJECT_KEY); Map componentByRef = indexComponentByRef(root); @@ -383,7 +387,7 @@ public void description_of_project_module_directory_and_file_is_description_of_S ScannerReport.Component project = newBuilder().setType(PROJECT).setRef(1).setDescription("desc of project").addChildRef(2).build(); scannerComponentProvider.add(newBuilder().setRef(2).setType(MODULE).setDescription("desc of module").addChildRef(3)); scannerComponentProvider.add(newBuilder().setRef(3).setType(DIRECTORY).setDescription("desc of directory").addChildRef(4)); - scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setDescription("desc of file")); + scannerComponentProvider.add(newBuilder().setRef(4).setType(FILE).setLines(1).setDescription("desc of file")); Component root = underTest.build(project, PROJECT_KEY); Map componentByRef = indexComponentByRef(root); @@ -466,18 +470,37 @@ public void createFileAttributes_returns_null_when_type_is_not_FILE() { @Test public void createFileAttributes_sets_language_to_null_when_unset_in_Scanner_Component() { - assertThat(createFileAttributes(newBuilder().setType(FILE).build()).getLanguageKey()).isNull(); + assertThat(createFileAttributes(newBuilder().setType(FILE).setLines(1).build()).getLanguageKey()).isNull(); } @Test public void createFileAttributes_sets_language_to_null_when_empty_in_Scanner_Component() { - assertThat(createFileAttributes(newBuilder().setType(FILE).setLanguage("").build()).getLanguageKey()).isNull(); + assertThat(createFileAttributes(newBuilder().setType(FILE).setLanguage("").setLines(1).build()).getLanguageKey()).isNull(); } @Test public void createFileAttributes_sets_unitTest_from_Scanner_Component() { - assertThat(createFileAttributes(newBuilder().setType(FILE).build()).isUnitTest()).isFalse(); - assertThat(createFileAttributes(newBuilder().setType(FILE).setIsTest(true).build()).isUnitTest()).isTrue(); + assertThat(createFileAttributes(newBuilder().setType(FILE).setLines(1).build()).isUnitTest()).isFalse(); + assertThat(createFileAttributes(newBuilder().setType(FILE).setIsTest(true).setLines(1).build()).isUnitTest()).isTrue(); + } + + @Test + public void createFileAttributes_sets_lines_in_Scanner_Component() { + assertThat(createFileAttributes(newBuilder().setType(FILE).setLines(10).build()).getLines()).isEqualTo(10); + } + + @Test + public void fail_with_IAE_when_createFileAttributes_sets_lines_to_0() throws Exception { + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Lines has not been set for this file"); + createFileAttributes(newBuilder().setType(FILE).setLines(0).build()); + } + + @Test + public void fail_with_IAE_when_createFileAttributes_lines_is_not_set() throws Exception { + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Lines has not been set for this file"); + createFileAttributes(newBuilder().setType(FILE).build()); } private static class ScannerComponentProvider extends ExternalResource implements Function { diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ReportComponent.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ReportComponent.java index cbf9e99fd90a..64023bd0ad2e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ReportComponent.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ReportComponent.java @@ -35,7 +35,7 @@ */ public class ReportComponent implements Component { - private static final FileAttributes DEFAULT_FILE_ATTRIBUTES = new FileAttributes(false, null); + private static final FileAttributes DEFAULT_FILE_ATTRIBUTES = new FileAttributes(false, null, 1); public static final Component DUMB_PROJECT = builder(Type.PROJECT, 1).setKey("PROJECT_KEY").setUuid("PROJECT_UUID").setName("Project Name").setVersion("1.0-SNAPSHOT").build(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java index b14e16a393bf..ababe9d888bd 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java @@ -25,8 +25,8 @@ import java.util.Collections; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.config.Settings; import org.sonar.api.config.MapSettings; +import org.sonar.api.config.Settings; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.duplications.block.Block; @@ -54,7 +54,7 @@ public class IntegrateCrossProjectDuplicationsTest { static final String ORIGIN_FILE_KEY = "ORIGIN_FILE_KEY"; static final Component ORIGIN_FILE = builder(FILE, 1) .setKey(ORIGIN_FILE_KEY) - .setFileAttributes(new FileAttributes(false, XOO_LANGUAGE)) + .setFileAttributes(new FileAttributes(false, XOO_LANGUAGE, 1)) .build(); static final String OTHER_FILE_KEY = "OTHER_FILE_KEY"; @@ -226,7 +226,7 @@ public void add_no_duplication_when_no_duplicated_blocks() { public void add_duplication_for_java_even_when_no_token() { Component javaFile = builder(FILE, 1) .setKey(ORIGIN_FILE_KEY) - .setFileAttributes(new FileAttributes(false, "java")) + .setFileAttributes(new FileAttributes(false, "java", 10)) .build(); Collection originBlocks = singletonList( diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CommentDensityRuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CommentDensityRuleTest.java index bacf258de624..fc482f87de22 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CommentDensityRuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CommentDensityRuleTest.java @@ -27,10 +27,10 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import org.sonar.core.issue.DefaultIssue; -import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.Component; -import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; import org.sonar.server.computation.task.projectanalysis.component.FileAttributes; +import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; +import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule; @@ -46,7 +46,7 @@ public class CommentDensityRuleTest { static RuleKey RULE_KEY = RuleKey.of(CommonRuleKeys.commonRepositoryForLang("java"), CommonRuleKeys.INSUFFICIENT_COMMENT_DENSITY); static ReportComponent FILE = ReportComponent.builder(Component.Type.FILE, 1) - .setFileAttributes(new FileAttributes(false, "java")) + .setFileAttributes(new FileAttributes(false, "java", 1)) .build(); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CommonRuleEngineImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CommonRuleEngineImplTest.java index 24abda535fe2..3ad2a27b42dd 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CommonRuleEngineImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CommonRuleEngineImplTest.java @@ -23,8 +23,8 @@ import org.junit.Test; import org.sonar.core.issue.DefaultIssue; import org.sonar.server.computation.task.projectanalysis.component.Component; -import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; import org.sonar.server.computation.task.projectanalysis.component.FileAttributes; +import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -42,7 +42,7 @@ public class CommonRuleEngineImplTest { public void process_files_with_known_language() throws Exception { ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1) .setKey("FILE_KEY").setUuid("FILE_UUID") - .setFileAttributes(new FileAttributes(false, "java")) + .setFileAttributes(new FileAttributes(false, "java", 1)) .build(); DefaultIssue issue = new DefaultIssue(); when(rule1.processFile(file, "java")).thenReturn(issue); @@ -56,7 +56,7 @@ public void process_files_with_known_language() throws Exception { public void do_not_process_files_with_unknown_language() throws Exception { ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1) .setKey("FILE_KEY").setUuid("FILE_UUID") - .setFileAttributes(new FileAttributes(false, null)) + .setFileAttributes(new FileAttributes(false, null, 1)) .build(); Collection issues = underTest.process(file); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CoverageRuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CoverageRuleTest.java index 3a3a602f3351..e6caaed3a056 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CoverageRuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CoverageRuleTest.java @@ -27,10 +27,10 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import org.sonar.core.issue.DefaultIssue; -import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.Component; -import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; import org.sonar.server.computation.task.projectanalysis.component.FileAttributes; +import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; +import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule; @@ -43,7 +43,7 @@ public abstract class CoverageRuleTest { static ReportComponent FILE = ReportComponent.builder(Component.Type.FILE, 1) - .setFileAttributes(new FileAttributes(false, "java")) + .setFileAttributes(new FileAttributes(false, "java", 1)) .build(); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/DuplicatedBlockRuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/DuplicatedBlockRuleTest.java index be3ec0acd4eb..013acccfc21d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/DuplicatedBlockRuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/DuplicatedBlockRuleTest.java @@ -26,10 +26,10 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import org.sonar.core.issue.DefaultIssue; -import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.Component; -import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; import org.sonar.server.computation.task.projectanalysis.component.FileAttributes; +import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; +import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule; @@ -45,7 +45,7 @@ public class DuplicatedBlockRuleTest { static RuleKey RULE_KEY = RuleKey.of(CommonRuleKeys.commonRepositoryForLang("java"), CommonRuleKeys.DUPLICATED_BLOCKS); static ReportComponent FILE = ReportComponent.builder(Component.Type.FILE, 1) - .setFileAttributes(new FileAttributes(false, "java")) + .setFileAttributes(new FileAttributes(false, "java", 1)) .build(); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/SkippedTestRuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/SkippedTestRuleTest.java index 9768a74597ef..3a8d5daa7c05 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/SkippedTestRuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/SkippedTestRuleTest.java @@ -26,10 +26,10 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import org.sonar.core.issue.DefaultIssue; -import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.Component; -import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; import org.sonar.server.computation.task.projectanalysis.component.FileAttributes; +import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; +import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule; @@ -45,7 +45,7 @@ public class SkippedTestRuleTest { static RuleKey RULE_KEY = RuleKey.of(CommonRuleKeys.commonRepositoryForLang("java"), CommonRuleKeys.SKIPPED_UNIT_TESTS); static ReportComponent FILE = ReportComponent.builder(Component.Type.FILE, 1) - .setFileAttributes(new FileAttributes(true, "java")) + .setFileAttributes(new FileAttributes(true, "java", 1)) .setName("FooTest.java") .build(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/TestErrorRuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/TestErrorRuleTest.java index c34ed0400bf9..4ea1147c4a78 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/TestErrorRuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/TestErrorRuleTest.java @@ -26,10 +26,10 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import org.sonar.core.issue.DefaultIssue; -import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.Component; -import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; import org.sonar.server.computation.task.projectanalysis.component.FileAttributes; +import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; +import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule; @@ -45,7 +45,7 @@ public class TestErrorRuleTest { static RuleKey RULE_KEY = RuleKey.of(CommonRuleKeys.commonRepositoryForLang("java"), CommonRuleKeys.FAILED_UNIT_TESTS); static ReportComponent FILE = ReportComponent.builder(Component.Type.FILE, 1) - .setFileAttributes(new FileAttributes(true, "java")) + .setFileAttributes(new FileAttributes(true, "java", 1)) .setName("FooTest.java") .build(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitorTest.java index 53acf238294a..3ef1c1325a23 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitorTest.java @@ -83,8 +83,8 @@ public class MaintainabilityMeasuresVisitorTest { .addChildren( builder(DIRECTORY, DIRECTORY_REF).setKey("directory") .addChildren( - builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1)).setKey("file1").build(), - builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1)).setKey("file2").build()) + builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file1").build(), + builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file2").build()) .build()) .build()) .build(); @@ -147,7 +147,7 @@ public void compute_development_cost() { createFileComponent(LANGUAGE_KEY_1, 1111), createFileComponent(LANGUAGE_KEY_2, 1112), // Unit test should not be ignored - builder(FILE, 1113).setFileAttributes(new FileAttributes(true, LANGUAGE_KEY_1)).build()) + builder(FILE, 1113).setFileAttributes(new FileAttributes(true, LANGUAGE_KEY_1, 1)).build()) .build(), builder(DIRECTORY, 112) .addChildren( @@ -358,7 +358,7 @@ private void verifyAddedRawMeasure(int componentRef, String metricKey, String va } private static ReportComponent createFileComponent(String languageKey1, int fileRef) { - return builder(FILE, fileRef).setFileAttributes(new FileAttributes(false, languageKey1)).build(); + return builder(FILE, fileRef).setFileAttributes(new FileAttributes(false, languageKey1, 1)).build(); } private static Measure createMaintainabilityRatingMeasure(Rating rating) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java index d54cbeda58be..a0fb67083e31 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java @@ -145,7 +145,7 @@ public void file_has_0_new_debt_ratio_if_all_scm_dates_are_before_snapshot_dates treeRootHolder.setRoot( builder(PROJECT, ROOT_REF) .addChildren( - builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY)).build()) + builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build()) .build()); measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50, 12)); measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4)); @@ -298,7 +298,7 @@ public void leaf_components_always_have_a_measure_when_at_least_one_period_exist .addChildren( builder(DIRECTORY, 111) .addChildren( - builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY)).build()) + builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build()) .build()) .build()) .build()); @@ -340,7 +340,7 @@ public void new_debt_ratio_is_computed_for_five_periods() throws Exception { treeRootHolder.setRoot( builder(PROJECT, ROOT_REF) - .addChildren(builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY)).build()) + .addChildren(builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build()) .build()); Measure newDebtMeasure = newMeasureBuilder().setVariations(new MeasureVariations(500d, 500d, 500d, 120d, 120d)).createNoValue(); @@ -374,7 +374,7 @@ public void compute_new_maintainability_rating() throws Exception { .addChildren( builder(DIRECTORY, 111) .addChildren( - builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY)).build()) + builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build()) .build()) .build()) .build()); @@ -408,7 +408,7 @@ public void compute_new_maintainability_rating_to_A_when_no_debt() throws Except .addChildren( builder(DIRECTORY, 111) .addChildren( - builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY)).build()) + builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build()) .build()) .build()) .build()); @@ -429,7 +429,7 @@ private void setupOneFileAloneInAProject(int newDebtPeriod2, int newDebtPeriod4, treeRootHolder.setRoot( builder(PROJECT, ROOT_REF) .addChildren( - builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(isUnitTest == Flag.UT_FILE, LANGUAGE_1_KEY)).build()) + builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(isUnitTest == Flag.UT_FILE, LANGUAGE_1_KEY, 1)).build()) .build()); Measure newDebtMeasure = createNewDebtMeasure(newDebtPeriod2, newDebtPeriod4); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java index dce6308ddfcb..1d962c7d637f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java @@ -88,8 +88,8 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitorTest { .addChildren( builder(DIRECTORY, DIRECTORY_REF).setKey("directory") .addChildren( - builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1)).setKey("file1").build(), - builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1)).setKey("file2").build()) + builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file1").build(), + builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file2").build()) .build()) .build()) .build(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitorTest.java index 8ba41fd91955..8265141fa061 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitorTest.java @@ -84,8 +84,8 @@ public class ReliabilityAndSecurityRatingMeasuresVisitorTest { .addChildren( builder(DIRECTORY, DIRECTORY_REF).setKey("directory") .addChildren( - builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1)).setKey("file1").build(), - builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1)).setKey("file2").build()) + builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file1").build(), + builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file2").build()) .build()) .build()) .build(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/LastCommitVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/LastCommitVisitorTest.java index bc3b215048c1..2afbc48248dc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/LastCommitVisitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/source/LastCommitVisitorTest.java @@ -24,11 +24,11 @@ import org.junit.Rule; import org.junit.Test; import org.sonar.api.measures.CoreMetrics; -import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.component.ComponentVisitor; import org.sonar.server.computation.task.projectanalysis.component.FileAttributes; import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; +import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.ViewsComponent; import org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler; import org.sonar.server.computation.task.projectanalysis.measure.Measure; @@ -232,6 +232,6 @@ private void assertDate(int componentRef, long expectedDate) { } private ReportComponent createFileComponent(int fileRef) { - return ReportComponent.builder(FILE, fileRef).setFileAttributes(new FileAttributes(false, "js")).build(); + return ReportComponent.builder(FILE, fileRef).setFileAttributes(new FileAttributes(false, "js", 1)).build(); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/BuildComponentTreeStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/BuildComponentTreeStepTest.java index 31b21bd42337..3185ba9ccbd2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/BuildComponentTreeStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/BuildComponentTreeStepTest.java @@ -338,7 +338,8 @@ private static ScannerReport.Component componentWithPath(int componentRef, Compo private static ScannerReport.Component component(int componentRef, ComponentType componentType, @Nullable String key, @Nullable String path, int... children) { ScannerReport.Component.Builder builder = ScannerReport.Component.newBuilder() .setType(componentType) - .setRef(componentRef); + .setRef(componentRef) + .setLines(1); if (key != null) { builder.setKey(key); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ComputeQProfileMeasureStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ComputeQProfileMeasureStepTest.java index afe20a5db7ad..7e343fd64d6f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ComputeQProfileMeasureStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ComputeQProfileMeasureStepTest.java @@ -74,13 +74,13 @@ public class ComputeQProfileMeasureStepTest { ReportComponent.builder(MODULE, SUB_MODULE_REF) .addChildren(ReportComponent.builder(DIRECTORY, FOLDER_1_REF) .addChildren( - ReportComponent.builder(FILE, FILE_1_1_REF).setFileAttributes(new FileAttributes(false, "java")).build(), - ReportComponent.builder(FILE, FILE_1_2_REF).setFileAttributes(new FileAttributes(false, "java")).build()) + ReportComponent.builder(FILE, FILE_1_1_REF).setFileAttributes(new FileAttributes(false, "java", 1)).build(), + ReportComponent.builder(FILE, FILE_1_2_REF).setFileAttributes(new FileAttributes(false, "java", 1)).build()) .build(), ReportComponent.builder(DIRECTORY, FOLDER_2_REF) .addChildren( - ReportComponent.builder(FILE, FILE_2_1_REF).setFileAttributes(new FileAttributes(false, null)).build(), - ReportComponent.builder(FILE, FILE_2_2_REF).setFileAttributes(new FileAttributes(false, "php")).build()) + ReportComponent.builder(FILE, FILE_2_1_REF).setFileAttributes(new FileAttributes(false, null, 1)).build(), + ReportComponent.builder(FILE, FILE_2_2_REF).setFileAttributes(new FileAttributes(false, "php", 1)).build()) .build()) .build()) .build()) diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java index e2ba981ab2fa..e45b7e4af4ac 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java @@ -42,16 +42,16 @@ import org.sonar.duplications.block.Block; import org.sonar.duplications.block.ByteArray; import org.sonar.scanner.protocol.output.ScannerReport; +import org.sonar.server.computation.task.projectanalysis.analysis.Analysis; import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule; import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule; -import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.component.FileAttributes; import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; +import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.duplication.CrossProjectDuplicationStatusHolder; import org.sonar.server.computation.task.projectanalysis.duplication.IntegrateCrossProjectDuplications; import org.sonar.server.computation.task.step.ComputationStep; -import org.sonar.server.computation.task.projectanalysis.analysis.Analysis; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; @@ -76,7 +76,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { static final Component CURRENT_FILE = ReportComponent.builder(FILE, FILE_REF) .setKey(CURRENT_FILE_KEY) - .setFileAttributes(new FileAttributes(false, XOO_LANGUAGE)) + .setFileAttributes(new FileAttributes(false, XOO_LANGUAGE, 1)) .build(); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistTestsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistTestsStepTest.java index f23b3e4bf23f..3f0cb7fc1dec 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistTestsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistTestsStepTest.java @@ -35,10 +35,10 @@ import org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail; import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus; import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule; -import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.component.FileAttributes; import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; +import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.step.ComputationStep; import static org.assertj.core.api.Assertions.assertThat; @@ -87,8 +87,8 @@ public void setup() { root = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).addChildren( ReportComponent.builder(Component.Type.MODULE, 2).setUuid("MODULE_UUID").setKey("MODULE_KEY").addChildren( - ReportComponent.builder(Component.Type.FILE, 3).setUuid(TEST_FILE_UUID_1).setKey("TEST_FILE1_KEY").setFileAttributes(new FileAttributes(true, null)).build(), - ReportComponent.builder(Component.Type.FILE, 4).setUuid(TEST_FILE_UUID_2).setKey("TEST_FILE2_KEY").setFileAttributes(new FileAttributes(true, null)).build(), + ReportComponent.builder(Component.Type.FILE, 3).setUuid(TEST_FILE_UUID_1).setKey("TEST_FILE1_KEY").setFileAttributes(new FileAttributes(true, null, 1)).build(), + ReportComponent.builder(Component.Type.FILE, 4).setUuid(TEST_FILE_UUID_2).setKey("TEST_FILE2_KEY").setFileAttributes(new FileAttributes(true, null, 1)).build(), ReportComponent.builder(Component.Type.FILE, 5).setUuid(MAIN_FILE_UUID_1).setKey("MAIN_FILE1_KEY").build(), ReportComponent.builder(Component.Type.FILE, 6).setUuid(MAIN_FILE_UUID_2).setKey("MAIN_FILE2_KEY").build()).build()) .build(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportCoverageMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportCoverageMeasuresStepTest.java index 1b076aa63a74..09e3c1a7d26d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportCoverageMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportCoverageMeasuresStepTest.java @@ -78,7 +78,7 @@ public void setUp() throws Exception { builder(DIRECTORY, DIRECTORY_REF) .addChildren( builder(FILE, FILE_1_REF).build(), - builder(FILE, UNIT_TEST_FILE_REF).setFileAttributes(new FileAttributes(true, "some language")).build(), + builder(FILE, UNIT_TEST_FILE_REF).setFileAttributes(new FileAttributes(true, "some language", 1)).build(), builder(FILE, FILE_2_REF).build()) .build()) .build()) diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java index d07c3ac89937..b689a252b895 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java @@ -22,8 +22,8 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.FileAttributes; +import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.server.computation.task.step.ComputationStep; @@ -79,10 +79,10 @@ public void setUp() throws Exception { .addChildren( builder(DIRECTORY, DIRECTORY_REF) .addChildren( - builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, XOO_LANGUAGE)).build(), - builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, XOO_LANGUAGE)).build(), - builder(FILE, FILE_3_REF).setFileAttributes(new FileAttributes(false, JAVA_LANGUAGE)).build(), - builder(FILE, FILE_4_REF).setFileAttributes(new FileAttributes(false, null)).build()) + builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, XOO_LANGUAGE, 1)).build(), + builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, XOO_LANGUAGE, 1)).build(), + builder(FILE, FILE_3_REF).setFileAttributes(new FileAttributes(false, JAVA_LANGUAGE, 1)).build(), + builder(FILE, FILE_4_REF).setFileAttributes(new FileAttributes(false, null, 1)).build()) .build()) .build()) .build()) diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportNewCoverageMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportNewCoverageMeasuresStepTest.java index aa09a74d46fc..e2e75ae45c9f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportNewCoverageMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportNewCoverageMeasuresStepTest.java @@ -113,7 +113,7 @@ public class ReportNewCoverageMeasuresStepTest { private NewCoverageMeasuresStep underTest = new NewCoverageMeasuresStep(treeRootHolder, periodsHolder, measureRepository, metricRepository, scmInfoRepository); public static final ReportComponent FILE_COMPONENT = ReportComponent.builder(Component.Type.FILE, FILE_1_REF) - .setFileAttributes(new FileAttributes(false, null)).build(); + .setFileAttributes(new FileAttributes(false, null, 1)).build(); @Before public void setUp() { @@ -151,7 +151,7 @@ public void no_measure_for_DIRECTORY_component() { @Test public void no_measure_for_unit_test_FILE_component() { - treeRootHolder.setRoot(ReportComponent.builder(Component.Type.FILE, FILE_1_REF).setFileAttributes(new FileAttributes(true, null)).build()); + treeRootHolder.setRoot(ReportComponent.builder(Component.Type.FILE, FILE_1_REF).setFileAttributes(new FileAttributes(true, null, 1)).build()); underTest.execute(); @@ -160,7 +160,7 @@ public void no_measure_for_unit_test_FILE_component() { @Test public void no_measures_for_FILE_component_without_code() { - treeRootHolder.setRoot(ReportComponent.builder(Component.Type.FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, null)).build()); + treeRootHolder.setRoot(ReportComponent.builder(Component.Type.FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, null, 1)).build()); underTest.execute(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistComponentsStepTest.java index ecb1ec7253ea..f3aae8bc576d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistComponentsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistComponentsStepTest.java @@ -92,7 +92,7 @@ protected ComputationStep step() { public void persist_components() { Component file = builder(FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java") .setPath("src/main/java/dir/Foo.java") - .setFileAttributes(new FileAttributes(false, "java")) + .setFileAttributes(new FileAttributes(false, "java", 1)) .build(); Component directory = builder(DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir") .setPath("src/main/java/dir") @@ -216,7 +216,7 @@ public void persist_unit_test() { .addChildren( builder(FILE, 3).setUuid("DEFG").setKey(PROJECT_KEY + ":src/test/java/dir/FooTest.java") .setPath("src/test/java/dir/FooTest.java") - .setFileAttributes(new FileAttributes(true, null)) + .setFileAttributes(new FileAttributes(true, null, 1)) .build()) .build()) .build()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportSizeMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportSizeMeasuresStepTest.java index a6f08ac2361a..1317341dd7c0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportSizeMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportSizeMeasuresStepTest.java @@ -23,8 +23,8 @@ import org.junit.Rule; import org.junit.Test; import org.sonar.api.measures.CoreMetrics; -import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.FileAttributes; +import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule; @@ -83,11 +83,11 @@ public class ReportSizeMeasuresStepTest { builder(DIRECTORY, DIRECTORY_2_REF) .addChildren( builder(FILE, FILE_3_REF).build(), - builder(FILE, UNIT_TEST_1_REF).setFileAttributes(new FileAttributes(true, LANGUAGE_DOES_NOT_MATTER_HERE)).build()) + builder(FILE, UNIT_TEST_1_REF).setFileAttributes(new FileAttributes(true, LANGUAGE_DOES_NOT_MATTER_HERE, 1)).build()) .build(), builder(DIRECTORY, DIRECTORY_3_REF) .addChildren( - builder(FILE, UNIT_TEST_2_REF).setFileAttributes(new FileAttributes(true, LANGUAGE_DOES_NOT_MATTER_HERE)).build()) + builder(FILE, UNIT_TEST_2_REF).setFileAttributes(new FileAttributes(true, LANGUAGE_DOES_NOT_MATTER_HERE, 1)).build()) .build()) .build()) .build()) diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java index 7260260f283a..59206e1d5206 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java @@ -22,8 +22,8 @@ import org.assertj.core.data.Offset; import org.junit.Rule; import org.junit.Test; -import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.FileAttributes; +import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.server.computation.task.step.ComputationStep; @@ -73,8 +73,8 @@ public class ReportUnitTestMeasuresStepTest { .addChildren( builder(DIRECTORY, DIRECTORY_REF) .addChildren( - builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(true, null)).build(), - builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(true, null)).build()) + builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(true, null, 1)).build(), + builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(true, null, 1)).build()) .build()) .build()) .build()) diff --git a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto index 01a9cc7ead8e..0bfdff21c152 100644 --- a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto +++ b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto @@ -86,7 +86,7 @@ message Component { // Only available on PROJECT and MODULE types // TODO rename this property -> moduleKey ? string key = 10; - // Only available on FILE type + // Only available on FILE type, should always be at least 1 int32 lines = 11; // Only available on PROJECT and MODULE types string description = 12;