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);
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) {
return propertyToBundles.keySet();
}
+ @CheckForNull
private String formatMessage(@Nullable String message, Object... parameters) {
if (message == null || parameters.length == 0) {
return message;
import org.sonar.api.i18n.RuleI18n;
import org.sonar.api.rules.Rule;
+import javax.annotation.CheckForNull;
+
import java.util.List;
import java.util.Locale;
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();
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);
--- /dev/null
+/*
+ * 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;
\ No newline at end of file
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
import java.util.Locale;
/**
* @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);
}
import org.sonar.api.ServerComponent;
import org.sonar.api.rules.Rule;
+import javax.annotation.CheckForNull;
+
import java.util.Locale;
/**
* @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);
/**
* @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);
/**
* @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);
}
--- /dev/null
+/*
+ * 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;
\ No newline at end of file
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;
this.id = id;
}
+ @CheckForNull
public String getName() {
return name;
}
/**
* Sets the rule name
*/
- public Rule setName(String name) {
+ public Rule setName(@Nullable String name) {
this.name = removeNewLineCharacters(name);
return this;
}
.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");
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.server.user.UserSession;
+import javax.annotation.CheckForNull;
+
/**
* Used through ruby code <pre>Internal.rules</pre>
*/
this.i18n = i18n;
}
+ @CheckForNull
public String ruleL10nName(Rule rule) {
String name = i18n.getName(rule.getRepositoryKey(), rule.getKey(), UserSession.get().locale());
if (name == null) {
--- /dev/null
+/*
+ * 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;
\ No newline at end of file