public boolean setPastLocations(DefaultIssue issue, @Nullable Object previousLocations) { Object currentLocations = issue.getLocations(); issue.setLocations(previousLocations); return setLocations(issue, currentLocations); }
public boolean setLocations(DefaultIssue issue, @Nullable Object locations) { if (!Objects.equals(locations, issue.getLocations())) { issue.setLocations(locations); issue.setChanged(true); return true; } return false; }
/** * 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())); }
@Override public void accept(DefaultIssue issue, ScmInfo scmInfo) { when(issue.getLocations()).thenReturn(DbIssues.Locations.newBuilder().setTextRange(range(2, 3)).build()); setDateOfChangetsetAtLine(scmInfo, 2, 1200L); setDateOfChangetsetAtLine(scmInfo, 3, 1300L); } }
@Test public void do_not_change_locations() { issue.setLocations("[1-3]"); boolean updated = underTest.setLocations(issue, "[1-3]"); assertThat(updated).isFalse(); assertThat(issue.getLocations().toString()).isEqualTo("[1-3]"); assertThat(issue.currentChange()).isNull(); assertThat(issue.mustSendNotifications()).isFalse(); }
@Test public void set_locations_for_the_first_time() { issue.setLocations(null); boolean updated = underTest.setLocations(issue, "[1-4]"); assertThat(updated).isTrue(); assertThat(issue.getLocations().toString()).isEqualTo("[1-4]"); assertThat(issue.currentChange()).isNull(); assertThat(issue.mustSendNotifications()).isFalse(); }
@Test public void change_locations() { issue.setLocations("[1-3]"); boolean updated = underTest.setLocations(issue, "[1-4]"); assertThat(updated).isTrue(); assertThat(issue.getLocations().toString()).isEqualTo("[1-4]"); assertThat(issue.currentChange()).isNull(); assertThat(issue.mustSendNotifications()).isFalse(); }
@Override public void accept(DefaultIssue issue, ScmInfo scmInfo) { Builder locations = DbIssues.Locations.newBuilder() .setTextRange(range(2, 3)) .addFlow(newFlow(newLocation(4, 5))) .addFlow(newFlow(newLocation(6, 7, COMPONENT_UUID), newLocation(8, 9, COMPONENT_UUID))); when(issue.getLocations()).thenReturn(locations.build()); setDateOfChangetsetAtLine(scmInfo, 2, 1200L); setDateOfChangetsetAtLine(scmInfo, 3, 1300L); setDateOfChangetsetAtLine(scmInfo, 4, 1400L); setDateOfChangetsetAtLine(scmInfo, 5, 1500L); // some lines missing should be ok setDateOfChangetsetAtLine(scmInfo, 9, 1900L); } }
@Override public void accept(DefaultIssue issue, ScmInfo scmInfo) { Builder locations = DbIssues.Locations.newBuilder() .setTextRange(range(2, 3)) .addFlow(newFlow(newLocation(4, 5))) .addFlow(newFlow(newLocation(6, 7, COMPONENT_UUID), newLocation(8, 9, "another"))); when(issue.getLocations()).thenReturn(locations.build()); setDateOfChangetsetAtLine(scmInfo, 2, 1200L); setDateOfChangetsetAtLine(scmInfo, 3, 1300L); setDateOfChangetsetAtLine(scmInfo, 4, 1400L); setDateOfChangetsetAtLine(scmInfo, 5, 1500L); setDateOfChangetsetAtLine(scmInfo, 6, 1600L); setDateOfChangetsetAtLine(scmInfo, 7, 1700L); setDateOfChangetsetAtLine(scmInfo, 8, 1800L); setDateOfChangetsetAtLine(scmInfo, 9, 1900L); } }
DefaultIssue issue = Iterators.getOnlyElement(issues.iterator()); DbIssues.Locations locations = issue.getLocations();
updater.setPastLocations(raw, base.getLocations()); updater.setPastMessage(raw, base.getMessage(), changeContext); updater.setPastGap(raw, base.gap(), changeContext);
.setType(issue.type()) .setLine(issue.line()) .setLocations((DbIssues.Locations) issue.getLocations()) .setMessage(issue.message()) .setGap(issue.gap())
.setType(issue.type()) .setLine(issue.line()) .setLocations((DbIssues.Locations) issue.getLocations()) .setMessage(issue.message()) .setGap(issue.gap())
public boolean setLocations(DefaultIssue issue, @Nullable Object locations) { if (!Objects.equals(locations, issue.getLocations())) { issue.setLocations(locations); issue.setChanged(true); return true; } return false; }
public boolean setPastLocations(DefaultIssue issue, @Nullable Object previousLocations) { Object currentLocations = issue.getLocations(); issue.setLocations(previousLocations); return setLocations(issue, currentLocations); }
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()); }
public void mergeExistingOpenIssue(DefaultIssue raw, DefaultIssue base) { raw.setKey(base.key()); raw.setNew(false); copyFields(raw, base); if (base.manualSeverity()) { raw.setManualSeverity(true); raw.setSeverity(base.severity()); } else { updater.setPastSeverity(raw, base.severity(), changeContext); } // set component/module related fields from base in case current component has been moved // (in which case base issue belongs to original file and raw issue to component) raw.setComponentUuid(base.componentUuid()); raw.setComponentKey(base.componentKey()); raw.setModuleUuid(base.moduleUuid()); raw.setModuleUuidPath(base.moduleUuidPath()); // fields coming from raw updater.setPastLine(raw, base.getLine()); updater.setPastLocations(raw, base.getLocations()); updater.setPastMessage(raw, base.getMessage(), changeContext); updater.setPastGap(raw, base.gap(), changeContext); updater.setPastEffort(raw, base.effort(), changeContext); }
.setType(issue.type()) .setLine(issue.line()) .setLocations((DbIssues.Locations) issue.getLocations()) .setMessage(issue.message()) .setGap(issue.gap())
.setType(issue.type()) .setLine(issue.line()) .setLocations((DbIssues.Locations) issue.getLocations()) .setMessage(issue.message()) .setGap(issue.gap())