From 7b31d816877f1ce5126079cc642b915c7d4dbc88 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Wed, 4 Nov 2015 16:08:00 +0100 Subject: SONARUNNER-146 Expose enhanced issues location in issues mode --- .../src/main/java/org/sonar/runner/api/Issue.java | 89 +++++++++++++++++----- .../org/sonar/runner/api/IssueListenerAdapter.java | 5 +- 2 files changed, 76 insertions(+), 18 deletions(-) (limited to 'sonar-runner-api/src/main/java/org') 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 23b81e4..7c9a89f 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 @@ -25,7 +25,6 @@ import javax.annotation.concurrent.Immutable; public final class Issue { private final String key; private final String componentKey; - private final Integer line; private final String message; private final String ruleKey; private final String ruleName; @@ -35,13 +34,16 @@ public final class Issue { private final String assigneeLogin; private final String assigneeName; private final String severity; + private final Integer startLine; + private final Integer startLineOffset; + private final Integer endLine; + private final Integer endLineOffset; - 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) { + private Issue(String key, String componentKey, String message, String ruleKey, String ruleName, String status, String resolution, boolean isNew, + String assigneeLogin, String assigneeName, String severity, Integer startLine, Integer startLineOffset, Integer endLine, Integer endLineOffset) { super(); this.key = key; this.componentKey = componentKey; - this.line = line; this.message = message; this.ruleKey = ruleKey; this.ruleName = ruleName; @@ -51,12 +53,15 @@ public final class Issue { this.assigneeLogin = assigneeLogin; this.assigneeName = assigneeName; this.severity = severity; + this.startLine = startLine; + this.startLineOffset = startLineOffset; + this.endLine = endLine; + this.endLineOffset = endLineOffset; } public static class Builder { private String key; private String componentKey; - private Integer line; private String message; private String ruleKey; private String ruleName; @@ -66,6 +71,46 @@ public final class Issue { private String assigneeLogin; private String assigneeName; private String severity; + private Integer startLine; + private Integer startLineOffset; + private Integer endLine; + private Integer endLineOffset; + + public Integer getStartLine() { + return startLine; + } + + public Builder setStartLine(Integer startLine) { + this.startLine = startLine; + return this; + } + + public Integer getStartLineOffset() { + return startLineOffset; + } + + public Builder setStartLineOffset(Integer startLineOffset) { + this.startLineOffset = startLineOffset; + return this; + } + + public Integer getEndLine() { + return endLine; + } + + public Builder setEndLine(Integer endLine) { + this.endLine = endLine; + return this; + } + + public Integer getEndLineOffset() { + return endLineOffset; + } + + public Builder setEndLineOffset(Integer endLineOffset) { + this.endLineOffset = endLineOffset; + return this; + } public String getKey() { return key; @@ -85,15 +130,6 @@ public final class Issue { return this; } - public Integer getLine() { - return line; - } - - public Builder setLine(Integer line) { - this.line = line; - return this; - } - public String getMessage() { return message; } @@ -176,7 +212,8 @@ public final class Issue { } public Issue build() { - return new Issue(key, componentKey, line, message, ruleKey, ruleName, status, resolution, isNew, assigneeLogin, assigneeName, severity); + return new Issue(key, componentKey, message, ruleKey, ruleName, status, resolution, isNew, assigneeLogin, + assigneeName, severity, startLine, startLineOffset, endLine, endLineOffset); } } @@ -192,8 +229,26 @@ public final class Issue { return componentKey; } - public Integer getLine() { - return line; + public Integer getStartLine() { + return startLine; + } + + /** + * @return null if it isn't supported by the sonar-batch being used (< 5.3). + */ + public Integer getStartLineOffset() { + return startLineOffset; + } + + public Integer getEndLine() { + return endLine; + } + + /** + * @return null if it isn't supported by the sonar-batch being used (< 5.3). + */ + public Integer getEndLineOffset() { + return endLineOffset; } public String getMessage() { diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/IssueListenerAdapter.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/IssueListenerAdapter.java index 88b1879..cb14175 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/api/IssueListenerAdapter.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/IssueListenerAdapter.java @@ -38,7 +38,6 @@ class IssueListenerAdapter implements org.sonar.runner.batch.IssueListener { 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()); @@ -46,6 +45,10 @@ class IssueListenerAdapter implements org.sonar.runner.batch.IssueListener { issueBuilder.setRuleName(batchIssue.getRuleName()); issueBuilder.setSeverity(batchIssue.getSeverity()); issueBuilder.setStatus(batchIssue.getStatus()); + issueBuilder.setStartLine(batchIssue.getStartLine()); + issueBuilder.setStartLineOffset(batchIssue.getStartLineOffset()); + issueBuilder.setEndLine(batchIssue.getEndLine()); + issueBuilder.setEndLineOffset(batchIssue.getEndLineOffset()); return issueBuilder.build(); } -- cgit v1.2.3