use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class HighlightableBuilderTest method project_should_not_be_highlightable.
@Test
public void project_should_not_be_highlightable() {
HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class), mock(AnalysisMode.class));
Highlightable perspective = builder.loadPerspective(Highlightable.class, new DefaultInputModule("struts"));
assertThat(perspective).isNull();
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class SensorContextTesterTest method testMeasures.
@Test
public void testMeasures() {
assertThat(tester.measures("foo:src/Foo.java")).isEmpty();
assertThat(tester.measure("foo:src/Foo.java", "ncloc")).isNull();
tester.<Integer>newMeasure().on(new TestInputFileBuilder("foo", "src/Foo.java").build()).forMetric(CoreMetrics.NCLOC).withValue(2).save();
assertThat(tester.measures("foo:src/Foo.java")).hasSize(1);
assertThat(tester.measure("foo:src/Foo.java", "ncloc")).isNotNull();
tester.<Integer>newMeasure().on(new TestInputFileBuilder("foo", "src/Foo.java").build()).forMetric(CoreMetrics.LINES).withValue(4).save();
assertThat(tester.measures("foo:src/Foo.java")).hasSize(2);
assertThat(tester.measure("foo:src/Foo.java", "ncloc")).isNotNull();
assertThat(tester.measure("foo:src/Foo.java", "lines")).isNotNull();
tester.<Integer>newMeasure().on(new DefaultInputModule("foo")).forMetric(CoreMetrics.DIRECTORIES).withValue(4).save();
assertThat(tester.measures("foo")).hasSize(1);
assertThat(tester.measure("foo", "directories")).isNotNull();
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class MetadataPublisher method publish.
@Override
public void publish(ScannerReportWriter writer) {
DefaultInputModule rootProject = moduleHierarchy.root();
ProjectDefinition rootDef = rootProject.definition();
ScannerReport.Metadata.Builder builder = ScannerReport.Metadata.newBuilder().setAnalysisDate(projectAnalysisInfo.analysisDate().getTime()).setProjectKey(rootDef.getKey()).setCrossProjectDuplicationActivated(SonarCpdBlockIndex.isCrossProjectDuplicationEnabled(settings)).setRootComponentRef(rootProject.batchId());
String organization = settings.getString(CoreProperties.PROJECT_ORGANIZATION_PROPERTY);
if (organization != null) {
builder.setOrganizationKey(organization);
}
String branch = rootDef.getBranch();
if (branch != null) {
builder.setBranch(branch);
}
for (QProfile qp : qProfiles.findAll()) {
builder.getMutableQprofilesPerLanguage().put(qp.getLanguage(), ScannerReport.Metadata.QProfile.newBuilder().setKey(qp.getKey()).setLanguage(qp.getLanguage()).setName(qp.getName()).setRulesUpdatedAt(qp.getRulesUpdatedAt().getTime()).build());
}
writer.writeMetadata(builder.build());
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule 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;
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class IssuesReportBuilder method buildReport.
public IssuesReport buildReport() {
DefaultInputModule project = moduleHierarchy.root();
IssuesReport issuesReport = new IssuesReport();
issuesReport.setNoFile(!inputComponentStore.allFilesToPublish().iterator().hasNext());
issuesReport.setTitle(project.definition().getName());
issuesReport.setDate(projectAnalysisInfo.analysisDate());
processIssues(issuesReport, issueCache.all());
return issuesReport;
}
Aggregations