use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.
the class DefaultIssueCallback method execute.
@Override
public void execute() {
if (listener == null) {
return;
}
for (TrackedIssue issue : issues.all()) {
collectInfo(issue);
}
getUsers();
for (TrackedIssue issue : issues.all()) {
IssueListener.Issue newIssue = new IssueListener.Issue();
newIssue.setAssigneeLogin(issue.assignee());
newIssue.setAssigneeName(getAssigneeName(issue.assignee()));
newIssue.setComponentKey(issue.componentKey());
newIssue.setKey(issue.key());
newIssue.setMessage(issue.getMessage());
newIssue.setNew(issue.isNew());
newIssue.setResolution(issue.resolution());
newIssue.setRuleKey(issue.getRuleKey().toString());
newIssue.setRuleName(getRuleName(issue.getRuleKey()));
newIssue.setSeverity(issue.severity());
newIssue.setStatus(issue.status());
newIssue.setStartLine(issue.startLine());
newIssue.setStartLineOffset(issue.startLineOffset());
newIssue.setEndLine(issue.endLine());
newIssue.setEndLineOffset(issue.endLineOffset());
listener.handle(newIssue);
}
}
use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.
the class IssueTransformer method toTrackedIssue.
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;
}
use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.
the class IssueTransformer method toTrackedIssue.
public static TrackedIssue toTrackedIssue(ServerIssue serverIssue) {
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);
issue.setComponentKey(ComponentKeys.createEffectiveKey(serverIssue.getModuleKey(), serverIssue.hasPath() ? serverIssue.getPath() : null));
issue.setCreationDate(new Date(serverIssue.getCreationDate()));
issue.setRuleKey(RuleKey.of(serverIssue.getRuleRepository(), serverIssue.getRuleKey()));
issue.setNew(false);
return issue;
}
use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.
the class ResourceReport method addIssue.
public void addIssue(TrackedIssue issue, Rule rule, RulePriority severity) {
ReportRuleKey reportRuleKey = new ReportRuleKey(rule, severity);
initMaps(reportRuleKey);
issues.add(issue);
Integer line = issue.startLine();
line = line != null ? line : 0;
if (!issuesPerLine.containsKey(line)) {
issuesPerLine.put(line, new ArrayList<TrackedIssue>());
}
issuesPerLine.get(line).add(issue);
if (!issuesByRule.containsKey(rule)) {
issuesByRule.put(rule, new AtomicInteger());
}
issuesByRule.get(rule).incrementAndGet();
if (!issuesBySeverity.containsKey(severity)) {
issuesBySeverity.put(severity, new AtomicInteger());
}
issuesBySeverity.get(severity).incrementAndGet();
ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementCountInCurrentAnalysis();
total.incrementCountInCurrentAnalysis();
if (issue.isNew()) {
if (!newIssuesPerLine.containsKey(line)) {
newIssuesPerLine.put(line, new ArrayList<TrackedIssue>());
}
newIssuesPerLine.get(line).add(issue);
total.incrementNewIssuesCount();
ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementNewIssuesCount();
}
}
use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.
the class DefaultProjectIssuesTest method should_get_all_issues.
@Test
public void should_get_all_issues() {
DefaultIssue issueOnModule = new DefaultIssue().setKey("1").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core");
DefaultIssue issueInModule = new DefaultIssue().setKey("2").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core:Action");
DefaultIssue resolvedIssueInModule = new DefaultIssue().setKey("3").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core:Action").setResolution(Issue.RESOLUTION_FIXED);
DefaultIssue issueOnRoot = new DefaultIssue().setKey("4").setRuleKey(SQUID_RULE_KEY).setSeverity(Severity.CRITICAL).setComponentKey("org.apache:struts");
DefaultIssue issueInRoot = new DefaultIssue().setKey("5").setRuleKey(SQUID_RULE_KEY).setSeverity(Severity.CRITICAL).setComponentKey("org.apache:struts:FileInRoot");
when(cache.all()).thenReturn(Arrays.<TrackedIssue>asList(toTrackedIssue(issueOnRoot), toTrackedIssue(issueInRoot), toTrackedIssue(issueOnModule), toTrackedIssue(issueInModule), toTrackedIssue(resolvedIssueInModule)));
// unresolved issues
List<Issue> issues = Lists.newArrayList(projectIssues.issues());
assertThat(issues).containsOnly(issueOnRoot, issueInRoot, issueInModule, issueOnModule);
List<Issue> resolvedIssues = Lists.newArrayList(projectIssues.resolvedIssues());
assertThat(resolvedIssues).containsOnly(resolvedIssueInModule);
}
Aggregations