Search in sources :

Example 46 with DefaultInputFile

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

the class CoveragePublisher method publish.

@Override
public void publish(ScannerReportWriter writer) {
    for (final DefaultInputFile inputFile : componentStore.allFilesToPublish()) {
        Map<Integer, LineCoverage.Builder> coveragePerLine = new LinkedHashMap<>();
        int lineCount = inputFile.lines();
        applyLineMeasure(inputFile.key(), lineCount, CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, coveragePerLine, (value, builder) -> builder.setHits(Integer.parseInt(value) > 0));
        applyLineMeasure(inputFile.key(), lineCount, CoreMetrics.CONDITIONS_BY_LINE_KEY, coveragePerLine, (value, builder) -> builder.setConditions(Integer.parseInt(value)));
        applyLineMeasure(inputFile.key(), lineCount, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine, (value, builder) -> builder.setCoveredConditions(Integer.parseInt(value)));
        writer.writeComponentCoverage(inputFile.batchId(), Iterables.transform(coveragePerLine.values(), BuildCoverage.INSTANCE));
    }
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Builder(org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.Builder) LinkedHashMap(java.util.LinkedHashMap)

Example 47 with DefaultInputFile

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

the class FileIndexer method indexFile.

private Void indexFile(DefaultModuleFileSystem fileSystem, Progress progress, Path sourceFile, InputFile.Type type) throws IOException {
    // get case of real file without resolving link
    Path realFile = sourceFile.toRealPath(LinkOption.NOFOLLOW_LINKS);
    DefaultInputFile inputFile = inputFileBuilder.create(realFile, type, fileSystem.encoding());
    if (inputFile != null) {
        if (exclusionFilters.accept(inputFile, type) && accept(inputFile)) {
            synchronized (this) {
                fileSystem.add(inputFile);
                indexParentDir(fileSystem, inputFile);
                progress.markAsIndexed(inputFile);
            }
            LOG.debug("'{}' indexed {}with language '{}'", inputFile.relativePath(), type == Type.TEST ? "as test " : "", inputFile.language());
            inputFileBuilder.checkMetadata(inputFile);
        } else {
            progress.increaseExcludedByPatternsCount();
        }
    }
    return null;
}
Also used : Path(java.nio.file.Path) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile)

Example 48 with DefaultInputFile

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

the class TaskResult method highlightingTypeFor.

/**
   * Get highlighting types at a given position in an inputfile
   * @param lineOffset 0-based offset in file
   */
public List<TypeOfText> highlightingTypeFor(InputFile file, int line, int lineOffset) {
    int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef();
    if (!reader.hasSyntaxHighlighting(ref)) {
        return Collections.emptyList();
    }
    TextPointer pointer = file.newPointer(line, lineOffset);
    List<TypeOfText> result = new ArrayList<>();
    try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = reader.readComponentSyntaxHighlighting(ref)) {
        while (it.hasNext()) {
            ScannerReport.SyntaxHighlightingRule rule = it.next();
            TextRange ruleRange = toRange(file, rule.getRange());
            if (ruleRange.start().compareTo(pointer) <= 0 && ruleRange.end().compareTo(pointer) > 0) {
                result.add(ScannerReportUtils.toBatchType(rule.getType()));
            }
        }
    } catch (Exception e) {
        throw new IllegalStateException("Can't read syntax highlighting for " + file.absolutePath(), e);
    }
    return result;
}
Also used : TypeOfText(org.sonar.api.batch.sensor.highlighting.TypeOfText) TextPointer(org.sonar.api.batch.fs.TextPointer) ArrayList(java.util.ArrayList) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) TextRange(org.sonar.api.batch.fs.TextRange) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile)

Example 49 with DefaultInputFile

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

the class JSONReport method writeJsonComponents.

private void writeJsonComponents(JsonWriter json) throws IOException {
    json.name("components").beginArray();
    // Dump modules
    writeJsonModuleComponents(json, rootModule);
    for (DefaultInputFile inputFile : componentStore.allFilesToPublish()) {
        String moduleKey = getModule(inputFile).definition().getKeyWithBranch();
        String key = ComponentKeys.createEffectiveKey(moduleKey, inputFile);
        json.beginObject().prop("key", key).prop("path", inputFile.relativePath()).prop("moduleKey", moduleKey).prop("status", inputFile.status().name()).endObject();
    }
    for (InputDir inputDir : componentStore.allDirs()) {
        String moduleKey = getModule(inputDir).definition().getKeyWithBranch();
        String key = ComponentKeys.createEffectiveKey(moduleKey, inputDir);
        json.beginObject().prop("key", key).prop("path", inputDir.relativePath()).prop("moduleKey", moduleKey).endObject();
    }
    json.endArray();
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) InputDir(org.sonar.api.batch.fs.InputDir)

Example 50 with DefaultInputFile

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

the class LocalIssueTracking method loadSourceHashes.

@CheckForNull
private SourceHashHolder loadSourceHashes(InputComponent component) {
    SourceHashHolder sourceHashHolder = null;
    if (component.isFile()) {
        DefaultInputModule module = (DefaultInputModule) componentTree.getParent(componentTree.getParent(component));
        DefaultInputFile file = (DefaultInputFile) component;
        sourceHashHolder = new SourceHashHolder(module, file, lastLineHashes);
    }
    return sourceHashHolder;
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) CheckForNull(javax.annotation.CheckForNull)

Aggregations

DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)64 Test (org.junit.Test)34 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)22 File (java.io.File)19 InputFile (org.sonar.api.batch.fs.InputFile)17 TaskResult (org.sonar.scanner.mediumtest.TaskResult)9 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)8 FileReader (java.io.FileReader)6 Path (java.nio.file.Path)6 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)6 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)5 InputDir (org.sonar.api.batch.fs.InputDir)5 WebSourceCode (org.sonar.plugins.web.visitor.WebSourceCode)5 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)5 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)4 Block (org.sonar.duplications.block.Block)4 Node (org.sonar.plugins.web.node.Node)4 CheckForNull (javax.annotation.CheckForNull)3 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)3 Issue (org.sonar.api.batch.sensor.issue.Issue)3