Search in sources :

Example 81 with DefaultInputFile

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

the class DefaultSensorStorage method store.

@Override
public void store(NewSignificantCode newSignificantCode) {
    DefaultSignificantCode significantCode = (DefaultSignificantCode) newSignificantCode;
    ScannerReportWriter writer = reportPublisher.getWriter();
    DefaultInputFile inputFile = (DefaultInputFile) significantCode.inputFile();
    if (shouldSkipStorage(inputFile)) {
        return;
    }
    inputFile.setPublished(true);
    int componentRef = inputFile.scannerId();
    if (writer.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, componentRef)) {
        throw new UnsupportedOperationException("Trying to save significant code information twice for the same file is not supported: " + significantCode.inputFile());
    }
    List<ScannerReport.LineSgnificantCode> protobuf = significantCode.significantCodePerLine().values().stream().map(range -> ScannerReport.LineSgnificantCode.newBuilder().setLine(range.start().line()).setStartOffset(range.start().lineOffset()).setEndOffset(range.end().lineOffset()).build()).collect(Collectors.toList());
    writer.writeComponentSignificantCode(componentRef, protobuf);
}
Also used : Metric(org.sonar.api.batch.measure.Metric) ScannerMetrics(org.sonar.core.metric.ScannerMetrics) Block(org.sonar.duplications.block.Block) Measure(org.sonar.api.batch.sensor.measure.Measure) COMMENT_LINES_DATA_KEY(org.sonar.api.measures.CoreMetrics.COMMENT_LINES_DATA_KEY) PmdBlockChunker(org.sonar.duplications.internal.pmd.PmdBlockChunker) NewSignificantCode(org.sonar.api.batch.sensor.code.NewSignificantCode) Loggers(org.sonar.api.utils.log.Loggers) NewCpdTokens(org.sonar.api.batch.sensor.cpd.NewCpdTokens) Map(java.util.Map) Configuration(org.sonar.api.config.Configuration) MetricFinder(org.sonar.api.batch.measure.MetricFinder) InputComponent(org.sonar.api.batch.fs.InputComponent) CloseableIterator(org.sonar.core.util.CloseableIterator) Set(java.util.Set) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Collectors(java.util.stream.Collectors) CoreMetrics(org.sonar.api.measures.CoreMetrics) Serializable(java.io.Serializable) List(java.util.List) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) ReportPublisher(org.sonar.scanner.report.ReportPublisher) DefaultSymbolTable(org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable) PUBLIC_DOCUMENTED_API_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.PUBLIC_DOCUMENTED_API_DENSITY_KEY) Math.max(java.lang.Math.max) DefaultHighlighting(org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting) DefaultMeasure(org.sonar.api.batch.sensor.measure.internal.DefaultMeasure) ContextPropertiesCache(org.sonar.scanner.repository.ContextPropertiesCache) SortedMap(java.util.SortedMap) DefaultInputComponent(org.sonar.api.batch.fs.internal.DefaultInputComponent) TEST_SUCCESS_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.TEST_SUCCESS_DENSITY_KEY) InputFile(org.sonar.api.batch.fs.InputFile) IssuePublisher(org.sonar.scanner.issue.IssuePublisher) BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) SonarCpdBlockIndex(org.sonar.scanner.cpd.index.SonarCpdBlockIndex) Constants(org.sonar.scanner.protocol.Constants) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) ExternalIssue(org.sonar.api.batch.sensor.issue.ExternalIssue) HashSet(java.util.HashSet) ScannerReportUtils(org.sonar.scanner.report.ScannerReportUtils) AdHocRule(org.sonar.api.batch.sensor.rule.AdHocRule) Nullable(javax.annotation.Nullable) Logger(org.sonar.api.utils.log.Logger) TextRange(org.sonar.api.batch.fs.TextRange) NewSymbolTable(org.sonar.api.batch.sensor.symbol.NewSymbolTable) LINES_KEY(org.sonar.api.measures.CoreMetrics.LINES_KEY) DefaultSignificantCode(org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode) Issue(org.sonar.api.batch.sensor.issue.Issue) FileStructure(org.sonar.scanner.protocol.output.FileStructure) AnalysisError(org.sonar.api.batch.sensor.error.AnalysisError) DefaultCoverage(org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage) NewHighlighting(org.sonar.api.batch.sensor.highlighting.NewHighlighting) Collectors.toList(java.util.stream.Collectors.toList) TreeMap(java.util.TreeMap) InputDir(org.sonar.api.batch.fs.InputDir) NewCoverage(org.sonar.api.batch.sensor.coverage.NewCoverage) KeyValueFormat(org.sonar.api.utils.KeyValueFormat) DefaultCpdTokens(org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultSignificantCode(org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter)

Example 82 with DefaultInputFile

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

the class DefaultSensorStorage method store.

@Override
public void store(NewHighlighting newHighlighting) {
    DefaultHighlighting highlighting = (DefaultHighlighting) newHighlighting;
    ScannerReportWriter writer = reportPublisher.getWriter();
    DefaultInputFile inputFile = (DefaultInputFile) highlighting.inputFile();
    if (shouldSkipStorage(inputFile)) {
        return;
    }
    inputFile.setPublished(true);
    int componentRef = inputFile.scannerId();
    if (writer.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, componentRef)) {
        throw new UnsupportedOperationException("Trying to save highlighting twice for the same file is not supported: " + inputFile);
    }
    final ScannerReport.SyntaxHighlightingRule.Builder builder = ScannerReport.SyntaxHighlightingRule.newBuilder();
    final ScannerReport.TextRange.Builder rangeBuilder = ScannerReport.TextRange.newBuilder();
    writer.writeComponentSyntaxHighlighting(componentRef, highlighting.getSyntaxHighlightingRuleSet().stream().map(input -> {
        builder.setRange(rangeBuilder.setStartLine(input.range().start().line()).setStartOffset(input.range().start().lineOffset()).setEndLine(input.range().end().line()).setEndOffset(input.range().end().lineOffset()).build());
        builder.setType(ScannerReportUtils.toProtocolType(input.getTextType()));
        return builder.build();
    }).collect(toList()));
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultHighlighting(org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting) TextRange(org.sonar.api.batch.fs.TextRange) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter)

