diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-07-16 10:52:00 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-07-16 15:47:03 +0200 |
commit | 3c25a824164a3f091a27215fd8086cbefd60da39 (patch) | |
tree | b3c918d8b5d46076e6a57c1ea9491a3e207c86bf /sonar-plugin-api/src | |
parent | 3ecc736b43a6d0e85fd4b4089c3dcad53f8640ec (diff) | |
download | sonarqube-3c25a824164a3f091a27215fd8086cbefd60da39.tar.gz sonarqube-3c25a824164a3f091a27215fd8086cbefd60da39.zip |
SONAR-5001 Update API, ES and WS to support Markdown in rule descriptions
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java index 885c2d5265f..2076fd07b52 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java @@ -20,13 +20,7 @@ package org.sonar.api.server.rule; import com.google.common.base.Strings; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSortedSet; -import com.google.common.collect.ListMultimap; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; +import com.google.common.collect.*; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.LoggerFactory; @@ -519,7 +513,7 @@ public interface RulesDefinition extends ServerExtension { class NewRule { private final String repoKey, key; - private String name, htmlDescription, internalKey, severity = Severity.MAJOR; + private String name, htmlDescription, markdownDescription, internalKey, severity = Severity.MAJOR; private boolean template; private RuleStatus status = RuleStatus.defaultStatus(); private String debtSubCharacteristic; @@ -561,6 +555,9 @@ public interface RulesDefinition extends ServerExtension { } public NewRule setHtmlDescription(@Nullable String s) { + if (markdownDescription != null) { + throw new IllegalStateException(String.format("Rule '%s' already has a Markdown description", this)); + } this.htmlDescription = StringUtils.trimToNull(s); return this; } @@ -581,6 +578,30 @@ public interface RulesDefinition extends ServerExtension { return this; } + public NewRule setMarkdownDescription(@Nullable String s) { + if (htmlDescription != null) { + throw new IllegalStateException(String.format("Rule '%s' already has an HTML description", this)); + } + this.markdownDescription = StringUtils.trimToNull(s); + return this; + } + + /** + * Load description from a file available in classpath. Example : <code>setMarkdownDescription(getClass().getResource("/myrepo/Rule1234.md")</code> + */ + public NewRule setMarkdownDescription(@Nullable URL classpathUrl) { + if (classpathUrl != null) { + try { + setMarkdownDescription(IOUtils.toString(classpathUrl)); + } catch (IOException e) { + throw new IllegalStateException("Fail to read: " + classpathUrl, e); + } + } else { + this.markdownDescription = null; + } + return this; + } + /** * Default value is {@link org.sonar.api.rule.RuleStatus#READY}. The value * {@link org.sonar.api.rule.RuleStatus#REMOVED} is not accepted and raises an @@ -702,7 +723,7 @@ public interface RulesDefinition extends ServerExtension { @Immutable class Rule { private final Repository repository; - private final String repoKey, key, name, htmlDescription, internalKey, severity; + private final String repoKey, key, name, htmlDescription, markdownDescription, internalKey, severity; private final boolean template; private final String debtSubCharacteristic; private final DebtRemediationFunction debtRemediationFunction; @@ -717,6 +738,7 @@ public interface RulesDefinition extends ServerExtension { this.key = newRule.key; this.name = newRule.name; this.htmlDescription = newRule.htmlDescription; + this.markdownDescription = newRule.markdownDescription; this.internalKey = newRule.internalKey; this.severity = newRule.severity; this.template = newRule.template; @@ -753,6 +775,11 @@ public interface RulesDefinition extends ServerExtension { return htmlDescription; } + @CheckForNull + public String markdownDescription() { + return markdownDescription; + } + public boolean template() { return template; } |