From 957ee8dda99b4ad469bc08250aab65a77863dc97 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 4 Aug 2015 09:25:07 +0200 Subject: [PATCH] SONARUNNER-143 New API to retrieve issues produced by the analysis --- .../org/sonar/runner/api/EmbeddedRunner.java | 7 +- .../main/java/org/sonar/runner/api/Issue.java | 89 ++++++++++++++----- .../sonar/runner/api/EmbeddedRunnerTest.java | 4 +- .../org/sonar/runner/batch/IssueListener.java | 87 +++++++++++------- .../org/sonar/runner/batch/Compatibility.java | 22 +++-- 5 files changed, 146 insertions(+), 63 deletions(-) diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java index 6d9f0fe..7b852ab 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java @@ -228,14 +228,17 @@ public class EmbeddedRunner { private static org.sonar.runner.api.Issue transformIssue(org.sonar.runner.batch.IssueListener.Issue batchIssue) { org.sonar.runner.api.Issue.Builder issueBuilder = org.sonar.runner.api.Issue.builder(); - issueBuilder.setAssignee(batchIssue.getAssignee()); + issueBuilder.setAssigneeLogin(batchIssue.getAssigneeLogin()); + issueBuilder.setAssigneeName(batchIssue.getAssigneeName()); issueBuilder.setComponentKey(batchIssue.getComponentKey()); issueBuilder.setKey(batchIssue.getKey()); issueBuilder.setLine(batchIssue.getLine()); issueBuilder.setMessage(batchIssue.getMessage()); issueBuilder.setNew(batchIssue.isNew()); issueBuilder.setResolution(batchIssue.getResolution()); - issueBuilder.setRule(batchIssue.getRule()); + issueBuilder.setRuleKey(batchIssue.getRuleKey()); + issueBuilder.setRuleName(batchIssue.getRuleName()); + issueBuilder.setSeverity(batchIssue.getSeverity()); issueBuilder.setStatus(batchIssue.getStatus()); return issueBuilder.build(); diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/Issue.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/Issue.java index eb765dd..23b81e4 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/api/Issue.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/Issue.java @@ -27,23 +27,30 @@ public final class Issue { private final String componentKey; private final Integer line; private final String message; - private final String rule; + private final String ruleKey; + private final String ruleName; private final String status; private final String resolution; private final boolean isNew; - private final String assignee; + private final String assigneeLogin; + private final String assigneeName; + private final String severity; - private Issue(String key, String componentKey, Integer line, String message, String rule, String status, String resolution, boolean isNew, String assignee) { + private Issue(String key, String componentKey, Integer line, String message, String ruleKey, String ruleName, String status, String resolution, boolean isNew, + String assigneeLogin, String assigneeName, String severity) { super(); this.key = key; this.componentKey = componentKey; this.line = line; this.message = message; - this.rule = rule; + this.ruleKey = ruleKey; + this.ruleName = ruleName; this.status = status; this.resolution = resolution; this.isNew = isNew; - this.assignee = assignee; + this.assigneeLogin = assigneeLogin; + this.assigneeName = assigneeName; + this.severity = severity; } public static class Builder { @@ -51,11 +58,14 @@ public final class Issue { private String componentKey; private Integer line; private String message; - private String rule; + private String ruleKey; + private String ruleName; private String status; private String resolution; private boolean isNew; - private String assignee; + private String assigneeLogin; + private String assigneeName; + private String severity; public String getKey() { return key; @@ -93,12 +103,21 @@ public final class Issue { return this; } - public String getRule() { - return rule; + public String getRuleKey() { + return ruleKey; } - public Builder setRule(String rule) { - this.rule = rule; + public Builder setRuleKey(String ruleKey) { + this.ruleKey = ruleKey; + return this; + } + + public String getRuleName() { + return ruleKey; + } + + public Builder setRuleName(String ruleName) { + this.ruleName = ruleName; return this; } @@ -129,17 +148,35 @@ public final class Issue { return this; } - public String getAssignee() { - return assignee; + public String getAssigneeLogin() { + return assigneeLogin; } - public Builder setAssignee(String assignee) { - this.assignee = assignee; + public Builder setAssigneeLogin(String assigneeLogin) { + this.assigneeLogin = assigneeLogin; + return this; + } + + public String getAssigneeName() { + return assigneeName; + } + + public Builder setAssigneeName(String assigneeName) { + this.assigneeName = assigneeName; + return this; + } + + public String getSeverity() { + return severity; + } + + public Builder setSeverity(String severity) { + this.severity = severity; return this; } public Issue build() { - return new Issue(key, componentKey, line, message, rule, status, resolution, isNew, assignee); + return new Issue(key, componentKey, line, message, ruleKey, ruleName, status, resolution, isNew, assigneeLogin, assigneeName, severity); } } @@ -163,8 +200,12 @@ public final class Issue { return message; } - public String getRule() { - return rule; + public String getRuleKey() { + return ruleKey; + } + + public String getRuleName() { + return ruleName; } public String getStatus() { @@ -179,8 +220,16 @@ public final class Issue { return isNew; } - public String getAssignee() { - return assignee; + public String getAssigneeLogin() { + return assigneeLogin; + } + + public String getAssigneeName() { + return assigneeName; + } + + public String getSeverity() { + return severity; } } diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java b/sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java index 05df62c..ea1e658 100644 --- a/sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java +++ b/sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java @@ -172,11 +172,11 @@ public class EmbeddedRunnerTest { IssueListenerAdapter adapter = new IssueListenerAdapter(apiIssueListener); org.sonar.runner.batch.IssueListener.Issue batchIssue = new org.sonar.runner.batch.IssueListener.Issue(); - batchIssue.setAssignee("assignee"); + batchIssue.setAssigneeName("assignee"); adapter.handle(batchIssue); assertThat(issuesRecorded).hasSize(1); - assertThat(issuesRecorded.get(0).getAssignee()).isEqualTo("assignee"); + assertThat(issuesRecorded.get(0).getAssigneeName()).isEqualTo("assignee"); } @Test(expected = IllegalArgumentException.class) diff --git a/sonar-runner-batch-interface/src/main/java/org/sonar/runner/batch/IssueListener.java b/sonar-runner-batch-interface/src/main/java/org/sonar/runner/batch/IssueListener.java index da59d80..f6b596f 100644 --- a/sonar-runner-batch-interface/src/main/java/org/sonar/runner/batch/IssueListener.java +++ b/sonar-runner-batch-interface/src/main/java/org/sonar/runner/batch/IssueListener.java @@ -27,82 +27,109 @@ public interface IssueListener { private String componentKey; private Integer line; private String message; - private String rule; + private String ruleKey; + private String ruleName; private String status; private String resolution; private boolean isNew; - private String assignee; + private String assigneeLogin; + private String assigneeName; + private String severity; + + public String getSeverity() { + return severity; + } + + public void setSeverity(String severity) { + this.severity = severity; + } + + public String getKey() { + return key; + } public void setKey(String key) { this.key = key; } + public String getComponentKey() { + return componentKey; + } + public void setComponentKey(String componentKey) { this.componentKey = componentKey; } + public Integer getLine() { + return line; + } + public void setLine(Integer line) { this.line = line; } + public String getMessage() { + return message; + } + public void setMessage(String message) { this.message = message; } - public void setRule(String rule) { - this.rule = rule; + public String getRuleKey() { + return ruleKey; } - public void setStatus(String status) { - this.status = status; + public void setRuleKey(String ruleKey) { + this.ruleKey = ruleKey; } - public void setResolution(String resolution) { - this.resolution = resolution; + public String getRuleName() { + return ruleName; } - public void setNew(boolean isNew) { - this.isNew = isNew; + public void setRuleName(String ruleName) { + this.ruleName = ruleName; } - public void setAssignee(String assignee) { - this.assignee = assignee; + public String getStatus() { + return status; } - public String getKey() { - return key; + public void setStatus(String status) { + this.status = status; } - public String getComponentKey() { - return componentKey; + public String getResolution() { + return resolution; } - public Integer getLine() { - return line; + public void setResolution(String resolution) { + this.resolution = resolution; } - public String getMessage() { - return message; + public boolean isNew() { + return isNew; } - public String getRule() { - return rule; + public void setNew(boolean isNew) { + this.isNew = isNew; } - public String getStatus() { - return status; + public String getAssigneeLogin() { + return assigneeLogin; } - public String getResolution() { - return resolution; + public void setAssigneeLogin(String assigneeLogin) { + this.assigneeLogin = assigneeLogin; } - public boolean isNew() { - return isNew; + public String getAssigneeName() { + return assigneeName; } - public String getAssignee() { - return assignee; + public void setAssigneeName(String assigneeName) { + this.assigneeName = assigneeName; } } diff --git a/sonar-runner-batch/src/main/java/org/sonar/runner/batch/Compatibility.java b/sonar-runner-batch/src/main/java/org/sonar/runner/batch/Compatibility.java index 99eb70c..f37e1b9 100644 --- a/sonar-runner-batch/src/main/java/org/sonar/runner/batch/Compatibility.java +++ b/sonar-runner-batch/src/main/java/org/sonar/runner/batch/Compatibility.java @@ -19,7 +19,6 @@ */ package org.sonar.runner.batch; -import org.sonar.api.issue.Issue; import org.sonar.batch.bootstrapper.Batch; import org.sonar.batch.bootstrapper.LogOutput; @@ -57,15 +56,20 @@ public class Compatibility { private static IssueListener.Issue transformIssue(Issue batchIssue) { IssueListener.Issue newIssue = new IssueListener.Issue(); - newIssue.setAssignee(batchIssue.assignee()); - newIssue.setComponentKey(batchIssue.componentKey()); - newIssue.setKey(batchIssue.key()); - newIssue.setResolution(batchIssue.resolution()); - newIssue.setRule(batchIssue.ruleKey().toString()); - newIssue.setMessage(batchIssue.message()); + + newIssue.setAssigneeLogin(batchIssue.getAssigneeLogin()); + newIssue.setAssigneeName(batchIssue.getAssigneeName()); + newIssue.setComponentKey(batchIssue.getComponentKey()); + newIssue.setKey(batchIssue.getKey()); + newIssue.setResolution(batchIssue.getResolution()); + newIssue.setRuleKey(batchIssue.getRuleKey()); + newIssue.setRuleName(batchIssue.getRuleName()); + newIssue.setMessage(batchIssue.getMessage()); newIssue.setNew(batchIssue.isNew()); - newIssue.setLine(batchIssue.line()); - + newIssue.setLine(batchIssue.getLine()); + newIssue.setSeverity(batchIssue.getSeverity()); + newIssue.setStatus(batchIssue.getStatus()); + return newIssue; } } -- 2.39.5