Search in sources :

Example 1 with InputModule

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

the class ComponentsPublisher method writeLinks.

private static void writeLinks(InputComponent c, ScannerReport.Component.Builder builder) {
    if (c instanceof InputModule) {
        DefaultInputModule inputModule = (DefaultInputModule) c;
        ProjectDefinition def = inputModule.definition();
        ComponentLink.Builder linkBuilder = ComponentLink.newBuilder();
        writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_HOME_PAGE, ComponentLinkType.HOME);
        writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_CI, ComponentLinkType.CI);
        writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_ISSUE_TRACKER, ComponentLinkType.ISSUE);
        writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_SOURCES, ComponentLinkType.SCM);
        writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_SOURCES_DEV, ComponentLinkType.SCM_DEV);
    }
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) InputModule(org.sonar.api.batch.fs.InputModule) ComponentLink(org.sonar.scanner.protocol.output.ScannerReport.ComponentLink) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 2 with InputModule

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

the class ModuleInputComponentStoreTest method newModuleInputComponentStore.

private ModuleInputComponentStore newModuleInputComponentStore() {
    InputModule module = mock(InputModule.class);
    when(module.key()).thenReturn("moduleKey");
    return new ModuleInputComponentStore(module, componentStore, mock(SensorStrategy.class));
}
Also used : InputModule(org.sonar.api.batch.fs.InputModule) SensorStrategy(org.sonar.api.batch.fs.internal.SensorStrategy)

Example 3 with InputModule

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

the class ModuleInputComponentStoreTest method should_find_module_components_with_non_global_strategy.

@Test
public void should_find_module_components_with_non_global_strategy() {
    InputComponentStore inputComponentStore = mock(InputComponentStore.class);
    SensorStrategy strategy = new SensorStrategy();
    InputModule module = mock(InputModule.class);
    when(module.key()).thenReturn("foo");
    ModuleInputComponentStore store = new ModuleInputComponentStore(module, inputComponentStore, strategy);
    strategy.setGlobal(false);
    store.inputFiles();
    verify(inputComponentStore).filesByModule("foo");
    String relativePath = "somepath";
    store.inputFile(relativePath);
    verify(inputComponentStore).getFile(any(String.class), eq(relativePath));
    store.languages();
    verify(inputComponentStore).languages(any(String.class));
}
Also used : InputModule(org.sonar.api.batch.fs.InputModule) SensorStrategy(org.sonar.api.batch.fs.internal.SensorStrategy) Test(org.junit.Test)

Example 4 with InputModule

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

the class ComponentsPublisher method recursiveWriteComponent.

/**
   * Writes the tree of components recursively, deep-first. 
   * @return true if component was written (not skipped)
   */
private boolean recursiveWriteComponent(DefaultInputComponent component) {
    Collection<InputComponent> children = componentTree.getChildren(component).stream().filter(c -> recursiveWriteComponent((DefaultInputComponent) c)).collect(Collectors.toList());
    if (shouldSkipComponent(component, children)) {
        return false;
    }
    ScannerReport.Component.Builder builder = ScannerReport.Component.newBuilder();
    // non-null fields
    builder.setRef(component.batchId());
    builder.setType(getType(component));
    // Don't set key on directories and files to save space since it can be deduced from path
    if (component instanceof InputModule) {
        DefaultInputModule inputModule = (DefaultInputModule) component;
        // Here we want key without branch
        builder.setKey(inputModule.key());
        // protocol buffers does not accept null values
        String name = getName(inputModule);
        if (name != null) {
            builder.setName(name);
        }
        String description = getDescription(inputModule);
        if (description != null) {
            builder.setDescription(description);
        }
        writeVersion(inputModule, builder);
    }
    if (component.isFile()) {
        DefaultInputFile file = (DefaultInputFile) component;
        builder.setIsTest(file.type() == InputFile.Type.TEST);
        builder.setLines(file.lines());
        String lang = getLanguageKey(file);
        if (lang != null) {
            builder.setLanguage(lang);
        }
    }
    String path = getPath(component);
    if (path != null) {
        builder.setPath(path);
    }
    for (InputComponent child : children) {
        builder.addChildRef(((DefaultInputComponent) child).batchId());
    }
    writeLinks(component, builder);
    writer.writeComponent(builder.build());
    return true;
}
Also used : DefaultInputComponent(org.sonar.api.batch.fs.internal.DefaultInputComponent) InputFile(org.sonar.api.batch.fs.InputFile) StringUtils(org.apache.commons.lang.StringUtils) InputComponent(org.sonar.api.batch.fs.InputComponent) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) CloseableIterator(org.sonar.core.util.CloseableIterator) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) Collection(java.util.Collection) CoreProperties(org.sonar.api.CoreProperties) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) InputPath(org.sonar.api.batch.fs.InputPath) Collectors(java.util.stream.Collectors) ComponentLinkType(org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLinkType) InputDir(org.sonar.api.batch.fs.InputDir) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) ComponentType(org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType) ComponentLink(org.sonar.scanner.protocol.output.ScannerReport.ComponentLink) Issue(org.sonar.scanner.protocol.output.ScannerReport.Issue) InputModule(org.sonar.api.batch.fs.InputModule) InputModuleHierarchy(org.sonar.api.batch.fs.internal.InputModuleHierarchy) CheckForNull(javax.annotation.CheckForNull) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) InputComponentTree(org.sonar.api.batch.fs.internal.InputComponentTree) DefaultInputComponent(org.sonar.api.batch.fs.internal.DefaultInputComponent) InputComponent(org.sonar.api.batch.fs.InputComponent) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) InputModule(org.sonar.api.batch.fs.InputModule) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) DefaultInputComponent(org.sonar.api.batch.fs.internal.DefaultInputComponent) InputComponent(org.sonar.api.batch.fs.InputComponent)

Aggregations

InputModule (org.sonar.api.batch.fs.InputModule)4 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)2 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)2 SensorStrategy (org.sonar.api.batch.fs.internal.SensorStrategy)2 ComponentLink (org.sonar.scanner.protocol.output.ScannerReport.ComponentLink)2 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 CheckForNull (javax.annotation.CheckForNull)1 StringUtils (org.apache.commons.lang.StringUtils)1 Test (org.junit.Test)1 CoreProperties (org.sonar.api.CoreProperties)1 InputComponent (org.sonar.api.batch.fs.InputComponent)1 InputDir (org.sonar.api.batch.fs.InputDir)1 InputFile (org.sonar.api.batch.fs.InputFile)1 InputPath (org.sonar.api.batch.fs.InputPath)1 DefaultInputComponent (org.sonar.api.batch.fs.internal.DefaultInputComponent)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 InputComponentTree (org.sonar.api.batch.fs.internal.InputComponentTree)1 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)1 CloseableIterator (org.sonar.core.util.CloseableIterator)1