Search in sources :

Example 21 with DefaultInputModule

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

the class LocalIssueTracking method loadSourceHashes.

@CheckForNull
private SourceHashHolder loadSourceHashes(InputComponent component) {
    SourceHashHolder sourceHashHolder = null;
    if (component.isFile()) {
        DefaultInputModule module = (DefaultInputModule) componentTree.getParent(componentTree.getParent(component));
        DefaultInputFile file = (DefaultInputFile) component;
        sourceHashHolder = new SourceHashHolder(module, file, lastLineHashes);
    }
    return sourceHashHolder;
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) CheckForNull(javax.annotation.CheckForNull)

Example 22 with DefaultInputModule

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

the class DefaultInputModuleHierarchy method relativePath.

@Override
@CheckForNull
public String relativePath(InputModule module) {
    DefaultInputModule parent = parent(module);
    if (parent == null) {
        return null;
    }
    DefaultInputModule inputModule = (DefaultInputModule) module;
    ProjectDefinition parentDefinition = parent.definition();
    Path parentBaseDir = parentDefinition.getBaseDir().toPath();
    ProjectDefinition moduleDefinition = inputModule.definition();
    Path moduleBaseDir = moduleDefinition.getBaseDir().toPath();
    return pathResolver.relativePath(parentBaseDir, moduleBaseDir);
}
Also used : Path(java.nio.file.Path) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) CheckForNull(javax.annotation.CheckForNull)

Example 23 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 24 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 25 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)

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