/** * Extract the lines of all the locations in the specified component. All the flows and secondary locations * are taken into account. The lines present in multiple flows and locations are kept * duplicated. Ordering of results is not guaranteed. * <p> * TODO should be a method of DefaultIssue, as soon as it's no * longer in sonar-core and can access sonar-db-dao. */ public static IntStream allLinesFor(DefaultIssue issue, String componentId) { DbIssues.Locations locations = issue.getLocations(); if (locations == null) { return IntStream.empty(); } Stream<DbCommons.TextRange> textRanges = Stream.concat( locations.hasTextRange() ? Stream.of(locations.getTextRange()) : Stream.empty(), locations.getFlowList().stream() .flatMap(f -> f.getLocationList().stream()) .filter(l -> Objects.equals(componentIdOf(issue, l), componentId)) .map(DbIssues.Location::getTextRange)); return textRanges.flatMapToInt(range -> IntStream.rangeClosed(range.getStartLine(), range.getEndLine())); }
private void collectComponentsFromIssueLocations(IssueDto issue) { DbIssues.Locations locations = issue.parseLocations(); if (locations != null) { for (DbIssues.Flow flow : locations.getFlowList()) { for (DbIssues.Location location : flow.getLocationList()) { if (location.hasComponentId()) { componentUuids.add(location.getComponentId()); } } } } }
assertThat(locations.getFlow(0).getLocationList()).hasSize(2);
private static Optional<Changeset> getChangeset(Component component, ScmInfo scmInfo, DefaultIssue issue) { Set<Integer> involvedLines = new HashSet<>(); DbIssues.Locations locations = issue.getLocations(); if (locations != null) { if (locations.hasTextRange()) { addLines(involvedLines, locations.getTextRange()); } for (Flow f : locations.getFlowList()) { for (Location l : f.getLocationList()) { if (Objects.equals(l.getComponentId(), component.getUuid())) { // Ignore locations in other files, since it is currently not very common, and this is hard to load SCM by component UUID. addLines(involvedLines, l.getTextRange()); } } } if (!involvedLines.isEmpty()) { return involvedLines.stream() .filter(scmInfo::hasChangesetForLine) .map(scmInfo::getChangesetForLine) .max(Comparator.comparingLong(Changeset::getDate)); } } return Optional.of(scmInfo.getLatestChangeset()); }
private static void completeIssueLocations(IssueDto dto, Issue.Builder issueBuilder, SearchResponseData data) { DbIssues.Locations locations = dto.parseLocations(); if (locations == null) { return; } if (locations.hasTextRange()) { DbCommons.TextRange textRange = locations.getTextRange(); issueBuilder.setTextRange(convertTextRange(textRange)); } for (DbIssues.Flow flow : locations.getFlowList()) { Flow.Builder targetFlow = Flow.newBuilder(); for (DbIssues.Location flowLocation : flow.getLocationList()) { targetFlow.addLocations(convertLocation(issueBuilder, flowLocation, data)); } issueBuilder.addFlows(targetFlow); } }
private void collectComponentsFromIssueLocations(IssueDto issue) { DbIssues.Locations locations = issue.parseLocations(); if (locations != null) { for (DbIssues.Flow flow : locations.getFlowList()) { for (DbIssues.Location location : flow.getLocationList()) { if (location.hasComponentId()) { componentUuids.add(location.getComponentId()); } } } } }
private static void completeIssueLocations(IssueDto dto, Issue.Builder issueBuilder, SearchResponseData data) { DbIssues.Locations locations = dto.parseLocations(); if (locations == null) { return; } if (locations.hasTextRange()) { DbCommons.TextRange textRange = locations.getTextRange(); issueBuilder.setTextRange(convertTextRange(textRange)); } for (DbIssues.Flow flow : locations.getFlowList()) { Flow.Builder targetFlow = Flow.newBuilder(); for (DbIssues.Location flowLocation : flow.getLocationList()) { targetFlow.addLocations(convertLocation(issueBuilder, flowLocation, data)); } issueBuilder.addFlows(targetFlow); } }