diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-08-24 13:23:12 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-08-24 13:23:50 +0200 |
commit | d172a42d012bc511fdbf43d9de826d0c69388fe5 (patch) | |
tree | ac5f2748c48cf8cfd1336d75a63b02ae0283d13c /sonar-plugin-api | |
parent | a2492ffc12f418771cec9d0164ff30a22d60ffd6 (diff) | |
download | sonarqube-d172a42d012bc511fdbf43d9de826d0c69388fe5.tar.gz sonarqube-d172a42d012bc511fdbf43d9de826d0c69388fe5.zip |
SONAR-4865 Do not fail when issue message is greater than 4000 (just truncate)
Diffstat (limited to 'sonar-plugin-api')
3 files changed, 12 insertions, 13 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java index 5538e155b7b..e4c3b73ba85 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java @@ -39,6 +39,8 @@ import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.batch.sensor.issue.NewIssueLocation; import org.sonar.api.rule.RuleKey; +import static java.lang.String.format; + public class DefaultIssue extends DefaultStorable implements Issue, NewIssue { private static final class ToExecutionFlow implements Function<List<IssueLocation>, ExecutionFlow> { @@ -77,6 +79,7 @@ public class DefaultIssue extends DefaultStorable implements Issue, NewIssue { @Override public DefaultIssue effortToFix(@Nullable Double effortToFix) { + Preconditions.checkArgument(effortToFix == null || effortToFix >= 0, format("Effort to fix must be greater than or equal 0 (got %s)", effortToFix)); this.effortToFix = effortToFix; return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueLocation.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueLocation.java index df800a0bba2..36673218db0 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueLocation.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueLocation.java @@ -20,6 +20,7 @@ package org.sonar.api.batch.sensor.issue.internal; import com.google.common.base.Preconditions; +import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.fs.TextRange; import org.sonar.api.batch.fs.internal.DefaultInputFile; @@ -33,7 +34,7 @@ public class DefaultIssueLocation implements NewIssueLocation, IssueLocation { private String message; @Override - public NewIssueLocation on(InputComponent component) { + public DefaultIssueLocation on(InputComponent component) { Preconditions.checkArgument(component != null, "Component can't be null"); Preconditions.checkState(this.component == null, "on() already called"); this.component = component; @@ -53,9 +54,7 @@ public class DefaultIssueLocation implements NewIssueLocation, IssueLocation { @Override public DefaultIssueLocation message(String message) { Preconditions.checkNotNull(message, "Message can't be null"); - Preconditions.checkArgument(message.length() <= MESSAGE_MAX_SIZE, - "Message of an issue can't be greater than " + MESSAGE_MAX_SIZE + ": [" + message + "] size is " + message.length()); - this.message = message; + this.message = StringUtils.abbreviate(StringUtils.trim(message), MESSAGE_MAX_SIZE); return this; } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueLocationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueLocationTest.java index cffb6367baf..f5d11c26a07 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueLocationTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueLocationTest.java @@ -27,6 +27,8 @@ import org.junit.rules.ExpectedException; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.FileMetadata; +import static org.assertj.core.api.Assertions.assertThat; + public class DefaultIssueLocationTest { @Rule @@ -46,18 +48,13 @@ public class DefaultIssueLocationTest { @Test public void prevent_too_long_messages() { - new DefaultIssueLocation() + assertThat(new DefaultIssueLocation() .on(inputFile) - .message(StringUtils.repeat("a", 4000)); - - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Message of an issue can't be greater than 4000: [aaa"); - thrown.expectMessage("aaa] size is 4001"); + .message(StringUtils.repeat("a", 4000)).message()).hasSize(4000); - new DefaultIssueLocation() + assertThat(new DefaultIssueLocation() .on(inputFile) - .message(StringUtils.repeat("a", 4001)); - + .message(StringUtils.repeat("a", 4001)).message()).hasSize(4000); } } |