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);
}
}
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));
}
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));
}
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;
}
Aggregations