Search in sources :

Example 6 with DefaultInputProject

use of org.sonar.api.batch.fs.internal.DefaultInputProject in project sonarqube by SonarSource.

the class DefaultSensorStorageTest method prepare.

@Before
public void prepare() throws Exception {
    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
    when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
    when(metricFinder.<Integer>findByKey(CoreMetrics.LINES_TO_COVER_KEY)).thenReturn(CoreMetrics.LINES_TO_COVER);
    settings = new MapSettings();
    moduleIssues = mock(IssuePublisher.class);
    reportPublisher = mock(ReportPublisher.class);
    final File reportDir = temp.newFolder();
    reportWriter = new ScannerReportWriter(reportDir);
    reportReader = new ScannerReportReader(reportDir);
    when(reportPublisher.getWriter()).thenReturn(reportWriter);
    when(reportPublisher.getReader()).thenReturn(reportReader);
    branchConfiguration = mock(BranchConfiguration.class);
    underTest = new DefaultSensorStorage(metricFinder, moduleIssues, settings.asConfig(), reportPublisher, mock(SonarCpdBlockIndex.class), contextPropertiesCache, new ScannerMetrics(), branchConfiguration);
    project = new DefaultInputProject(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
}
Also used : BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) MetricFinder(org.sonar.api.batch.measure.MetricFinder) ScannerMetrics(org.sonar.core.metric.ScannerMetrics) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) ReportPublisher(org.sonar.scanner.report.ReportPublisher) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) MapSettings(org.sonar.api.config.internal.MapSettings) IssuePublisher(org.sonar.scanner.issue.IssuePublisher) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Before(org.junit.Before)

Example 7 with DefaultInputProject

use of org.sonar.api.batch.fs.internal.DefaultInputProject in project sonarqube by SonarSource.

the class ModuleInputComponentStoreTest method setUp.

@Before
public void setUp() throws IOException {
    DefaultInputProject root = TestInputFileBuilder.newDefaultInputProject(projectKey, temp.newFolder());
    componentStore = new InputComponentStore(mock(BranchConfiguration.class), mock(SonarRuntime.class));
}
Also used : DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) Before(org.junit.Before)

Example 8 with DefaultInputProject

use of org.sonar.api.batch.fs.internal.DefaultInputProject in project sonarqube by SonarSource.

the class InputComponentStoreTest method should_add_input_file.

@Test
public void should_add_input_file() throws Exception {
    String rootModuleKey = "struts";
    String subModuleKey = "struts-core";
    File rootBaseDir = temp.newFolder();
    ProjectDefinition moduleDef = ProjectDefinition.create().setKey(subModuleKey).setBaseDir(rootBaseDir).setWorkDir(temp.newFolder());
    ProjectDefinition rootDef = ProjectDefinition.create().setKey(rootModuleKey).setBaseDir(rootBaseDir).setWorkDir(temp.newFolder()).addSubProject(moduleDef);
    DefaultInputProject rootProject = TestInputFileBuilder.newDefaultInputProject(rootDef);
    DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(moduleDef);
    InputComponentStore store = new InputComponentStore(mock(BranchConfiguration.class), sonarRuntime);
    store.put(subModule);
    DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java").setModuleBaseDir(rootBaseDir.toPath()).setPublish(true).build();
    store.put(rootProject.key(), fooFile);
    store.put(subModuleKey, new TestInputFileBuilder(rootModuleKey, "src/main/java/Bar.java").setLanguage("bla").setPublish(false).setType(Type.MAIN).setStatus(Status.ADDED).setLines(2).setCharset(StandardCharsets.UTF_8).setModuleBaseDir(temp.newFolder().toPath()).build());
    DefaultInputFile loadedFile = (DefaultInputFile) store.getFile(subModuleKey, "src/main/java/Bar.java");
    assertThat(loadedFile.relativePath()).isEqualTo("src/main/java/Bar.java");
    assertThat(loadedFile.charset()).isEqualTo(StandardCharsets.UTF_8);
    assertThat(store.filesByModule(rootModuleKey)).hasSize(1);
    assertThat(store.filesByModule(subModuleKey)).hasSize(1);
    assertThat(store.inputFiles()).hasSize(2);
    for (InputPath inputPath : store.inputFiles()) {
        assertThat(inputPath.relativePath()).startsWith("src/main/java/");
    }
    List<InputFile> toPublish = new LinkedList<>();
    store.allFilesToPublish().forEach(toPublish::add);
    assertThat(toPublish).containsExactly(fooFile);
}
Also used : BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) InputPath(org.sonar.api.batch.fs.InputPath) LinkedList(java.util.LinkedList) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 9 with DefaultInputProject

use of org.sonar.api.batch.fs.internal.DefaultInputProject in project sonarqube by SonarSource.

the class ComponentsPublisherTest method add_components_to_report.

