return new FileAttributes(
component.getIsTest(),
- trimToNull(component.getLanguage()));
+ trimToNull(component.getLanguage()),
+ component.getLines());
}
@VisibleForTesting
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}.
*/
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() {
return languageKey;
}
+ public int getLines() {
+ return lines;
+ }
+
@Override
public String toString() {
return "FileAttributes{" +
"languageKey='" + languageKey + '\'' +
", unitTest=" + unitTest +
+ ", lines=" + lines +
'}';
}
}
@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();
}
@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);
}
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;
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();
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);
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);
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);
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);
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);
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);
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);
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);
@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> {
*/
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();
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;
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";
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(
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;
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
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;
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);
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);
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;
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
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;
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
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;
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();
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;
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();
.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();
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(
}
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) {
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));
.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());
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();
.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());
.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());
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);
.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();
.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();
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;
}
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();
}
}
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);
}
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())
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;
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
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;
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();
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())
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;
.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())
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() {
@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();
@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();
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")
.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());
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;
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())
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;
.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())
// 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;