summaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2012-12-04 11:59:12 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2012-12-04 11:59:12 +0100
commit034013c4aefee3ffbf158caf1489d261ae5bf4b9 (patch)
tree73f6e5a485e4a0498439567f31ae5b0ae08eb082 /sonar-core
parenta0b9f5612d661375fc6fa8e8c97a9b0a5dcd7ff7 (diff)
downloadsonarqube-034013c4aefee3ffbf158caf1489d261ae5bf4b9.tar.gz
sonarqube-034013c4aefee3ffbf158caf1489d261ae5bf4b9.zip
SONARIDE-334 Title is not displayed for some rules
RuleI18nManager has now a new method to get the rule name by searching the name in the i18n, and then if not found return the rule name property.
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java6
-rw-r--r--sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java39
2 files changed, 33 insertions, 12 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java b/sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java
index bf396aee978..00ed8a789a7 100644
--- a/sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java
+++ b/sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java
@@ -24,6 +24,7 @@ import org.apache.commons.lang.StringUtils;
import org.sonar.api.BatchExtension;
import org.sonar.api.ServerExtension;
import org.sonar.api.i18n.RuleI18n;
+import org.sonar.api.rules.Rule;
import java.util.List;
import java.util.Locale;
@@ -54,6 +55,11 @@ public class RuleI18nManager implements RuleI18n, ServerExtension, BatchExtensio
return message(repositoryKey, ruleKey, locale, NAME_SUFFIX);
}
+ public String getName(Rule rule, Locale locale) {
+ String name = message(rule.getRepositoryKey(), rule.getKey(), locale, NAME_SUFFIX);
+ return name != null ? name : rule.getName();
+ }
+
public String getDescription(String repositoryKey, String ruleKey, Locale locale) {
String relatedProperty = new StringBuilder().append(RULE_PREFIX).append(repositoryKey).append(".").append(ruleKey).append(NAME_SUFFIX).toString();
diff --git a/sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java b/sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java
index 4a6f17c82bf..81804e2490e 100644
--- a/sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java
@@ -19,6 +19,16 @@
*/
package org.sonar.core.i18n;
+import com.google.common.collect.Sets;
+import org.fest.assertions.Assertions;
+import org.hamcrest.core.Is;
+import org.junit.Test;
+import org.sonar.api.rules.Rule;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@@ -28,16 +38,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Locale;
-
-import org.hamcrest.core.Is;
-import org.junit.Test;
-
-import com.google.common.collect.Sets;
-
public class RuleI18nManagerTest {
+
@Test
public void shouldGetName() {
I18nManager i18n = mock(I18nManager.class);
@@ -51,6 +53,19 @@ public class RuleI18nManagerTest {
}
@Test
+ public void shouldGetRuleNameIfNoLocalizationFound() {
+ String propertyKey = "rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.name";
+ I18nManager i18n = mock(I18nManager.class);
+ when(i18n.message(Locale.ENGLISH, propertyKey, null)).thenReturn(null);
+ RuleI18nManager ruleI18n = new RuleI18nManager(i18n);
+
+ String ruleName = "RULE_NAME";
+ Rule rule = Rule.create("checkstyle", "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck", ruleName);
+ String name = ruleI18n.getName(rule, Locale.ENGLISH);
+ Assertions.assertThat(name).isEqualTo(ruleName);
+ }
+
+ @Test
public void shouldGetParamDescription() {
I18nManager i18n = mock(I18nManager.class);
RuleI18nManager ruleI18n = new RuleI18nManager(i18n);
@@ -65,7 +80,7 @@ public class RuleI18nManagerTest {
@Test
public void shouldGetDescriptionFromFile() {
String propertyKeyForName = "rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.name";
-
+
I18nManager i18n = mock(I18nManager.class);
when(i18n.messageFromFile(Locale.ENGLISH, "rules/checkstyle/com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.html", propertyKeyForName, true)).thenReturn("Description");
@@ -81,7 +96,7 @@ public class RuleI18nManagerTest {
@Test
public void shouldGetDescriptionFromFileWithBackwardCompatibility() {
String propertyKeyForName = "rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.name";
-
+
I18nManager i18n = mock(I18nManager.class);
// this is the "old" way of storing HTML description files for rules (they are not in the "rules/<repo-key>" folder)
when(i18n.messageFromFile(Locale.ENGLISH, "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.html", propertyKeyForName, true)).thenReturn("Description");
@@ -99,7 +114,7 @@ public class RuleI18nManagerTest {
@Test
public void shouldGetDescriptionFromFileWithBackwardCompatibilityWithSpecificLocale() {
String propertyKeyForName = "rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.name";
-
+
I18nManager i18n = mock(I18nManager.class);
// this is the "old" way of storing HTML description files for rules (they are not in the "rules/<repo-key>" folder)
when(i18n.messageFromFile(Locale.ENGLISH, "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.html", propertyKeyForName, true)).thenReturn("Description");