@@ -31,17 +31,13 @@ import org.sonar.api.platform.PluginMetadata; | |||
import org.sonar.api.platform.PluginRepository; | |||
import org.sonar.api.utils.SonarException; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.text.MessageFormat; | |||
import java.util.Enumeration; | |||
import java.util.Locale; | |||
import java.util.Map; | |||
import java.util.MissingResourceException; | |||
import java.util.ResourceBundle; | |||
import java.util.Set; | |||
import java.util.*; | |||
public class I18nManager implements I18n, ServerExtension, BatchExtension { | |||
private static final Logger LOG = LoggerFactory.getLogger(I18nManager.class); | |||
@@ -87,7 +83,8 @@ public class I18nManager implements I18n, ServerExtension, BatchExtension { | |||
fileContentCache=null; | |||
} | |||
public String message(Locale locale, String key, String defaultValue, Object... parameters) { | |||
@CheckForNull | |||
public String message(Locale locale, String key, @Nullable String defaultValue, Object... parameters) { | |||
String bundleKey = propertyToBundles.get(key); | |||
String value = null; | |||
if (bundleKey != null) { | |||
@@ -159,6 +156,7 @@ public class I18nManager implements I18n, ServerExtension, BatchExtension { | |||
return propertyToBundles.keySet(); | |||
} | |||
@CheckForNull | |||
private String formatMessage(@Nullable String message, Object... parameters) { | |||
if (message == null || parameters.length == 0) { | |||
return message; |
@@ -26,6 +26,8 @@ import org.sonar.api.ServerExtension; | |||
import org.sonar.api.i18n.RuleI18n; | |||
import org.sonar.api.rules.Rule; | |||
import javax.annotation.CheckForNull; | |||
import java.util.List; | |||
import java.util.Locale; | |||
@@ -51,10 +53,12 @@ public class RuleI18nManager implements RuleI18n, ServerExtension, BatchExtensio | |||
this.ruleKeys = list.toArray(new RuleKey[list.size()]); | |||
} | |||
@CheckForNull | |||
public String getName(String repositoryKey, String ruleKey, Locale locale) { | |||
return message(repositoryKey, ruleKey, locale, NAME_SUFFIX); | |||
} | |||
@CheckForNull | |||
public String getName(Rule rule, Locale locale) { | |||
String name = message(rule.getRepositoryKey(), rule.getKey(), locale, NAME_SUFFIX); | |||
return name != null ? name : rule.getName(); | |||
@@ -92,10 +96,12 @@ public class RuleI18nManager implements RuleI18n, ServerExtension, BatchExtensio | |||
return description; | |||
} | |||
@CheckForNull | |||
public String getParamDescription(String repositoryKey, String ruleKey, String paramKey, Locale locale) { | |||
return message(repositoryKey, ruleKey, locale, ".param." + paramKey); | |||
} | |||
@CheckForNull | |||
String message(String repositoryKey, String ruleKey, Locale locale, String suffix) { | |||
String propertyKey = new StringBuilder().append(RULE_PREFIX).append(repositoryKey).append(".").append(ruleKey).append(suffix).toString(); | |||
return i18nManager.message(locale, propertyKey, null); |
@@ -0,0 +1,23 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2013 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.core.i18n; | |||
import javax.annotation.ParametersAreNonnullByDefault; |
@@ -22,6 +22,9 @@ package org.sonar.api.i18n; | |||
import org.sonar.api.BatchComponent; | |||
import org.sonar.api.ServerComponent; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import java.util.Locale; | |||
/** | |||
@@ -45,6 +48,7 @@ public interface I18n extends ServerComponent, BatchComponent { | |||
* @param parameters the parameters used to format the message from the translated pattern. | |||
* @return the message formatted with the translated pattern and the given parameters | |||
*/ | |||
String message(final Locale locale, final String key, final String defaultValue, final Object... parameters); | |||
@CheckForNull | |||
String message(final Locale locale, final String key, @Nullable final String defaultValue, final Object... parameters); | |||
} |
@@ -23,6 +23,8 @@ import org.sonar.api.BatchComponent; | |||
import org.sonar.api.ServerComponent; | |||
import org.sonar.api.rules.Rule; | |||
import javax.annotation.CheckForNull; | |||
import java.util.Locale; | |||
/** | |||
@@ -43,6 +45,7 @@ public interface RuleI18n extends ServerComponent, BatchComponent { | |||
* @param locale the locale to translate into | |||
* @return the translated name of the rule, or the default English one if the given locale is not supported, or null | |||
*/ | |||
@CheckForNull | |||
String getName(String repositoryKey, String ruleKey, Locale locale); | |||
/** | |||
@@ -55,6 +58,7 @@ public interface RuleI18n extends ServerComponent, BatchComponent { | |||
* @param locale the locale to translate into | |||
* @return the translated name of the rule, or the default English one if the given locale is not supported, or the rule name. | |||
*/ | |||
@CheckForNull | |||
String getName(Rule rule, Locale locale); | |||
/** | |||
@@ -83,6 +87,7 @@ public interface RuleI18n extends ServerComponent, BatchComponent { | |||
* @return the translated name of the rule parameter, or the default English one if the given locale is not supported, or null if | |||
* no translation can be found. | |||
*/ | |||
@CheckForNull | |||
String getParamDescription(String repositoryKey, String ruleKey, String paramKey, Locale locale); | |||
} |
@@ -0,0 +1,23 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2013 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.api.i18n; | |||
import javax.annotation.ParametersAreNonnullByDefault; |
@@ -32,6 +32,8 @@ import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.utils.SonarException; | |||
import org.sonar.check.Cardinality; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import javax.persistence.*; | |||
import java.util.ArrayList; | |||
@@ -205,6 +207,7 @@ public final class Rule { | |||
this.id = id; | |||
} | |||
@CheckForNull | |||
public String getName() { | |||
return name; | |||
} | |||
@@ -212,7 +215,7 @@ public final class Rule { | |||
/** | |||
* Sets the rule name | |||
*/ | |||
public Rule setName(String name) { | |||
public Rule setName(@Nullable String name) { | |||
this.name = removeNewLineCharacters(name); | |||
return this; | |||
} | |||
@@ -504,7 +507,8 @@ public final class Rule { | |||
.toString(); | |||
} | |||
private String removeNewLineCharacters(String text) { | |||
@CheckForNull | |||
private String removeNewLineCharacters(@Nullable String text) { | |||
String removedCRLF = StringUtils.remove(text, "\n"); | |||
removedCRLF = StringUtils.remove(removedCRLF, "\r"); | |||
removedCRLF = StringUtils.remove(removedCRLF, "\n\r"); |
@@ -25,6 +25,8 @@ import org.sonar.api.rules.Rule; | |||
import org.sonar.core.i18n.RuleI18nManager; | |||
import org.sonar.server.user.UserSession; | |||
import javax.annotation.CheckForNull; | |||
/** | |||
* Used through ruby code <pre>Internal.rules</pre> | |||
*/ | |||
@@ -36,6 +38,7 @@ public class RubyRuleService implements ServerComponent, Startable { | |||
this.i18n = i18n; | |||
} | |||
@CheckForNull | |||
public String ruleL10nName(Rule rule) { | |||
String name = i18n.getName(rule.getRepositoryKey(), rule.getKey(), UserSession.get().locale()); | |||
if (name == null) { |
@@ -0,0 +1,23 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2013 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.server.rule; | |||
import javax.annotation.ParametersAreNonnullByDefault; |