public List<ScannerReport.ExternalIssue> externalIssuesFor(InputComponent inputComponent) { return externalIssuesFor(((DefaultInputComponent) inputComponent).scannerId()); }
public Iterable<ServerIssue> byComponent(InputComponent component) { return issuesCache.values(((DefaultInputComponent) component).scannerId()); }
public List<ScannerReport.Issue> issuesFor(InputComponent inputComponent) { return issuesFor(((DefaultInputComponent) inputComponent).scannerId()); }
public void initAndAddExternalIssue(ExternalIssue issue) { DefaultInputComponent inputComponent = (DefaultInputComponent) issue.primaryLocation().inputComponent(); ScannerReport.ExternalIssue rawExternalIssue = createReportExternalIssue(issue, inputComponent.scannerId()); write(inputComponent.scannerId(), rawExternalIssue); }
public List<ScannerReport.CpdTextBlock> duplicationBlocksFor(InputFile file) { List<ScannerReport.CpdTextBlock> result = new ArrayList<>(); int ref = ((DefaultInputComponent) file).scannerId(); try (CloseableIterator<ScannerReport.CpdTextBlock> it = getReportReader().readCpdTextBlocks(ref)) { while (it.hasNext()) { result.add(it.next()); } } catch (Exception e) { throw new IllegalStateException(e); } return result; }
public Component getReportComponent(InputComponent inputComponent) { return getReportReader().readComponent(((DefaultInputComponent) inputComponent).scannerId()); }
public List<ScannerReport.Duplication> duplicationsFor(InputFile file) { List<ScannerReport.Duplication> result = new ArrayList<>(); int ref = ((DefaultInputComponent) file).scannerId(); try (CloseableIterator<ScannerReport.Duplication> it = getReportReader().readComponentDuplications(ref)) { while (it.hasNext()) { result.add(it.next()); } } catch (Exception e) { throw new IllegalStateException(e); } return result; }
public Map<String, List<ScannerReport.Measure>> allMeasures() { Map<String, List<ScannerReport.Measure>> result = new HashMap<>(); List<ScannerReport.Measure> projectMeasures = new ArrayList<>(); try (CloseableIterator<ScannerReport.Measure> it = reader.readComponentMeasures(((DefaultInputComponent) project).scannerId())) { Iterators.addAll(projectMeasures, it); } result.put(project.key(), projectMeasures); for (InputFile inputFile : inputFilesByKeys.values()) { List<ScannerReport.Measure> measures = new ArrayList<>(); try (CloseableIterator<ScannerReport.Measure> it = reader.readComponentMeasures(((DefaultInputComponent) inputFile).scannerId())) { Iterators.addAll(measures, it); } result.put(inputFile.key(), measures); } return result; }
@VisibleForTesting final void saveDuplications(final DefaultInputComponent component, List<CloneGroup> duplications) { if (duplications.size() > MAX_CLONE_GROUP_PER_FILE) { LOG.warn("Too many duplication groups on file {}. Keep only the first {} groups.", component, MAX_CLONE_GROUP_PER_FILE); } Iterable<ScannerReport.Duplication> reportDuplications = duplications.stream() .limit(MAX_CLONE_GROUP_PER_FILE) .map( new Function<CloneGroup, Duplication>() { private final ScannerReport.Duplication.Builder dupBuilder = ScannerReport.Duplication.newBuilder(); private final ScannerReport.Duplicate.Builder blockBuilder = ScannerReport.Duplicate.newBuilder(); @Override public ScannerReport.Duplication apply(CloneGroup input) { return toReportDuplication(component, dupBuilder, blockBuilder, input); } })::iterator; publisher.getWriter().writeComponentDuplications(component.scannerId(), reportDuplications); }
@CheckForNull public ScannerReport.LineCoverage coverageFor(InputFile file, int line) { int ref = ((DefaultInputComponent) file).scannerId(); try (CloseableIterator<ScannerReport.LineCoverage> it = getReportReader().readComponentCoverage(ref)) { while (it.hasNext()) { ScannerReport.LineCoverage coverage = it.next(); if (coverage.getLine() == line) { return coverage; } } } catch (Exception e) { throw new IllegalStateException(e); } return null; }
public void trackIssues(ScannerReportReader reader, DefaultInputComponent component) { // raw issues = all the issues created by rule engines during this module scan and not excluded by filters List<ScannerReport.Issue> rawIssues = new LinkedList<>(); try (CloseableIterator<ScannerReport.Issue> it = reader.readComponentIssues(component.scannerId())) { while (it.hasNext()) { rawIssues.add(it.next()); } } catch (Exception e) { throw new IllegalStateException("Can't read issues for " + component.key(), e); } List<TrackedIssue> trackedIssues; if (localIssueTracking != null) { trackedIssues = localIssueTracking.trackIssues(component, rawIssues, analysisDate); } else { trackedIssues = doTransition(rawIssues, component); } for (TrackedIssue issue : trackedIssues) { issueCache.put(issue); } }
public boolean initAndAddIssue(Issue issue) { DefaultInputComponent inputComponent = (DefaultInputComponent) issue.primaryLocation().inputComponent(); if (noSonar(inputComponent, issue)) { return false; } ActiveRule activeRule = activeRules.find(issue.ruleKey()); if (activeRule == null) { // rule does not exist or is not enabled -> ignore the issue return false; } ScannerReport.Issue rawIssue = createReportIssue(issue, inputComponent.scannerId(), activeRule.severity()); if (filters.accept(inputComponent, rawIssue)) { write(inputComponent.scannerId(), rawIssue); return true; } return false; }
@Override public void publish(ScannerReportWriter writer) { final ScannerReport.Measure.Builder builder = ScannerReport.Measure.newBuilder(); for (final InputComponent c : componentStore.all()) { DefaultInputComponent component = (DefaultInputComponent) c; if (component.isFile()) { DefaultInputFile file = (DefaultInputFile) component; // Recompute all coverage measures from line data to take into account the possible merge of several reports updateCoverageFromLineData(file); // Recompute test execution measures from MutableTestPlan to take into account the possible merge of several reports updateTestExecutionFromTestPlan(file); } Iterable<DefaultMeasure<?>> scannerMeasures = measureCache.byComponentKey(component.key()); if (scannerMeasures.iterator().hasNext()) { writer.writeComponentMeasures(component.scannerId(), StreamSupport.stream(scannerMeasures.spliterator(), false) .map(input -> { if (input.value() == null) { throw new IllegalArgumentException( String.format("Measure on metric '%s' and component '%s' has no value, but it's not allowed", input.metric().key(), component.key())); } builder.clear(); builder.setMetricKey(input.metric().key()); setValueAccordingToType(builder, input); return builder.build(); }).collect(Collectors.toList())); } } }
/** * Get list of all start positions of a symbol in an inputfile * * @param symbolStartLine 0-based start offset for the symbol in file * @param symbolStartLineOffset 0-based end offset for the symbol in file */ @CheckForNull public List<ScannerReport.TextRange> symbolReferencesFor(InputFile file, int symbolStartLine, int symbolStartLineOffset) { int ref = ((DefaultInputComponent) file).scannerId(); try (CloseableIterator<Symbol> symbols = getReportReader().readComponentSymbols(ref)) { while (symbols.hasNext()) { Symbol symbol = symbols.next(); if (symbol.getDeclaration().getStartLine() == symbolStartLine && symbol.getDeclaration().getStartOffset() == symbolStartLineOffset) { return symbol.getReferenceList(); } } } return Collections.emptyList(); }
/** * 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 = ((DefaultInputComponent) file).scannerId(); 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, e); } return result; }
private static void applyFlows(Consumer<ScannerReport.Flow> consumer, ScannerReport.IssueLocation.Builder locationBuilder, ScannerReport.TextRange.Builder textRangeBuilder, Collection<Flow> flows) { ScannerReport.Flow.Builder flowBuilder = ScannerReport.Flow.newBuilder(); for (Flow flow : flows) { if (flow.locations().isEmpty()) { return; } flowBuilder.clear(); for (org.sonar.api.batch.sensor.issue.IssueLocation location : flow.locations()) { int locationComponentRef = ((DefaultInputComponent) location.inputComponent()).scannerId(); locationBuilder.clear(); locationBuilder.setComponentRef(locationComponentRef); String message = location.message(); if (message != null) { locationBuilder.setMsg(message); } TextRange textRange = location.textRange(); if (textRange != null) { locationBuilder.setTextRange(toProtobufTextRange(textRangeBuilder, textRange)); } flowBuilder.addLocation(locationBuilder.build()); } consumer.accept(flowBuilder.build()); } }
private void store(ServerIssue issue) { String moduleKeyWithBranch = issue.getModuleKey(); AbstractProjectOrModule moduleOrProject = componentStore.getModule(moduleKeyWithBranch); if (moduleOrProject != null) { String componentKeyWithoutBranch = ComponentKeys.createEffectiveKey(moduleOrProject.key(), issue.hasPath() ? issue.getPath() : null); DefaultInputComponent r = (DefaultInputComponent) componentStore.getByKey(componentKeyWithoutBranch); if (r != null) { issuesCache.put(r.scannerId(), issue.getKey(), issue); return; } } // Deleted resource issuesCache.put(0, issue.getKey(), issue); }
if (!component.key().equals(componentKey)) { DefaultInputComponent sameProjectComponent = (DefaultInputComponent) componentStore.getByKey(componentKey); blockBuilder.setOtherFileRef(sameProjectComponent.scannerId());
public List<ScannerReport.Duplication> duplicationsFor(InputFile file) { List<ScannerReport.Duplication> result = new ArrayList<>(); int ref = ((DefaultInputComponent) file).scannerId(); try (CloseableIterator<ScannerReport.Duplication> it = getReportReader().readComponentDuplications(ref)) { while (it.hasNext()) { result.add(it.next()); } } catch (Exception e) { throw new IllegalStateException(e); } return result; }
public List<ScannerReport.CpdTextBlock> duplicationBlocksFor(InputFile file) { List<ScannerReport.CpdTextBlock> result = new ArrayList<>(); int ref = ((DefaultInputComponent) file).scannerId(); try (CloseableIterator<ScannerReport.CpdTextBlock> it = getReportReader().readCpdTextBlocks(ref)) { while (it.hasNext()) { result.add(it.next()); } } catch (Exception e) { throw new IllegalStateException(e); } return result; }