Search in sources :

Example 16 with DefaultInputModule

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();
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Highlightable(org.sonar.api.source.Highlightable) AnalysisMode(org.sonar.api.batch.AnalysisMode) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 17 with DefaultInputModule

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();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Test(org.junit.Test)

Example 18 with DefaultInputModule

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());
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) QProfile(org.sonar.scanner.rule.QProfile) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 19 with DefaultInputModule

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

Example 20 with DefaultInputModule

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;
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule)

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