diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-01-25 15:16:02 +0100 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2017-01-27 16:26:30 +0100 |
commit | f3741d7e1fd83961c038f71338f986f35a22720d (patch) | |
tree | 774e23ac0a9253c19c526c6d36bf548b0bffc0e1 | |
parent | 976e8639cf83e476f46d03db90d12763620091cb (diff) | |
download | sonarqube-f3741d7e1fd83961c038f71338f986f35a22720d.tar.gz sonarqube-f3741d7e1fd83961c038f71338f986f35a22720d.zip |
SONAR-8701 Store number of lines of files in compute engine Component
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 885500e7f8e..dc2b3cfc8e7 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 @@ public class ComponentRootBuilder { 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 43e6101220a..a096500c92c 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.CheckForNull; 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 class FileAttributes { 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 1d8c0065519..e9d745e50c1 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 class ComponentImplTest { @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 class ComponentImplTest { @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 bae25d17483..7a39a042ccc 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.Map; 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; @@ -69,6 +70,9 @@ public class ComponentRootBuilderTest { private static final String DEFAULT_VERSION = "not provided"; @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Rule public ScannerComponentProvider scannerComponentProvider = new ScannerComponentProvider(); private ComponentRootBuilder underTest = new ComponentRootBuilder(NO_BRANCH, SIMPLE_UUID_GENERATOR, scannerComponentProvider, NO_COMPONENT_DTO_FOR_PROJECT, NO_BASEANALYSIS); @@ -139,7 +143,7 @@ public class ComponentRootBuilderTest { 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 class ComponentRootBuilderTest { 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 class ComponentRootBuilderTest { 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 class ComponentRootBuilderTest { 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<Integer, Component> componentsByRef = indexComponentByRef(root); @@ -337,7 +341,7 @@ public class ComponentRootBuilderTest { 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<Integer, Component> componentByRef = indexComponentByRef(root); @@ -353,7 +357,7 @@ public class ComponentRootBuilderTest { 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<Integer, Component> componentByRef = indexComponentByRef(root); @@ -368,7 +372,7 @@ public class ComponentRootBuilderTest { 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<Integer, Component> componentByRef = indexComponentByRef(root); @@ -383,7 +387,7 @@ public class ComponentRootBuilderTest { 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<Integer, Component> componentByRef = indexComponentByRef(root); @@ -466,18 +470,37 @@ public class ComponentRootBuilderTest { @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<Integer, ScannerReport.Component> { 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 cbf9e99fd90..64023bd0ad2 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 @@ import static java.util.Arrays.asList; */ 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 b14e16a393b..ababe9d888b 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.Collection; 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 class IntegrateCrossProjectDuplicationsTest { 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<Block> 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 bacf258de62..fc482f87de2 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.measures.CoreMetrics; 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 24abda535fe..3ad2a27b42d 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 java.util.Collection; 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 class CommonRuleEngineImplTest { 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<DefaultIssue> 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 3a3a602f335..e6caaed3a05 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.measures.CoreMetrics; 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 @@ import static org.sonar.server.computation.task.projectanalysis.component.Report 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 be3ec0acd4e..013acccfc21 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.measures.CoreMetrics; 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 9768a74597e..3a8d5daa7c0 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.measures.CoreMetrics; 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 c34ed0400bf..4ea1147c4a7 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.measures.CoreMetrics; 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 53acf238294..3ef1c1325a2 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 class MaintainabilityMeasuresVisitorTest { 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 @@ public class MaintainabilityMeasuresVisitorTest { } 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 d54cbeda58b..a0fb67083e3 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 class NewMaintainabilityMeasuresVisitorTest { 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 class NewMaintainabilityMeasuresVisitorTest { .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 class NewMaintainabilityMeasuresVisitorTest { 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 class NewMaintainabilityMeasuresVisitorTest { .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 class NewMaintainabilityMeasuresVisitorTest { .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 @@ public class NewMaintainabilityMeasuresVisitorTest { 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 dce6308ddfc..1d962c7d637 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 8ba41fd9195..8265141fa06 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 bc3b215048c..2afbc48248d 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 com.google.common.collect.Lists; 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 @@ public class LastCommitVisitorTest { } 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 31b21bd4233..3185ba9ccbd 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 @@ public class BuildComponentTreeStepTest { 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 afe20a5db7a..7e343fd64d6 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 e2ba981ab2f..e45b7e4af4a 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.db.duplication.DuplicationUnitDto; 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 f23b3e4bf23..3f0cb7fc1de 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; 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 class PersistTestsStepTest extends BaseStepTest { 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 1b076aa63a7..09e3c1a7d26 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 class ReportCoverageMeasuresStepTest { 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 d07c3ac8993..b689a252b89 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 @@ package org.sonar.server.computation.task.projectanalysis.step; 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 class ReportLanguageDistributionMeasuresStepTest { .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 aa09a74d46f..e2e75ae45c9 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 class ReportNewCoverageMeasuresStepTest { @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 class ReportNewCoverageMeasuresStepTest { @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 ecb1ec7253e..f3aae8bc576 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 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { 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 class ReportPersistComponentsStepTest extends BaseStepTest { .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 a6f08ac2361..1317341dd7c 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 javax.annotation.Nullable; 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 7260260f283..59206e1d520 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 @@ package org.sonar.server.computation.task.projectanalysis.step; 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 01a9cc7ead8..0bfdff21c15 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; |