@Test
public void add_components_to_report() throws Exception {
    ProjectInfo projectInfo = mock(ProjectInfo.class);
    when(projectInfo.getAnalysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
    ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0").setName("Root project").setDescription("Root description").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder());
    DefaultInputProject project = new DefaultInputProject(rootDef, 1);
    InputComponentStore store = new InputComponentStore(branchConfiguration, sonarRuntime);
    Path moduleBaseDir = temp.newFolder().toPath();
    ProjectDefinition module1Def = ProjectDefinition.create().setKey("module1").setName("Module1").setDescription("Module description").setBaseDir(moduleBaseDir.toFile()).setWorkDir(temp.newFolder());
    rootDef.addSubProject(module1Def);
    DefaultInputFile file = new TestInputFileBuilder("foo", "module1/src/Foo.java", 4).setLines(2).setStatus(InputFile.Status.SAME).build();
    store.put("module1", file);
    DefaultInputFile file18 = new TestInputFileBuilder("foo", "module1/src2/Foo.java", 18).setLines(2).setStatus(InputFile.Status.SAME).build();
    store.put("module1", file18);
    DefaultInputFile file2 = new TestInputFileBuilder("foo", "module1/src/Foo2.java", 5).setPublish(false).setLines(2).build();
    store.put("module1", file2);
    DefaultInputFile fileWithoutLang = new TestInputFileBuilder("foo", "module1/src/make", 6).setLines(10).setStatus(InputFile.Status.CHANGED).build();
    store.put("module1", fileWithoutLang);
    DefaultInputFile testFile = new TestInputFileBuilder("foo", "module1/test/FooTest.java", 7).setType(Type.TEST).setStatus(InputFile.Status.ADDED).setLines(4).build();
    store.put("module1", testFile);
    ComponentsPublisher publisher = new ComponentsPublisher(project, store);
    publisher.publish(writer);
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 4)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 7)).isTrue();
    // not marked for publishing
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 5)).isFalse();
    // no such reference
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 8)).isFalse();
    ScannerReportReader reader = new ScannerReportReader(outputDir);
    Component rootProtobuf = reader.readComponent(1);
    assertThat(rootProtobuf.getKey()).isEqualTo("foo");
    assertThat(rootProtobuf.getDescription()).isEqualTo("Root description");
    assertThat(rootProtobuf.getLinkCount()).isZero();
    assertThat(reader.readComponent(4).getStatus()).isEqualTo(FileStatus.SAME);
    assertThat(reader.readComponent(6).getStatus()).isEqualTo(FileStatus.CHANGED);
    assertThat(reader.readComponent(7).getStatus()).isEqualTo(FileStatus.ADDED);
}
Also used : Path(java.nio.file.Path) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) ProjectInfo(org.sonar.scanner.ProjectInfo) Component(org.sonar.scanner.protocol.output.ScannerReport.Component) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 10 with DefaultInputProject

use of org.sonar.api.batch.fs.internal.DefaultInputProject in project sonarqube by SonarSource.

the class ComponentsPublisherTest method publish_project_with_links.

@Test
public void publish_project_with_links() throws Exception {
    ProjectInfo projectInfo = mock(ProjectInfo.class);
    when(projectInfo.getAnalysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
    ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0").setName("Root project").setProperty(CoreProperties.LINKS_HOME_PAGE, "http://home").setProperty(CoreProperties.LINKS_CI, "http://ci").setDescription("Root description").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder());
    DefaultInputProject project = new DefaultInputProject(rootDef, 1);
    InputComponentStore store = new InputComponentStore(branchConfiguration, sonarRuntime);
    ComponentsPublisher publisher = new ComponentsPublisher(project, store);
    publisher.publish(writer);
    ScannerReportReader reader = new ScannerReportReader(outputDir);
    Component rootProtobuf = reader.readComponent(1);
    assertThat(rootProtobuf.getLinkCount()).isEqualTo(2);
    assertThat(rootProtobuf.getLink(0).getType()).isEqualTo(ComponentLinkType.HOME);
    assertThat(rootProtobuf.getLink(0).getHref()).isEqualTo("http://home");
    assertThat(rootProtobuf.getLink(1).getType()).isEqualTo(ComponentLinkType.CI);
    assertThat(rootProtobuf.getLink(1).getHref()).isEqualTo("http://ci");
}
Also used : ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) ProjectInfo(org.sonar.scanner.ProjectInfo) Component(org.sonar.scanner.protocol.output.ScannerReport.Component) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Aggregations

DefaultInputProject (org.sonar.api.batch.fs.internal.DefaultInputProject)14 Test (org.junit.Test)8 File (java.io.File)7 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)7 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)6 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)6 Before (org.junit.Before)5 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)5 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)4 ProjectInfo (org.sonar.scanner.ProjectInfo)4 AbstractProjectOrModule (org.sonar.api.batch.fs.internal.AbstractProjectOrModule)3 Component (org.sonar.scanner.protocol.output.ScannerReport.Component)3 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)3 BranchConfiguration (org.sonar.scanner.scan.branch.BranchConfiguration)3 Path (java.nio.file.Path)2 InputFile (org.sonar.api.batch.fs.InputFile)2 LinkedList (java.util.LinkedList)1 SonarRuntime (org.sonar.api.SonarRuntime)1 InputPath (org.sonar.api.batch.fs.InputPath)1 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)1