@Test public void should_update_existing_issue() { IssueCache cache = new IssueCache(caches); TrackedIssue issue = createIssue("111", "org.struts.Action", Severity.BLOCKER); cache.put(issue); issue.setSeverity(Severity.MINOR); cache.put(issue); List<TrackedIssue> issues = ImmutableList.copyOf(cache.byComponent("org.struts.Action")); assertThat(issues).hasSize(1); TrackedIssue reloaded = issues.iterator().next(); assertThat(reloaded.key()).isEqualTo("111"); assertThat(reloaded.severity()).isEqualTo(Severity.MINOR); }
@VisibleForTesting protected void mergeMatched(Tracking<TrackedIssue, ServerIssueFromWs> result, Collection<TrackedIssue> mergeTo, Collection<TrackedIssue> rawIssues) { for (Map.Entry<TrackedIssue, ServerIssueFromWs> e : result.getMatchedRaws().entrySet()) { org.sonar.scanner.protocol.input.ScannerInput.ServerIssue dto = e.getValue().getDto(); TrackedIssue tracked = e.getKey(); // invariant fields tracked.setKey(dto.getKey()); // non-persisted fields tracked.setNew(false); // fields to update with old values tracked.setResolution(dto.hasResolution() ? dto.getResolution() : null); tracked.setStatus(dto.getStatus()); tracked.setAssignee(dto.hasAssigneeLogin() ? dto.getAssigneeLogin() : null); tracked.setCreationDate(new Date(dto.getCreationDate())); if (dto.getManualSeverity()) { // Severity overridden by user tracked.setSeverity(dto.getSeverity().name()); } mergeTo.add(tracked); } }
private TrackedIssue createIssue(String key, String componentKey, String severity) { TrackedIssue issue = new TrackedIssue(); issue.setKey(key); issue.setComponentKey(componentKey); issue.setSeverity(severity); return issue; } }
defaultIssue.setStartLine(1); defaultIssue.setMessage("msg"); defaultIssue.setSeverity("BLOCKER"); when(issueCache.all()).thenReturn(Arrays.asList(defaultIssue));
@Test public void should_write_json() throws Exception { TrackedIssue issue = new TrackedIssue(); issue.setKey("200"); issue.setComponentKey("struts:src/main/java/org/apache/struts/Action.java"); issue.setRuleKey(RuleKey.of("squid", "AvoidCycles")); issue.setMessage("There are 2 cycles"); issue.setSeverity("MINOR"); issue.setStatus(Issue.STATUS_OPEN); issue.setResolution(null); issue.setStartLine(1); issue.setEndLine(2); issue.setStartLineOffset(3); issue.setEndLineOffset(4); issue.setGap(3.14); issue.setAssignee("simon"); issue.setCreationDate(SIMPLE_DATE_FORMAT.parse("2013-04-24")); issue.setNew(false); when(issueCache.all()).thenReturn(Collections.singleton(issue)); StringWriter writer = new StringWriter(); jsonReport.writeJson(writer); assertThatJson(writer.toString()).isEqualTo(IOUtils.toString(this.getClass().getResource(this.getClass().getSimpleName() + "/report.json"))); }
.setComponentKey("foo") .setRuleKey(RuleKey.of("repo", "rule")) .setSeverity("MAJOR") .setMessage("msg") .setStartLine(1)
public static TrackedIssue toTrackedIssue(InputComponent component, ScannerReport.Issue rawIssue, @Nullable SourceHashHolder hashes) { RuleKey ruleKey = RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey()); Preconditions.checkNotNull(component.key(), "Component key must be set"); Preconditions.checkNotNull(ruleKey, "Rule key must be set"); TrackedIssue issue = new TrackedIssue(hashes != null ? hashes.getHashedSource() : null); issue.setKey(Uuids.createFast()); issue.setComponentKey(component.key()); issue.setRuleKey(ruleKey); issue.setGap(rawIssue.getGap() != 0 ? rawIssue.getGap() : null); issue.setSeverity(rawIssue.getSeverity().name()); issue.setMessage(StringUtils.trimToNull(rawIssue.getMsg())); issue.setResolution(null); issue.setStatus(Issue.STATUS_OPEN); issue.setNew(true); if (rawIssue.hasTextRange()) { TextRange r = rawIssue.getTextRange(); issue.setStartLine(r.getStartLine()); issue.setStartLineOffset(r.getStartOffset()); issue.setEndLine(r.getEndLine()); issue.setEndLineOffset(r.getEndOffset()); } return issue; }
private TrackedIssue toTrackedIssue(DefaultIssue issue) { TrackedIssue trackedIssue = new TrackedIssue(); trackedIssue.setKey(issue.key()); trackedIssue.setRuleKey(issue.ruleKey()); trackedIssue.setComponentKey(issue.componentKey()); trackedIssue.setSeverity(issue.severity()); trackedIssue.setResolution(issue.resolution()); return trackedIssue; } }
public static TrackedIssue toTrackedIssue(ServerIssue serverIssue, String componentKey) { TrackedIssue issue = new TrackedIssue(); issue.setKey(serverIssue.getKey()); issue.setStatus(serverIssue.getStatus()); issue.setResolution(serverIssue.hasResolution() ? serverIssue.getResolution() : null); issue.setMessage(serverIssue.hasMsg() ? serverIssue.getMsg() : null); issue.setStartLine(serverIssue.hasLine() ? serverIssue.getLine() : null); issue.setEndLine(serverIssue.hasLine() ? serverIssue.getLine() : null); issue.setSeverity(serverIssue.getSeverity().name()); issue.setAssignee(serverIssue.hasAssigneeLogin() ? serverIssue.getAssigneeLogin() : null); // key in serverIssue might have branch, so don't use it issue.setComponentKey(componentKey); issue.setCreationDate(new Date(serverIssue.getCreationDate())); issue.setRuleKey(RuleKey.of(serverIssue.getRuleRepository(), serverIssue.getRuleKey())); issue.setNew(false); return issue; }
@VisibleForTesting protected void mergeMatched(Tracking<TrackedIssue, ServerIssueFromWs> result, Collection<TrackedIssue> mergeTo, Collection<TrackedIssue> rawIssues) { for (Map.Entry<TrackedIssue, ServerIssueFromWs> e : result.getMatchedRaws().entrySet()) { org.sonar.scanner.protocol.input.ScannerInput.ServerIssue dto = e.getValue().getDto(); TrackedIssue tracked = e.getKey(); // invariant fields tracked.setKey(dto.getKey()); // non-persisted fields tracked.setNew(false); // fields to update with old values tracked.setResolution(dto.hasResolution() ? dto.getResolution() : null); tracked.setStatus(dto.getStatus()); tracked.setAssignee(dto.hasAssigneeLogin() ? dto.getAssigneeLogin() : null); tracked.setCreationDate(new Date(dto.getCreationDate())); if (dto.getManualSeverity()) { // Severity overridden by user tracked.setSeverity(dto.getSeverity().name()); } mergeTo.add(tracked); } }
public static TrackedIssue toTrackedIssue(InputComponent component, ScannerReport.Issue rawIssue, @Nullable SourceHashHolder hashes) { RuleKey ruleKey = RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey()); Preconditions.checkNotNull(component.key(), "Component key must be set"); Preconditions.checkNotNull(ruleKey, "Rule key must be set"); TrackedIssue issue = new TrackedIssue(hashes != null ? hashes.getHashedSource() : null); issue.setKey(Uuids.createFast()); issue.setComponentKey(component.key()); issue.setRuleKey(ruleKey); issue.setGap(rawIssue.getGap() != 0 ? rawIssue.getGap() : null); issue.setSeverity(rawIssue.getSeverity().name()); issue.setMessage(StringUtils.trimToNull(rawIssue.getMsg())); issue.setResolution(null); issue.setStatus(Issue.STATUS_OPEN); issue.setNew(true); if (rawIssue.hasTextRange()) { TextRange r = rawIssue.getTextRange(); issue.setStartLine(r.getStartLine()); issue.setStartLineOffset(r.getStartOffset()); issue.setEndLine(r.getEndLine()); issue.setEndLineOffset(r.getEndOffset()); } return issue; }
public static TrackedIssue toTrackedIssue(ServerIssue serverIssue, String componentKey) { TrackedIssue issue = new TrackedIssue(); issue.setKey(serverIssue.getKey()); issue.setStatus(serverIssue.getStatus()); issue.setResolution(serverIssue.hasResolution() ? serverIssue.getResolution() : null); issue.setMessage(serverIssue.hasMsg() ? serverIssue.getMsg() : null); issue.setStartLine(serverIssue.hasLine() ? serverIssue.getLine() : null); issue.setEndLine(serverIssue.hasLine() ? serverIssue.getLine() : null); issue.setSeverity(serverIssue.getSeverity().name()); issue.setAssignee(serverIssue.hasAssigneeLogin() ? serverIssue.getAssigneeLogin() : null); // key in serverIssue might have branch, so don't use it issue.setComponentKey(componentKey); issue.setCreationDate(new Date(serverIssue.getCreationDate())); issue.setRuleKey(RuleKey.of(serverIssue.getRuleRepository(), serverIssue.getRuleKey())); issue.setNew(false); return issue; }