Search in sources :

Example 36 with DefaultInputModule

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

the class ModuleIndexer method createChildren.

private void createChildren(DefaultInputModule parent) {
    for (ProjectDefinition def : parent.definition().getSubProjects()) {
        DefaultInputModule child = new DefaultInputModule(def, batchIdGenerator.get());
        moduleHierarchy.index(child, parent);
        componentTree.index(child, parent);
        componentStore.put(child);
        createChildren(child);
    }
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 37 with DefaultInputModule

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

the class DefaultIndexTest method shouldGetHierarchy.

@Test
public void shouldGetHierarchy() {
    InputComponent component = new DefaultInputModule("module1");
    InputFile file1 = new TestInputFileBuilder("module1", "src/org/foo/Bar.java").build();
    when(componentStore.getByKey("module1")).thenReturn(component);
    when(componentStore.getByKey("module1:src/org/foo/Bar.java")).thenReturn(file1);
    when(componentTree.getParent(file1)).thenReturn(component);
    when(componentTree.getChildren(component)).thenReturn(Collections.singleton(file1));
    assertThat(index.getParent("module1:src/org/foo/Bar.java").getKey()).isEqualTo("module1");
    assertThat(index.getParent("module1")).isNull();
    assertThat(index.getChildren("module1")).containsOnly(File.create("src/org/foo/Bar.java"));
    assertThat(index.getChildren("module1:src/org/foo/Bar.java")).isEmpty();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputComponent(org.sonar.api.batch.fs.InputComponent) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 38 with DefaultInputModule

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

the class DefaultIndexTest method shouldTransformToResource.

@Test
public void shouldTransformToResource() {
    DefaultInputModule component = new DefaultInputModule(ProjectDefinition.create().setKey("module1").setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "branch1"), 1);
    InputFile file1 = new TestInputFileBuilder("module1", "src/org/foo/Bar.java").build();
    InputDir dir = new DefaultInputDir("module1", "src");
    assertThat(index.toResource(component)).isInstanceOf(Project.class);
    assertThat(index.toResource(component).getKey()).isEqualTo("module1");
    assertThat(index.toResource(component).getEffectiveKey()).isEqualTo("module1:branch1");
    assertThat(index.toResource(file1)).isInstanceOf(File.class);
    assertThat(index.toResource(file1).getKey()).isEqualTo("src/org/foo/Bar.java");
    assertThat(index.toResource(file1).getPath()).isEqualTo("src/org/foo/Bar.java");
    assertThat(index.toResource(dir)).isInstanceOf(Directory.class);
    assertThat(index.toResource(dir).getKey()).isEqualTo("src");
    assertThat(index.toResource(dir).getPath()).isEqualTo("src");
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) InputDir(org.sonar.api.batch.fs.InputDir) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 39 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 40 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)

Aggregations

DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)57 Test (org.junit.Test)34 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)17 File (java.io.File)9 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)9 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)9 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)8 Path (java.nio.file.Path)6 InputFile (org.sonar.api.batch.fs.InputFile)6 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)6 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)5 Before (org.junit.Before)4 InputComponent (org.sonar.api.batch.fs.InputComponent)4 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)4 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)4 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)4 CheckForNull (javax.annotation.CheckForNull)3 InputDir (org.sonar.api.batch.fs.InputDir)3 DefaultInputComponent (org.sonar.api.batch.fs.internal.DefaultInputComponent)3 InputModuleHierarchy (org.sonar.scanner.fs.InputModuleHierarchy)3