diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-07-20 16:40:18 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-07-21 15:59:45 +0200 |
commit | cabe5c343615115d51fedc1c36e5f7a85fe9782a (patch) | |
tree | 403bb28fd268da75e27bc96d691e3bafb1b216a6 /sonar-batch | |
parent | ba624912e734f614010752afefbce84ba0d73cff (diff) | |
download | sonarqube-cabe5c343615115d51fedc1c36e5f7a85fe9782a.tar.gz sonarqube-cabe5c343615115d51fedc1c36e5f7a85fe9782a.zip |
SONAR-6679 Remove computation of language distribution measures from batch
Diffstat (limited to 'sonar-batch')
5 files changed, 2 insertions, 256 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java index 435c547020f..e372cabd17c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java @@ -27,7 +27,6 @@ import org.sonar.batch.compute.FilesDecorator; import org.sonar.batch.compute.UnitTestDecorator; import org.sonar.batch.cpd.CpdComponents; import org.sonar.batch.issue.tracking.IssueTracking; -import org.sonar.batch.language.LanguageDistributionDecorator; import org.sonar.batch.scan.report.ConsoleReport; import org.sonar.batch.scan.report.HtmlReport; import org.sonar.batch.scan.report.IssuesReportBuilder; @@ -67,14 +66,11 @@ public class BatchComponents { SourceProvider.class, RuleNameProvider.class, - // language - LanguageDistributionDecorator.class, - // to be moved to compute engine UnitTestDecorator.class, DirectoriesDecorator.class, FilesDecorator.class - ); + ); components.addAll(CorePropertyDefinitions.all()); // CPD components.addAll(CpdComponents.all()); 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 deleted file mode 100644 index ab9fb78b8ff..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/language/LanguageDistributionDecorator.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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. - */ - -package org.sonar.batch.language; - -import org.sonar.api.batch.Decorator; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependedUpon; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.CountDistributionBuilder; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; -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; - } - - @DependsUpon - public Metric dependsUponMetric() { - return CoreMetrics.LINES; - } - - @DependedUpon - public Metric generatesMetric() { - return CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION; - } - - @Override - public void decorate(Resource resource, DecoratorContext context) { - CountDistributionBuilder nclocDistribution = new CountDistributionBuilder(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION); - if (ResourceUtils.isFile(resource)) { - Language language = resource.getLanguage(); - Measure ncloc = context.getMeasure(CoreMetrics.NCLOC); - if (ncloc != null) { - nclocDistribution.add(language != null ? language.getKey() : UNKNOWN_LANGUAGE_KEY, ncloc.getIntValue()); - } - } else { - for (Measure measure : context.getChildrenMeasures(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION)) { - nclocDistribution.add(measure); - } - } - Measure measure = nclocDistribution.build(false); - if (measure != null) { - context.saveMeasure(measure); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/language/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/language/package-info.java deleted file mode 100644 index 78142a00deb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/language/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.batch.language; - -import javax.annotation.ParametersAreNonnullByDefault; 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 deleted file mode 100644 index aa351984b5a..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/language/LanguageDistributionDecoratorTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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. - */ - -package org.sonar.batch.language; - -import com.google.common.collect.ImmutableMap; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Resource; -import org.sonar.api.resources.Scopes; -import org.sonar.api.utils.KeyValueFormat; - -import java.util.Collections; - -import static com.google.common.collect.Lists.newArrayList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class LanguageDistributionDecoratorTest { - - @Mock - DecoratorContext context; - - @Mock - Resource resource; - - @Captor - ArgumentCaptor<Measure> measureCaptor; - - LanguageDistributionDecorator decorator; - - @Before - public void setUp() { - decorator = new LanguageDistributionDecorator(); - } - - @Test - public void depended_upon_metric() { - assertThat(decorator.generatesMetric()).isEqualTo(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION); - } - - @Test - public void depens_upon_metric() { - assertThat(decorator.dependsUponMetric()).isEqualTo(CoreMetrics.LINES); - } - - @Test - public void save_ncloc_language_distribution_on_file() { - Language language = mock(Language.class); - when(language.getKey()).thenReturn("xoo"); - - when(resource.getScope()).thenReturn(Scopes.FILE); - when(resource.getLanguage()).thenReturn(language); - 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("xoo=200"); - } - - @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( - new Measure(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION, KeyValueFormat.format(ImmutableMap.of("java", 20))), - new Measure(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION, KeyValueFormat.format(ImmutableMap.of("xoo", 150))), - new Measure(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION, KeyValueFormat.format(ImmutableMap.of("xoo", 50))) - )); - - 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("java=20;xoo=200"); - } - - @Test - public void not_save_language_distribution_on_file_if_no_measure() { - Language language = mock(Language.class); - when(language.getKey()).thenReturn("xoo"); - - when(resource.getScope()).thenReturn(Scopes.FILE); - when(resource.getLanguage()).thenReturn(language); - when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(null); - - decorator.decorate(resource, context); - - verify(context, never()).saveMeasure(measureCaptor.capture()); - } - - @Test - public void not_save_language_distribution_on_project_if_no_chidren_measures() { - when(resource.getScope()).thenReturn(Scopes.PROJECT); - when(context.getChildrenMeasures(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION)).thenReturn(Collections.<Measure>emptyList()); - - decorator.decorate(resource, context); - - verify(context, never()).saveMeasure(measureCaptor.capture()); - } - -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java index 58cd7c18c3c..001673e63f8 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java @@ -67,7 +67,7 @@ public class MeasuresMediumTest { .newScanTask(new File(tmpDir, "sonar-project.properties")) .start(); - assertThat(result.allMeasures()).hasSize(43); + assertThat(result.allMeasures()).hasSize(37); } @Test |