assertThat(locations.getFlow(0).getLocationList()).hasSize(2); assertThat(locations.getFlow(0).getLocation(0).getComponentId()).isEmpty(); assertThat(locations.getFlow(0).getLocation(1).getComponentId()).isEqualTo(ANOTHER_FILE_UUID);
private Optional<DbIssues.Location> convertLocation(ScannerReport.IssueLocation source) { DbIssues.Location.Builder target = DbIssues.Location.newBuilder(); if (source.getComponentRef() != 0 && source.getComponentRef() != component.getReportAttributes().getRef()) { // SONAR-10781 Component might not exist because on short living branch and PR, only changed components are included in the report Optional<Component> optionalComponent = treeRootHolder.getOptionalComponentByRef(source.getComponentRef()); if (!optionalComponent.isPresent()) { return Optional.empty(); } target.setComponentId(optionalComponent.get().getUuid()); } if (isNotEmpty(source.getMsg())) { target.setMsg(source.getMsg()); } if (source.hasTextRange()) { ScannerReport.TextRange sourceRange = source.getTextRange(); DbCommons.TextRange.Builder targetRange = convertTextRange(sourceRange); target.setTextRange(targetRange); } return Optional.of(target.build()); }
private static Location convertLocation(Issue.Builder issueBuilder, DbIssues.Location source, SearchResponseData data) { Location.Builder target = Location.newBuilder(); if (source.hasMsg()) { target.setMsg(source.getMsg()); } if (source.hasTextRange()) { DbCommons.TextRange sourceRange = source.getTextRange(); Common.TextRange.Builder targetRange = convertTextRange(sourceRange); target.setTextRange(targetRange); } if (source.hasComponentId()) { ofNullable(data.getComponentByUuid(source.getComponentId())).ifPresent(c -> target.setComponent(c.getKey())); } else { target.setComponent(issueBuilder.getComponent()); } return target.build(); }
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 Optional<DbIssues.Location> convertLocation(ScannerReport.IssueLocation source) { DbIssues.Location.Builder target = DbIssues.Location.newBuilder(); if (source.getComponentRef() != 0 && source.getComponentRef() != component.getReportAttributes().getRef()) { // SONAR-10781 Component might not exist because on short living branch and PR, only changed components are included in the report Optional<Component> optionalComponent = treeRootHolder.getOptionalComponentByRef(source.getComponentRef()); if (!optionalComponent.isPresent()) { return Optional.empty(); } target.setComponentId(optionalComponent.get().getUuid()); } if (isNotEmpty(source.getMsg())) { target.setMsg(source.getMsg()); } if (source.hasTextRange()) { ScannerReport.TextRange sourceRange = source.getTextRange(); DbCommons.TextRange.Builder targetRange = convertTextRange(sourceRange); target.setTextRange(targetRange); } return Optional.of(target.build()); }
public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += com.google.protobuf.GeneratedMessage.computeStringSize(1, componentId_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(2, getTextRange()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { size += com.google.protobuf.GeneratedMessage.computeStringSize(3, msg_); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
public Builder mergeFrom(org.sonar.db.protobuf.DbIssues.Location other) { if (other == org.sonar.db.protobuf.DbIssues.Location.getDefaultInstance()) return this; if (other.hasComponentId()) { bitField0_ |= 0x00000001; componentId_ = other.componentId_; onChanged(); } if (other.hasTextRange()) { mergeTextRange(other.getTextRange()); } if (other.hasMsg()) { bitField0_ |= 0x00000004; msg_ = other.msg_; onChanged(); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
private static Location convertLocation(Issue.Builder issueBuilder, DbIssues.Location source, SearchResponseData data) { Location.Builder target = Location.newBuilder(); if (source.hasMsg()) { target.setMsg(source.getMsg()); } if (source.hasTextRange()) { DbCommons.TextRange sourceRange = source.getTextRange(); Common.TextRange.Builder targetRange = convertTextRange(sourceRange); target.setTextRange(targetRange); } if (source.hasComponentId()) { setNullable(data.getComponentByUuid(source.getComponentId()), c -> target.setComponent(c.getKey())); } else { target.setComponent(issueBuilder.getComponent()); } return target.build(); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) == 0x00000001)) { com.google.protobuf.GeneratedMessage.writeString(output, 1, componentId_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeMessage(2, getTextRange()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { com.google.protobuf.GeneratedMessage.writeString(output, 3, msg_); } unknownFields.writeTo(output); }
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()); } } } } }
/** * <code>optional string component_id = 1;</code> */ public Builder clearComponentId() { bitField0_ = (bitField0_ & ~0x00000001); componentId_ = getDefaultInstance().getComponentId(); onChanged(); return this; } /**
/** * <code>optional string msg = 3;</code> */ public Builder clearMsg() { bitField0_ = (bitField0_ & ~0x00000004); msg_ = getDefaultInstance().getMsg(); onChanged(); return this; } /**
ComponentDto anotherFile = db.components().insertComponent(newFileDto(project)); DbIssues.Locations.Builder locations = DbIssues.Locations.newBuilder().addFlow(DbIssues.Flow.newBuilder().addAllLocation(Arrays.asList( DbIssues.Location.newBuilder() .setComponentId(file.uuid()) .setMsg("FLOW MESSAGE") .build()) .build(), DbIssues.Location.newBuilder() .setComponentId(anotherFile.uuid()) .setMsg("ANOTHER FLOW MESSAGE") .build()) .build(), DbIssues.Location.newBuilder()
private static Location newLocation(int startLine, int endLine, String componentUuid) { return Location.newBuilder().setTextRange(range(startLine, endLine)).setComponentId(componentUuid).build(); }
private static Location newLocation(int startLine, int endLine) { return Location.newBuilder().setTextRange(range(startLine, endLine)).build(); }
private static DbIssues.Location newLocation(@Nullable String componentId, int startLine, int endLine) { DbIssues.Location.Builder builder = DbIssues.Location.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder().setStartLine(startLine).setEndLine(endLine).build()); ofNullable(componentId).ifPresent(builder::setComponentId); return builder.build(); } }
private static DbIssues.Location newLocation(int line) { return DbIssues.Location.newBuilder() .setComponentId(FILE.getUuid()) .setTextRange(DbCommons.TextRange.newBuilder().setStartLine(line).setEndLine(line).build()).build(); }
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 String componentIdOf(DefaultIssue issue, DbIssues.Location location) { if (location.hasComponentId()) { return StringUtils.defaultIfEmpty(location.getComponentId(), issue.componentUuid()); } return issue.componentUuid(); } }