Search in sources :

Example 6 with DefaultInputDir

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

the class FileIndexer method indexParentDir.

private void indexParentDir(DefaultModuleFileSystem fileSystem, InputFile inputFile) {
    Path parentDir = inputFile.path().getParent();
    String relativePath = new PathResolver().relativePath(fileSystem.baseDirPath(), parentDir);
    if (relativePath == null) {
        throw new IllegalStateException("Failed to compute relative path of file: " + inputFile);
    }
    DefaultInputDir inputDir = (DefaultInputDir) componentStore.getDir(module.key(), relativePath);
    if (inputDir == null) {
        inputDir = new DefaultInputDir(fileSystem.moduleKey(), relativePath, batchIdGenerator.get());
        inputDir.setModuleBaseDir(fileSystem.baseDirPath());
        fileSystem.add(inputDir);
        componentTree.index(inputDir, module);
    }
    componentTree.index(inputFile, inputDir);
}
Also used : Path(java.nio.file.Path) PathResolver(org.sonar.api.scan.filesystem.PathResolver) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir)

Example 7 with DefaultInputDir

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

the class InputComponentStore method remove.

public InputComponentStore remove(InputDir inputDir) {
    DefaultInputDir dir = (DefaultInputDir) inputDir;
    inputDirCache.remove(dir.moduleKey(), inputDir.relativePath());
    return this;
}
Also used : DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir)

Example 8 with DefaultInputDir

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

the class InputComponentStore method put.

public InputComponentStore put(InputDir inputDir) {
    DefaultInputDir dir = (DefaultInputDir) inputDir;
    inputDirCache.put(dir.moduleKey(), inputDir.relativePath(), inputDir);
    globalInputDirCache.put(getProjectRelativePath(dir), inputDir);
    inputComponents.put(inputDir.key(), inputDir);
    return this;
}
Also used : DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir)

Example 9 with DefaultInputDir

use of org.sonar.api.batch.fs.internal.DefaultInputDir 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 10 with DefaultInputDir

use of org.sonar.api.batch.fs.internal.DefaultInputDir 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)

Aggregations

DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)10 Test (org.junit.Test)6 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)6 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)6 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)5 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)5 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)4 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)4 ComponentsPublisher (org.sonar.scanner.report.ComponentsPublisher)4 Component (org.sonar.scanner.protocol.output.ScannerReport.Component)3 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)3 InputFile (org.sonar.api.batch.fs.InputFile)2 PathResolver (org.sonar.api.scan.filesystem.PathResolver)2 File (java.io.File)1 Path (java.nio.file.Path)1 Before (org.junit.Before)1 InputDir (org.sonar.api.batch.fs.InputDir)1 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)1 RulesBuilder (org.sonar.api.batch.rule.internal.RulesBuilder)1 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)1