diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-05-13 15:21:23 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-05-18 11:48:30 +0200 |
commit | 73c7ffd633528d129258360f4d85c64fec4ec5ea (patch) | |
tree | 5c3d5200a0c193ce7c3ec2803dc0e05db565269e /sonar-core | |
parent | 5076cc2f6b9c421359a1c711a20f9d1965226cec (diff) | |
download | sonarqube-73c7ffd633528d129258360f4d85c64fec4ec5ea.tar.gz sonarqube-73c7ffd633528d129258360f4d85c64fec4ec5ea.zip |
SONAR-7635 Sanitize metric name and description in default l10n bundle and CoreMetrics
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/resources/org/sonar/l10n/core.properties | 60 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java | 109 |
2 files changed, 112 insertions, 57 deletions
diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 442e81d8f83..fbe76868fa2 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -506,8 +506,7 @@ deletion.page=Deletion project_deletion.page=Delete {0} project_deletion.page.description=Delete this project from the SonarQube database. provisioning.page=Provisioning -provisioning.page.description=Use this page to initialize projects if you would like to configure them before the first analysis. \ - Once a project is provisioned, you have access to perform all project configurations on it. +provisioning.page.description=Use this page to initialize projects if you would like to configure them before the first analysis. Once a project is provisioned, you have access to perform all project configurations on it. #------------------------------------------------------------------------------ # @@ -2246,10 +2245,21 @@ metric.complexity.name=Complexity metric.complexity.description=Cyclomatic complexity metric.complexity.abbreviation=Cmpx +metric.complexity_in_classes.name=Complexity in Classes +metric.complexity_in_classes.description=Cyclomatic complexity in classes + +metric.complexity_in_functions.name=Complexity in Functions +metric.complexity_in_functions.description=Cyclomatic complexity in functions + +metric.development_cost.name=SQALE Development Cost + metric.directories.name=Directories metric.directories.description=Directories metric.directories.abbreviation=Dirs +metric.effort_to_reach_maintainability_rating_a.name=Effort to Reach Maintainability Rating A +metric.effort_to_reach_maintainability_rating_a.description=Effort to reach maintainability rating A + metric.files.name=Files metric.files.description=Number of files @@ -2266,17 +2276,31 @@ metric.generated_ncloc.name.suffix=generated lines of code metric.generated_ncloc.description=Generated non Commenting Lines of Code metric.generated_ncloc.abbreviation=Gen. LOC +metric.last_commit_date.name=Date of Last Commit + metric.lines.name=Lines metric.lines.description=Lines +metric.new_reliability_remediation_effort.name=Reliability Remediation Effort on New Code +metric.new_reliability_remediation_effort.description=Reliability remediation effort on new code + +metric.new_security_remediation_effort.name=Security Remediation Effort on New Code +metric.new_security_remediation_effort.description=Security remediation effort on new code + metric.ncloc.name=Lines of Code metric.ncloc.description=Non Commenting Lines of Code metric.ncloc.abbreviation=LOC +metric.ncloc_language_distribution.name=Lines of Code Per Language +metric.ncloc_language_distribution.description=Non Commenting Lines of Code Distributed By Language + metric.packages.name=Packages metric.packages.description=Packages metric.packages.abbreviation=Pkgs +metric.projects.name=Projects +metric.projects.description=Number of projects + metric.public_api.name=Public API metric.public_api.description=Public API @@ -2288,6 +2312,18 @@ metric.public_undocumented_api.name=Public Undocumented API metric.public_undocumented_api.description=Public undocumented classes, functions and variables metric.public_undocumented_api.abbreviation=Pub. undoc. API +metric.quality_gate_details.name=Quality Gate Details +metric.quality_gate_details.description=The project detailed status with regard to its quality gate + +metric.quality_profiles.name=Profiles +metric.quality_profiles.description=Details of quality profiles used during analysis + +metric.reliability_rating.description=Reliability rating +metric.reliability_remediation_effort.description=Reliability Remediation Effort + +metric.security_rating.description=Security rating +metric.security_remediation_effort.description=Security remediation effort + metric.statements.name=Statements metric.statements.description=Number of statements metric.statements.abbreviation=Stmts @@ -2732,16 +2768,10 @@ metric.profile_version.name=Profile Version metric.profile_version.description=Selected quality profile version -#-------------------------------------------------------------------------------------------------------------------- -# -# ISSUES METRICS -# -#-------------------------------------------------------------------------------------------------------------------- - metric.false_positive_issues.name=False Positive Issues metric.false_positive_issues.description=False positive issues -metric.wont_fix_issues.name=Won't Fix Issues +metric.wont_fix_issues.name=Won't Fix Issues metric.wont_fix_issues.description=Won't fix issues metric.open_issues.name=Open Issues @@ -2754,26 +2784,20 @@ metric.confirmed_issues.name=Confirmed Issues metric.confirmed_issues.description=Confirmed issues -#-------------------------------------------------------------------------------------------------------------------- -# -# TECHNICAL DEBT METRICS -# -#-------------------------------------------------------------------------------------------------------------------- - metric.sqale_index.name=Technical Debt metric.sqale_index.short_name=Effort metric.sqale_index.description=Total effort (in days) to fix all the issues on the component and therefore to comply to all the requirements. metric.new_technical_debt.name=Added Technical Debt metric.new_technical_debt.short_name=Added Debt -metric.new_technical_debt.description=Added Technical Debt +metric.new_technical_debt.description=Added technical debt metric.sqale_rating.name=Maintainability Rating -metric.sqale_rating.description=A-to-E rating based on the technical debt ratio. +metric.sqale_rating.description=A-to-E rating based on the technical debt ratio metric.sqale_debt_ratio.name=Technical Debt Ratio metric.sqale_debt_ratio.short_name=Debt Ratio -metric.sqale_debt_ratio.description=Ratio of the actual technical debt compared to the estimated cost to develop the whole source code from scratch. +metric.sqale_debt_ratio.description=Ratio of the actual technical debt compared to the estimated cost to develop the whole source code from scratch metric.new_sqale_debt_ratio.name=Technical Debt Ratio on New Code metric.new_sqale_debt_ratio.short_name=Debt Ratio on new code diff --git a/sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java b/sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java index c1dfd378437..b53d5e10e12 100644 --- a/sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java +++ b/sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java @@ -19,6 +19,7 @@ */ package org.sonar.core.i18n; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -28,6 +29,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Metric; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.core.platform.PluginInfo; @@ -43,7 +46,7 @@ public class DefaultI18nTest { @Mock System2 system2; - DefaultI18n manager; + DefaultI18n underTest; @Before public void before() { @@ -51,29 +54,57 @@ public class DefaultI18nTest { List<PluginInfo> plugins = Arrays.asList(newPlugin("sqale"), newPlugin("frpack"), newPlugin("checkstyle"), newPlugin("other")); when(pluginRepository.getPluginInfos()).thenReturn(plugins); - manager = new DefaultI18n(pluginRepository, system2); - manager.doStart(getClass().getClassLoader()); + underTest = new DefaultI18n(pluginRepository, system2); + underTest.doStart(getClass().getClassLoader()); } @Test public void load_core_bundle() { - assertThat(manager.message(Locale.ENGLISH, "any", null)).isEqualTo("Any"); + assertThat(underTest.message(Locale.ENGLISH, "any", null)).isEqualTo("Any"); } @Test public void introspect_all_available_properties() { - assertThat(manager.getPropertyKeys().contains("any")).isTrue(); + assertThat(underTest.getPropertyKeys().contains("any")).isTrue(); // Only in english - assertThat(manager.getPropertyKeys().contains("assignee")).isTrue(); - assertThat(manager.getPropertyKeys().contains("sqale.page")).isTrue(); - assertThat(manager.getPropertyKeys().contains("bla_bla_bla")).isFalse(); + assertThat(underTest.getPropertyKeys().contains("assignee")).isTrue(); + assertThat(underTest.getPropertyKeys().contains("sqale.page")).isTrue(); + assertThat(underTest.getPropertyKeys().contains("bla_bla_bla")).isFalse(); + } + + @Test + public void all_core_metrics_are_in_core_bundle() { + List<Metric> coreMetrics = CoreMetrics.getMetrics(); + List<String> incorrectMetricDefinitions = new ArrayList<>(); + for (Metric metric : coreMetrics) { + if (metric.isHidden()) { + continue; + } + String metricNamePropertyKey = "metric." + metric.getKey() + ".name"; + String l10nMetricName = underTest.message(Locale.ENGLISH, metricNamePropertyKey, null); + if (l10nMetricName == null) { + incorrectMetricDefinitions.add(metricNamePropertyKey + "=" + metric.getName()); + } else if (!l10nMetricName.equals(metric.getName())) { + incorrectMetricDefinitions.add(metricNamePropertyKey + " is not consistent in core bundle and CoreMetrics"); + } + + String metricDescriptionPropertyKey = "metric." + metric.getKey() + ".description"; + String l10nMetricDescription = underTest.message(Locale.ENGLISH, metricDescriptionPropertyKey, null); + if (l10nMetricDescription == null) { + incorrectMetricDefinitions.add(metricDescriptionPropertyKey + "=" + metric.getDescription()); + } else if (!l10nMetricDescription.equals(metric.getDescription())) { + incorrectMetricDefinitions.add(metricDescriptionPropertyKey + " is not consistent in core bundle and CoreMetrics"); + } + } + + assertThat(incorrectMetricDefinitions).as("Metric definitions to fix in core bundle", incorrectMetricDefinitions.size()).isEmpty(); } @Test public void get_english_labels() { - assertThat(manager.message(Locale.ENGLISH, "any", null)).isEqualTo("Any"); - assertThat(manager.message(Locale.ENGLISH, "sqale.page", null)).isEqualTo("Sqale page title"); - assertThat(manager.message(Locale.ENGLISH, "checkstyle.rule1.name", null)).isEqualTo("Rule one"); + assertThat(underTest.message(Locale.ENGLISH, "any", null)).isEqualTo("Any"); + assertThat(underTest.message(Locale.ENGLISH, "sqale.page", null)).isEqualTo("Sqale page title"); + assertThat(underTest.message(Locale.ENGLISH, "checkstyle.rule1.name", null)).isEqualTo("Rule one"); } // SONAR-2927 @@ -82,9 +113,9 @@ public class DefaultI18nTest { Locale defaultLocale = Locale.getDefault(); try { Locale.setDefault(Locale.FRENCH); - assertThat(manager.message(Locale.ENGLISH, "any", null)).isEqualTo("Any"); - assertThat(manager.message(Locale.ENGLISH, "sqale.page", null)).isEqualTo("Sqale page title"); - assertThat(manager.message(Locale.ENGLISH, "checkstyle.rule1.name", null)).isEqualTo("Rule one"); + assertThat(underTest.message(Locale.ENGLISH, "any", null)).isEqualTo("Any"); + assertThat(underTest.message(Locale.ENGLISH, "sqale.page", null)).isEqualTo("Sqale page title"); + assertThat(underTest.message(Locale.ENGLISH, "checkstyle.rule1.name", null)).isEqualTo("Rule one"); } finally { Locale.setDefault(defaultLocale); } @@ -92,80 +123,80 @@ public class DefaultI18nTest { @Test public void get_labels_from_french_pack() { - assertThat(manager.message(Locale.FRENCH, "checkstyle.rule1.name", null)).isEqualTo("Rule un"); - assertThat(manager.message(Locale.FRENCH, "any", null)).isEqualTo("Tous"); + assertThat(underTest.message(Locale.FRENCH, "checkstyle.rule1.name", null)).isEqualTo("Rule un"); + assertThat(underTest.message(Locale.FRENCH, "any", null)).isEqualTo("Tous"); // language pack - assertThat(manager.message(Locale.FRENCH, "sqale.page", null)).isEqualTo("Titre de la page Sqale"); + assertThat(underTest.message(Locale.FRENCH, "sqale.page", null)).isEqualTo("Titre de la page Sqale"); } @Test public void get_french_label_if_swiss_country() { Locale swiss = new Locale("fr", "CH"); - assertThat(manager.message(swiss, "checkstyle.rule1.name", null)).isEqualTo("Rule un"); - assertThat(manager.message(swiss, "any", null)).isEqualTo("Tous"); + assertThat(underTest.message(swiss, "checkstyle.rule1.name", null)).isEqualTo("Rule un"); + assertThat(underTest.message(swiss, "any", null)).isEqualTo("Tous"); // language pack - assertThat(manager.message(swiss, "sqale.page", null)).isEqualTo("Titre de la page Sqale"); + assertThat(underTest.message(swiss, "sqale.page", null)).isEqualTo("Titre de la page Sqale"); } @Test public void fallback_to_default_locale() { - assertThat(manager.message(Locale.CHINA, "checkstyle.rule1.name", null)).isEqualTo("Rule one"); - assertThat(manager.message(Locale.CHINA, "any", null)).isEqualTo("Any"); - assertThat(manager.message(Locale.CHINA, "sqale.page", null)).isEqualTo("Sqale page title"); + assertThat(underTest.message(Locale.CHINA, "checkstyle.rule1.name", null)).isEqualTo("Rule one"); + assertThat(underTest.message(Locale.CHINA, "any", null)).isEqualTo("Any"); + assertThat(underTest.message(Locale.CHINA, "sqale.page", null)).isEqualTo("Sqale page title"); } @Test public void return_default_value_if_missing_key() { - assertThat(manager.message(Locale.ENGLISH, "bla_bla_bla", "default")).isEqualTo("default"); - assertThat(manager.message(Locale.FRENCH, "bla_bla_bla", "default")).isEqualTo("default"); + assertThat(underTest.message(Locale.ENGLISH, "bla_bla_bla", "default")).isEqualTo("default"); + assertThat(underTest.message(Locale.FRENCH, "bla_bla_bla", "default")).isEqualTo("default"); } @Test public void format_message_with_parameters() { - assertThat(manager.message(Locale.ENGLISH, "name_too_long_x", null, "10")).isEqualTo("Name is too long (maximum is 10 characters)"); + assertThat(underTest.message(Locale.ENGLISH, "name_too_long_x", null, "10")).isEqualTo("Name is too long (maximum is 10 characters)"); } @Test public void use_default_locale_if_missing_value_in_localized_bundle() { - assertThat(manager.message(Locale.FRENCH, "assignee", null)).isEqualTo("Assignee"); - assertThat(manager.message(Locale.CHINA, "assignee", null)).isEqualTo("Assignee"); + assertThat(underTest.message(Locale.FRENCH, "assignee", null)).isEqualTo("Assignee"); + assertThat(underTest.message(Locale.CHINA, "assignee", null)).isEqualTo("Assignee"); } @Test public void return_null_if_file_not_found() { - String html = manager.messageFromFile(Locale.ENGLISH, "UnknownRule.html", "checkstyle.rule1.name"); + String html = underTest.messageFromFile(Locale.ENGLISH, "UnknownRule.html", "checkstyle.rule1.name"); assertThat(html).isNull(); } @Test public void return_null_if_rule_not_internationalized() { - String html = manager.messageFromFile(Locale.ENGLISH, "UnknownRule.html", "foo.rule1.name"); + String html = underTest.messageFromFile(Locale.ENGLISH, "UnknownRule.html", "foo.rule1.name"); assertThat(html).isNull(); } @Test public void get_age_with_duration() { - assertThat(manager.age(Locale.ENGLISH, 10)).isEqualTo("less than a minute"); + assertThat(underTest.age(Locale.ENGLISH, 10)).isEqualTo("less than a minute"); } @Test public void get_age_with_dates() { - assertThat(manager.age(Locale.ENGLISH, DateUtils.parseDate("2014-01-01"), DateUtils.parseDate("2014-01-02"))).isEqualTo("a day"); + assertThat(underTest.age(Locale.ENGLISH, DateUtils.parseDate("2014-01-01"), DateUtils.parseDate("2014-01-02"))).isEqualTo("a day"); } @Test public void get_age_from_now() { when(system2.now()).thenReturn(DateUtils.parseDate("2014-01-02").getTime()); - assertThat(manager.ageFromNow(Locale.ENGLISH, DateUtils.parseDate("2014-01-01"))).isEqualTo("a day"); + assertThat(underTest.ageFromNow(Locale.ENGLISH, DateUtils.parseDate("2014-01-01"))).isEqualTo("a day"); } @Test public void format_date_time() { TimeZone initialTz = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT+1")); - assertThat(manager.formatDateTime(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100"))).startsWith("Jan 22, 2014"); + assertThat(underTest.formatDateTime(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100"))).startsWith("Jan 22, 2014"); TimeZone.setDefault(initialTz); } @@ -173,20 +204,20 @@ public class DefaultI18nTest { public void format_date() { TimeZone initialTz = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT+1")); - assertThat(manager.formatDate(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100"))).isEqualTo("Jan 22, 2014"); + assertThat(underTest.formatDate(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100"))).isEqualTo("Jan 22, 2014"); TimeZone.setDefault(initialTz); } @Test public void format_double() { - assertThat(manager.formatDouble(Locale.FRENCH, 10.56)).isEqualTo("10,6"); - assertThat(manager.formatDouble(Locale.FRENCH, 10d)).isEqualTo("10,0"); + assertThat(underTest.formatDouble(Locale.FRENCH, 10.56)).isEqualTo("10,6"); + assertThat(underTest.formatDouble(Locale.FRENCH, 10d)).isEqualTo("10,0"); } @Test public void format_integer() { - assertThat(manager.formatInteger(Locale.ENGLISH, 10)).isEqualTo("10"); - assertThat(manager.formatInteger(Locale.ENGLISH, 100000)).isEqualTo("100,000"); + assertThat(underTest.formatInteger(Locale.ENGLISH, 10)).isEqualTo("10"); + assertThat(underTest.formatInteger(Locale.ENGLISH, 100000)).isEqualTo("100,000"); } private PluginInfo newPlugin(String key) { |