diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-03-02 14:29:16 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-03-02 14:41:44 +0100 |
commit | 6f4488154742041dc531f83ad45e487dbc2fe6d7 (patch) | |
tree | 8b22dd62057c16bf93e5947ff9dd9813feb7b97d | |
parent | 32de25202356fdb88963f02e3fde0ec133bf85c7 (diff) | |
download | sonarqube-6f4488154742041dc531f83ad45e487dbc2fe6d7.tar.gz sonarqube-6f4488154742041dc531f83ad45e487dbc2fe6d7.zip |
SONAR-5077 Display ncloc of files with no language in size widget
4 files changed, 33 insertions, 8 deletions
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/size.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/size.html.erb index 0a28f86c05c..9e0797f8005 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/size.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/size.html.erb @@ -49,8 +49,12 @@ %> <tr> <td> - <% language = languages.find { |l| l.getKey()==language_key.to_s } -%> - <%= language ? language.getName() : language_key -%> + <% if language_key.eql? '<null>' %> + <%= message('other') -%> + <% else %> + <% language = languages.find { |l| l.getKey()==language_key.to_s } -%> + <%= language ? language.getName() : language_key -%> + <% end %> </td> <td class="thin right nowrap"> <%= ncloc.format_numeric_value(language_ncloc) %> @@ -73,11 +77,14 @@ }); </script> <% else %> - <% + <% language_key = ncloc_language_dist_hash.first[0] - language = languages.find { |l| l.getKey()==language_key.to_s } - -%> - <%= language ? language.getName() : language_key -%> + if language_key.eql? '<null>' %> + <%= message('other') -%> + <% else %> + <% language = languages.find { |l| l.getKey()==language_key.to_s } -%> + <%= language ? language.getName() : language_key -%> + <% end %> <% end %> <% end %> <% else %> diff --git a/sonar-batch/src/main/java/org/sonar/batch/language/LanguageDistributionDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/language/LanguageDistributionDecorator.java index cc246cfc793..ab9fb78b8ff 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/language/LanguageDistributionDecorator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/language/LanguageDistributionDecorator.java @@ -35,6 +35,8 @@ import org.sonar.api.resources.ResourceUtils; public class LanguageDistributionDecorator implements Decorator { + private static final String UNKNOWN_LANGUAGE_KEY = "<null>"; + @Override public boolean shouldExecuteOnProject(Project project) { return true; @@ -56,8 +58,8 @@ public class LanguageDistributionDecorator implements Decorator { if (ResourceUtils.isFile(resource)) { Language language = resource.getLanguage(); Measure ncloc = context.getMeasure(CoreMetrics.NCLOC); - if (language != null && ncloc != null) { - nclocDistribution.add(language.getKey(), ncloc.getIntValue()); + if (ncloc != null) { + nclocDistribution.add(language != null ? language.getKey() : UNKNOWN_LANGUAGE_KEY, ncloc.getIntValue()); } } else { for (Measure measure : context.getChildrenMeasures(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION)) { diff --git a/sonar-batch/src/test/java/org/sonar/batch/language/LanguageDistributionDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/language/LanguageDistributionDecoratorTest.java index cb9d52bae9e..155b9cd4910 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/language/LanguageDistributionDecoratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/language/LanguageDistributionDecoratorTest.java @@ -93,6 +93,21 @@ public class LanguageDistributionDecoratorTest { } @Test + public void save_ncloc_language_distribution_on_file_without_language() { + + when(resource.getScope()).thenReturn(Scopes.FILE); + when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 200.0)); + + decorator.decorate(resource, context); + + verify(context).saveMeasure(measureCaptor.capture()); + + Measure result = measureCaptor.getValue(); + assertThat(result.getMetric()).isEqualTo(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION); + assertThat(result.getData()).isEqualTo("<null>=200"); + } + + @Test public void save_ncloc_language_distribution_on_project() { when(resource.getScope()).thenReturn(Scopes.PROJECT); when(context.getChildrenMeasures(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION)).thenReturn(newArrayList( 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 9f6f5dbfdfb..daa7a8c7a4a 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -104,6 +104,7 @@ open_verb=Open operations=Operations optional=Optional order=Order +other=Other owner=Owner package=Package packages=Packages |