Search in sources :

Example 26 with DefaultInputModule

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

the class IssuableFactoryTest method project_should_be_issuable.

@Test
public void project_should_be_issuable() {
    IssuableFactory factory = new IssuableFactory(mock(DefaultSensorContext.class));
    Issuable issuable = factory.loadPerspective(Issuable.class, new DefaultInputModule("foo"));
    assertThat(issuable).isNotNull();
    assertThat(issuable.issues()).isEmpty();
}
Also used : DefaultSensorContext(org.sonar.scanner.sensor.DefaultSensorContext) Issuable(org.sonar.api.issue.Issuable) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Test(org.junit.Test)

Example 27 with DefaultInputModule

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

the class ComponentsPublisherTest method add_components_to_report.

@Test
public void add_components_to_report() throws Exception {
    ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
    when(projectAnalysisInfo.analysisDate()).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");
    DefaultInputModule root = new DefaultInputModule(rootDef, 1);
    ProjectDefinition module1Def = ProjectDefinition.create().setKey("module1").setName("Module1").setDescription("Module description");
    rootDef.addSubProject(module1Def);
    DefaultInputModule module1 = new DefaultInputModule(module1Def, 2);
    moduleHierarchy = mock(InputModuleHierarchy.class);
    when(moduleHierarchy.root()).thenReturn(root);
    when(moduleHierarchy.children(root)).thenReturn(Collections.singleton(module1));
    tree.index(module1, root);
    DefaultInputDir dir = new DefaultInputDir("module1", "src", 3);
    tree.index(dir, module1);
    DefaultInputFile file = new TestInputFileBuilder("module1", "src/Foo.java", 4).setLines(2).build();
    tree.index(file, dir);
    DefaultInputFile file2 = new TestInputFileBuilder("module1", "src/Foo2.java", 5).setPublish(false).setLines(2).build();
    tree.index(file2, dir);
    DefaultInputFile fileWithoutLang = new TestInputFileBuilder("module1", "src/make", 6).setLines(10).build();
    tree.index(fileWithoutLang, dir);
    DefaultInputFile testFile = new TestInputFileBuilder("module1", "test/FooTest.java", 7).setType(Type.TEST).setLines(4).build();
    tree.index(testFile, dir);
    ComponentsPublisher publisher = new ComponentsPublisher(moduleHierarchy, tree);
    publisher.publish(writer);
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 2)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 3)).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.getVersion()).isEqualTo("1.0");
    assertThat(rootProtobuf.getLinkCount()).isEqualTo(0);
    Component module1Protobuf = reader.readComponent(2);
    assertThat(module1Protobuf.getKey()).isEqualTo("module1");
    assertThat(module1Protobuf.getDescription()).isEqualTo("Module description");
    assertThat(module1Protobuf.getVersion()).isEqualTo("1.0");
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) InputModuleHierarchy(org.sonar.api.batch.fs.internal.InputModuleHierarchy) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectAnalysisInfo(org.sonar.scanner.ProjectAnalysisInfo) ComponentsPublisher(org.sonar.scanner.report.ComponentsPublisher) Component(org.sonar.scanner.protocol.output.ScannerReport.Component) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 28 with DefaultInputModule

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

the class MetadataPublisherTest method prepare.

@Before
public void prepare() {
    projectDef = ProjectDefinition.create().setKey("foo");
    rootModule = new DefaultInputModule(projectDef, TestInputFileBuilder.nextBatchId());
    projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
    when(projectAnalysisInfo.analysisDate()).thenReturn(new Date(1234567L));
    inputModuleHierarchy = mock(InputModuleHierarchy.class);
    when(inputModuleHierarchy.root()).thenReturn(rootModule);
    settings = new MapSettings();
    qProfiles = mock(ModuleQProfiles.class);
    underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings, qProfiles);
}
Also used : InputModuleHierarchy(org.sonar.api.batch.fs.internal.InputModuleHierarchy) MapSettings(org.sonar.api.config.MapSettings) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectAnalysisInfo(org.sonar.scanner.ProjectAnalysisInfo) Date(java.util.Date) ModuleQProfiles(org.sonar.scanner.rule.ModuleQProfiles) Before(org.junit.Before)

