private TrackedIssue createIssue(String key, String componentKey, String severity) { TrackedIssue issue = new TrackedIssue(); issue.setKey(key); issue.setComponentKey(componentKey); issue.setSeverity(severity); return issue; } }
@Test public void should_exclude_resolved_issues() throws Exception { RuleKey ruleKey = RuleKey.of("squid", "AvoidCycles"); TrackedIssue issue = new TrackedIssue(); issue.setKey("200"); issue.setComponentKey("struts:src/main/java/org/apache/struts/Action.java"); issue.setRuleKey(ruleKey); issue.setStatus(Issue.STATUS_CLOSED); issue.setResolution(Issue.RESOLUTION_FIXED); 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-without-resolved-issues.json"))); }
defaultIssue.setComponentKey("foo:src/Foo.php"); defaultIssue.setGap(2.0); defaultIssue.setNew(true);
@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"))); }
TrackedIssue trackedIssue = new TrackedIssue() .setKey("XYZ123") .setComponentKey("foo") .setRuleKey(RuleKey.of("repo", "rule")) .setSeverity("MAJOR")
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; }
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; }