summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java15
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java18
-rw-r--r--sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java3
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java17
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java30
8 files changed, 26 insertions, 65 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java
index c6f9bf8530a..992fb82ae91 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java
@@ -29,6 +29,8 @@ import org.sonar.api.config.Settings;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.platform.Server;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleFinder;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import org.sonar.api.user.User;
import org.sonar.api.user.UserFinder;
@@ -62,25 +64,25 @@ public class JsonReport implements BatchComponent {
private final Settings settings;
private final ModuleFileSystem fileSystem;
private final Server server;
- private final RuleI18nManager ruleI18nManager;
+ private final RuleFinder ruleFinder;
private final IssueCache issueCache;
private final EventBus eventBus;
private final ComponentSelector componentSelector;
private AnalysisMode analysisMode;
private UserFinder userFinder;
- public JsonReport(Settings settings, ModuleFileSystem fileSystem, Server server, RuleI18nManager ruleI18nManager, IssueCache issueCache,
+ public JsonReport(Settings settings, ModuleFileSystem fileSystem, Server server, RuleFinder ruleFinder, IssueCache issueCache,
EventBus eventBus, ComponentSelectorFactory componentSelectorFactory, AnalysisMode mode, UserFinder userFinder) {
- this(settings, fileSystem, server, ruleI18nManager, issueCache, eventBus, componentSelectorFactory.create(), mode, userFinder);
+ this(settings, fileSystem, server, ruleFinder, issueCache, eventBus, componentSelectorFactory.create(), mode, userFinder);
}
@VisibleForTesting
- JsonReport(Settings settings, ModuleFileSystem fileSystem, Server server, RuleI18nManager ruleI18nManager, IssueCache issueCache,
+ JsonReport(Settings settings, ModuleFileSystem fileSystem, Server server, RuleFinder ruleFinder, IssueCache issueCache,
EventBus eventBus, ComponentSelector componentSelector, AnalysisMode analysisMode, UserFinder userFinder) {
this.settings = settings;
this.fileSystem = fileSystem;
this.server = server;
- this.ruleI18nManager = ruleI18nManager;
+ this.ruleFinder = ruleFinder;
this.issueCache = issueCache;
this.eventBus = eventBus;
this.componentSelector = componentSelector;
@@ -216,7 +218,8 @@ public class JsonReport implements BatchComponent {
}
private String getRuleName(RuleKey ruleKey) {
- return ruleI18nManager.getName(ruleKey.repository(), ruleKey.rule());
+ Rule rule = ruleFinder.findByKey(ruleKey);
+ return rule != null ? rule.getName() : null;
}
@VisibleForTesting
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java
index 94cabfd72eb..0b0ce6bd1a1 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java
@@ -32,13 +32,13 @@ import org.sonar.api.platform.Server;
import org.sonar.api.resources.Resource;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleFinder;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import org.sonar.api.user.User;
import org.sonar.api.user.UserFinder;
import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.issue.IssueCache;
-import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.core.user.DefaultUser;
import org.sonar.test.TestUtils;
@@ -48,7 +48,6 @@ import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Locale;
import java.util.TimeZone;
import static org.fest.assertions.Assertions.assertThat;
@@ -67,7 +66,7 @@ public class JsonReportTest {
Resource resource = mock(Resource.class);
ModuleFileSystem fileSystem = mock(ModuleFileSystem.class);
Server server = mock(Server.class);
- RuleI18nManager ruleI18nManager = mock(RuleI18nManager.class);
+ RuleFinder ruleFinder = mock(RuleFinder.class);
Settings settings;
IssueCache issueCache = mock(IssueCache.class);
private AnalysisMode mode;
@@ -83,7 +82,7 @@ public class JsonReportTest {
mode = mock(AnalysisMode.class);
when(mode.isPreview()).thenReturn(true);
userFinder = mock(UserFinder.class);
- jsonReport = new JsonReport(settings, fileSystem, server, ruleI18nManager, issueCache, mock(EventBus.class), new DefaultComponentSelector(), mode, userFinder);
+ jsonReport = new JsonReport(settings, fileSystem, server, ruleFinder, issueCache, mock(EventBus.class), new DefaultComponentSelector(), mode, userFinder);
}
@Test
@@ -103,7 +102,7 @@ public class JsonReportTest {
.setCreationDate(SIMPLE_DATE_FORMAT.parse("2013-04-24"))
.setUpdateDate(SIMPLE_DATE_FORMAT.parse("2013-04-25"))
.setNew(false);
- when(ruleI18nManager.getName("squid", "AvoidCycles", Locale.getDefault())).thenReturn("Avoid Cycles");
+ when(ruleFinder.findByKey(RuleKey.of("squid", "AvoidCycles"))).thenReturn(new Rule().setName("Avoid Cycles"));
when(jsonReport.getIssues()).thenReturn(Lists.<DefaultIssue>newArrayList(issue));
DefaultUser user1 = new DefaultUser().setLogin("julien").setName("Julien");
DefaultUser user2 = new DefaultUser().setLogin("simon").setName("Simon");
@@ -118,17 +117,18 @@ public class JsonReportTest {
@Test
public void should_exclude_resolved_issues() throws Exception {
+ RuleKey ruleKey = RuleKey.of("squid", "AvoidCycles");
DefaultIssue issue = new DefaultIssue()
.setKey("200")
.setComponentKey("struts:org.apache.struts.Action")
- .setRuleKey(RuleKey.of("squid", "AvoidCycles"))
+ .setRuleKey(ruleKey)
.setStatus(Issue.STATUS_CLOSED)
.setResolution(Issue.RESOLUTION_FIXED)
.setCreationDate(SIMPLE_DATE_FORMAT.parse("2013-04-24"))
.setUpdateDate(SIMPLE_DATE_FORMAT.parse("2013-04-25"))
.setCloseDate(SIMPLE_DATE_FORMAT.parse("2013-04-26"))
.setNew(false);
- when(ruleI18nManager.getName("squid", "AvoidCycles", Locale.getDefault())).thenReturn("Avoid Cycles");
+ when(ruleFinder.findByKey(ruleKey)).thenReturn(Rule.create(ruleKey.repository(), ruleKey.rule()).setName("Avoid Cycles"));
when(jsonReport.getIssues()).thenReturn(Lists.<DefaultIssue>newArrayList(issue));
StringWriter writer = new StringWriter();
@@ -152,8 +152,8 @@ public class JsonReportTest {
public void should_export_issues_to_file() throws IOException {
File sonarDirectory = temporaryFolder.newFolder("sonar");
- Rule rule = Rule.create("squid", "AvoidCycles");
- when(ruleI18nManager.getName(rule, Locale.getDefault())).thenReturn("Avoid Cycles");
+ Rule rule = Rule.create("squid", "AvoidCycles").setName("Avoid Cycles");
+ when(ruleFinder.findByKey(RuleKey.of("squid", "AvoidCycles"))).thenReturn(rule);
when(jsonReport.getIssues()).thenReturn(Collections.<DefaultIssue>emptyList());
settings.setProperty("sonar.report.export.path", "output.json");
diff --git a/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java b/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java
index b518d67164d..992a8ea637b 100644
--- a/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java
+++ b/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java
@@ -63,7 +63,8 @@ public class ChannelDispatcherTest {
private static class FakeChannel extends Channel<StringBuilder> {
@Override
public boolean consume(CodeReader code, StringBuilder output) {
- return true;
+ boolean b = true;
+ return b;
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java b/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java
index e2807da24c6..639225b7124 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java
@@ -46,23 +46,6 @@ public class RubyRuleService implements ServerComponent, Startable {
this.ruleRegistry = ruleRegistry;
}
- @CheckForNull
- public String ruleL10nName(Rule rule) {
- String name = i18n.getName(rule.getRepositoryKey(), rule.getKey());
- if (name == null) {
- name = rule.getName();
- }
- return name;
- }
-
- public String ruleL10nDescription(Rule rule) {
- String desc = i18n.getDescription(rule.getRepositoryKey(), rule.getKey());
- if (desc == null) {
- desc = rule.getDescription();
- }
- return desc;
- }
-
public Integer[] findIds(Map<String, String> options) {
Map<String, String> params = Maps.newHashMap();
translateNonBlankKey(options, params, OPTIONS_STATUS, OPTIONS_STATUS);
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb
index 778e58ca98e..0ee770cc918 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb
@@ -70,7 +70,7 @@ class Api::ViolationsController < Api::ApiController
hash[:switchedOff]=true if issue.resolution=='FALSE-POSITIVE'
rule = results.rule(issue)
if rule
- hash[:rule] = {:key => rule.ruleKey.toString(), :name => Internal.rules.ruleL10nName(rule)}
+ hash[:rule] = {:key => rule.ruleKey.toString(), :name => rule.getName()}
end
resource = results.component(issue)
if resource
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
index fb3f5ab8baa..97d1bf5bba3 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
@@ -189,8 +189,8 @@ class Rule < ActiveRecord::Base
end
def self.to_hash(java_rule)
- l10n_name = Internal.rules.ruleL10nName(java_rule)
- l10n_desc = Internal.rules.ruleL10nDescription(java_rule)
+ l10n_name = java_rule.getName()
+ l10n_desc = java_rule.getDescription()
hash = {:key => java_rule.ruleKey().toString()}
hash[:name] = l10n_name if l10n_name
hash[:desc] = l10n_desc if l10n_desc
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb
index caa3053f748..8f7e4236b32 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb
@@ -6,7 +6,7 @@
<img src="<%= ApplicationController.root_context -%>/images/priority/<%= issue.severity -%>.png" title="<%= h message("severity.#{issue.severity}") -%>">
&nbsp;
- <a href="#" onclick="return toggleIssueRule(this)" class="rulename issue-rule-link"><%= h Internal.rules.ruleL10nName(@issue_results.rule(issue)) -%></a>
+ <a href="#" onclick="return toggleIssueRule(this)" class="rulename issue-rule-link"><%= h @issue_results.rule(issue).getName() -%></a>
&nbsp;
<% if issue.resolution %>
<img src="<%= ApplicationController.root_context -%>/images/sep12.png"/>
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java
index 153b2a74ed6..05401792eb5 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java
@@ -22,17 +22,13 @@ package org.sonar.server.rule;
import com.google.common.collect.Maps;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.rules.Rule;
import org.sonar.core.i18n.RuleI18nManager;
-import org.sonar.server.user.MockUserSession;
-import java.util.Locale;
import java.util.Map;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
public class RubyRuleServiceTest {
@@ -41,29 +37,7 @@ public class RubyRuleServiceTest {
RubyRuleService facade = new RubyRuleService(i18n, ruleRegistry);
@Test
- public void should_get_raw_name_if_no_l10n_name() throws Exception {
- MockUserSession.set().setLocale(Locale.FRENCH);
- when(i18n.getName("squid", "AvoidCycle", Locale.FRENCH)).thenReturn(null);
-
- Rule rule = new Rule("squid", "AvoidCycle");
- rule.setName("Avoid cycles");
- String name = facade.ruleL10nName(rule);
- assertThat(name).isEqualTo("Avoid cycles");
- }
-
- @Test
- public void should_get_raw_description_if_no_l10n_description() throws Exception {
- MockUserSession.set().setLocale(Locale.FRENCH);
- when(i18n.getDescription("squid", "AvoidCycle", Locale.FRENCH)).thenReturn(null);
-
- Rule rule = new Rule("squid", "AvoidCycle");
- rule.setDescription("Cycles are evil");
- String desc = facade.ruleL10nDescription(rule);
- assertThat(desc).isEqualTo("Cycles are evil");
- }
-
- @Test
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings({"unchecked", "rawtypes"})
public void should_translate_arguments_ind_find_ids() {
Map<String, String> options = Maps.newHashMap();
String status = " ";
@@ -73,7 +47,7 @@ public class RubyRuleServiceTest {
options.put("status", status);
options.put("repositories", repositories);
// language not specified to cover blank option case
- options.put("searchtext", searchText );
+ options.put("searchtext", searchText);
facade.findIds(options);
ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);