Example 29 with DefaultInputModule

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

the class DefaultSensorStorageTest method shouldSaveProjectMeasureToSensorContext.

@Test
public void shouldSaveProjectMeasureToSensorContext() {
    String projectKey = "myProject";
    DefaultInputModule module = new DefaultInputModule(projectKey);
    ArgumentCaptor<DefaultMeasure> argumentCaptor = ArgumentCaptor.forClass(DefaultMeasure.class);
    when(measureCache.put(eq(module.key()), eq(CoreMetrics.NCLOC_KEY), argumentCaptor.capture())).thenReturn(null);
    underTest.store(new DefaultMeasure().on(module).forMetric(CoreMetrics.NCLOC).withValue(10));
    DefaultMeasure m = argumentCaptor.getValue();
    assertThat(m.value()).isEqualTo(10);
    assertThat(m.metric()).isEqualTo(CoreMetrics.NCLOC);
}
Also used : DefaultMeasure(org.sonar.api.batch.sensor.measure.internal.DefaultMeasure) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Test(org.junit.Test)

Example 30 with DefaultInputModule

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

the class InputComponentStoreTest method should_add_input_file.

@Test
public void should_add_input_file() throws Exception {
    InputComponentStore cache = new InputComponentStore(new PathResolver());
    String rootModuleKey = "struts";
    File rootBaseDir = temp.newFolder();
    DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootModuleKey, rootBaseDir);
    cache.put(rootModule);
    String subModuleKey = "struts-core";
    DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(subModuleKey, temp.newFolder());
    rootModule.definition().addSubProject(subModule.definition());
    cache.put(subModule);
    DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java").setModuleBaseDir(rootBaseDir.toPath()).setPublish(true).build();
    cache.put(fooFile);
    cache.put(new TestInputFileBuilder(subModuleKey, "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) cache.getFile(subModuleKey, "src/main/java/Bar.java");
    assertThat(loadedFile.relativePath()).isEqualTo("src/main/java/Bar.java");
    assertThat(loadedFile.charset()).isEqualTo(StandardCharsets.UTF_8);
    assertThat(cache.filesByModule(rootModuleKey)).hasSize(1);
    assertThat(cache.filesByModule(subModuleKey)).hasSize(1);
    assertThat(cache.allFiles()).hasSize(2);
    for (InputPath inputPath : cache.allFiles()) {
        assertThat(inputPath.relativePath()).startsWith("src/main/java/");
    }
    List<InputFile> toPublish = new LinkedList<>();
    cache.allFilesToPublish().forEach(toPublish::add);
    assertThat(toPublish).containsExactly(fooFile);
    cache.remove(fooFile);
    assertThat(cache.allFiles()).hasSize(1);
    cache.removeModule(rootModuleKey);
    assertThat(cache.filesByModule(rootModuleKey)).hasSize(0);
    assertThat(cache.filesByModule(subModuleKey)).hasSize(1);
    assertThat(cache.allFiles()).hasSize(1);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputPath(org.sonar.api.batch.fs.InputPath) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) PathResolver(org.sonar.api.scan.filesystem.PathResolver) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) LinkedList(java.util.LinkedList) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Aggregations

DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)32 Test (org.junit.Test)19 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)9 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)9 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)8 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)7 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)6 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)6 InputFile (org.sonar.api.batch.fs.InputFile)5 Before (org.junit.Before)4 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)4 CheckForNull (javax.annotation.CheckForNull)3 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)3 PathResolver (org.sonar.api.scan.filesystem.PathResolver)3 Component (org.sonar.scanner.protocol.output.ScannerReport.Component)3 ComponentsPublisher (org.sonar.scanner.report.ComponentsPublisher)3 File (java.io.File)2 AnalysisMode (org.sonar.api.batch.AnalysisMode)2 InputComponent (org.sonar.api.batch.fs.InputComponent)2 InputDir (org.sonar.api.batch.fs.InputDir)2