Example 83 with DefaultInputFile

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

the class DefaultIssueLocation method at.

@Override
public DefaultIssueLocation at(TextRange location) {
    checkState(this.component != null, "at() should be called after on()");
    checkState(this.component.isFile(), "at() should be called only for an InputFile.");
    DefaultInputFile file = (DefaultInputFile) this.component;
    file.validate(location);
    this.textRange = location;
    return this;
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile)

Example 84 with DefaultInputFile

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

the class ModuleCoverageAndDuplicationExclusionsTest method shouldNotExcludeFileBasedOnPattern.

@Test
public void shouldNotExcludeFileBasedOnPattern() {
    DefaultInputFile file = TestInputFileBuilder.create("foo", new File(baseDir, "moduleA"), new File(baseDir, "moduleA/src/org/polop/File.php")).setProjectBaseDir(baseDir.toPath()).build();
    coverageExclusions = new ModuleCoverageAndDuplicationExclusions(mockConfig("src/org/other/*", ""));
    assertThat(coverageExclusions.isExcludedForCoverage(file)).isFalse();
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) ModuleCoverageAndDuplicationExclusions(org.sonar.scanner.scan.filesystem.ModuleCoverageAndDuplicationExclusions) Test(org.junit.Test)

Example 85 with DefaultInputFile

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

the class ComponentsPublisherTest method publish_unchanged_components_even_in_prs.

@Test
public void publish_unchanged_components_even_in_prs() throws IOException {
    when(branchConfiguration.isPullRequest()).thenReturn(true);
    ProjectInfo projectInfo = mock(ProjectInfo.class);
    when(projectInfo.getAnalysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
    Path baseDir = temp.newFolder().toPath();
    ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0").setName("Root project").setDescription("Root description").setBaseDir(baseDir.toFile()).setWorkDir(temp.newFolder());
    DefaultInputProject project = new DefaultInputProject(rootDef, 1);
    InputComponentStore store = new InputComponentStore(branchConfiguration, sonarRuntime);
    DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.java", 5).setLines(2).setPublish(true).setStatus(InputFile.Status.ADDED).build();
    store.put("foo", file);
    DefaultInputFile file2 = new TestInputFileBuilder("foo", "src2/Foo2.java", 6).setPublish(true).setStatus(InputFile.Status.SAME).setLines(2).build();
    store.put("foo", file2);
    ComponentsPublisher publisher = new ComponentsPublisher(project, store);
    publisher.publish(writer);
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 5)).isTrue();
    // do not skip, needed for computing overall coverage
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isTrue();
}
Also used : Path(java.nio.file.Path) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) ProjectInfo(org.sonar.scanner.ProjectInfo) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Aggregations

DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)173 Test (org.junit.Test)117 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)75 File (java.io.File)63 InputFile (org.sonar.api.batch.fs.InputFile)46 Path (java.nio.file.Path)25 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)18 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)17 BlameOutput (org.sonar.api.batch.scm.BlameCommand.BlameOutput)16 FileMetadata (org.sonar.api.batch.fs.internal.FileMetadata)14 IOException (java.io.IOException)13 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)11 Metadata (org.sonar.api.batch.fs.internal.Metadata)11 Before (org.junit.Before)10 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)10 BlameLine (org.sonar.api.batch.scm.BlameLine)9 List (java.util.List)8 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)8 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)7 TextRange (org.sonar.api.batch.fs.TextRange)7