aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-07-21 17:30:13 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-07-23 11:06:03 +0200
commit44a68c43498da870ebc4c7b4f638620f14e50b3b (patch)
treead64c932c6a0b831f5acb70b453d4ca15622f7e9 /sonar-batch
parentc5a1decadac5bcefe65fc1194c1694e2b6c73143 (diff)
downloadsonarqube-44a68c43498da870ebc4c7b4f638620f14e50b3b.tar.gz
sonarqube-44a68c43498da870ebc4c7b4f638620f14e50b3b.zip
SONAR-6676 remove Decorators for FILES and DIRECTORIES metrics
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/compute/DirectoriesDecorator.java69
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/compute/FilesDecorator.java65
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/compute/DirectoriesDecoratorTest.java90
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/compute/FilesDecoratorTest.java111
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java4
6 files changed, 3 insertions, 344 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 40ece5d78d0..1704d303520 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
@@ -22,8 +22,6 @@ package org.sonar.batch.bootstrap;
import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.List;
-import org.sonar.batch.compute.DirectoriesDecorator;
-import org.sonar.batch.compute.FilesDecorator;
import org.sonar.batch.cpd.CpdComponents;
import org.sonar.batch.issue.tracking.IssueTracking;
import org.sonar.batch.scan.report.ConsoleReport;
@@ -63,11 +61,7 @@ public class BatchComponents {
HtmlReport.class,
IssuesReportBuilder.class,
SourceProvider.class,
- RuleNameProvider.class,
-
- // to be moved to compute engine
- DirectoriesDecorator.class,
- FilesDecorator.class
+ RuleNameProvider.class
);
components.addAll(CorePropertyDefinitions.all());
// CPD
diff --git a/sonar-batch/src/main/java/org/sonar/batch/compute/DirectoriesDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/compute/DirectoriesDecorator.java
deleted file mode 100644
index e1dc25e7740..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/compute/DirectoriesDecorator.java
+++ /dev/null
@@ -1,69 +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.compute;
-
-import java.util.Collection;
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.DependedUpon;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.MeasureUtils;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-
-/**
- * @since 2.2
- */
-public final class DirectoriesDecorator implements Decorator {
-
- @Override
- public boolean shouldExecuteOnProject(Project project) {
- return true;
- }
-
- @DependedUpon
- public Metric generateDirectoriesMetric() {
- return CoreMetrics.DIRECTORIES;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void decorate(Resource resource, DecoratorContext context) {
- if (MeasureUtils.hasValue(context.getMeasure(CoreMetrics.DIRECTORIES))) {
- return;
- }
-
- if (Resource.QUALIFIER_DIRECTORY.equals(resource.getQualifier())) {
- context.saveMeasure(CoreMetrics.DIRECTORIES, 1.0);
-
- } else if (ResourceUtils.isSet(resource)) {
- Collection<Measure> childrenMeasures = context.getChildrenMeasures(CoreMetrics.DIRECTORIES);
- Double sum = MeasureUtils.sum(false, childrenMeasures);
- if (sum != null) {
- context.saveMeasure(CoreMetrics.DIRECTORIES, sum);
- }
- }
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/compute/FilesDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/compute/FilesDecorator.java
deleted file mode 100644
index 27b0cbd07f8..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/compute/FilesDecorator.java
+++ /dev/null
@@ -1,65 +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.compute;
-
-import java.util.Collection;
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.DependedUpon;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.MeasureUtils;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-
-/**
- * @since 2.2
- */
-public final class FilesDecorator implements Decorator {
-
- @Override
- public boolean shouldExecuteOnProject(Project project) {
- return true;
- }
-
- @DependedUpon
- public Metric generateDirectoriesMetric() {
- return CoreMetrics.FILES;
- }
-
- @Override
- public void decorate(Resource resource, DecoratorContext context) {
- if (MeasureUtils.hasValue(context.getMeasure(CoreMetrics.FILES))) {
- return;
- }
-
- if (Resource.QUALIFIER_CLASS.equals(resource.getQualifier()) || Resource.QUALIFIER_FILE.equals(resource.getQualifier())) {
- context.saveMeasure(CoreMetrics.FILES, 1.0);
-
- } else {
- Collection<Measure> childrenMeasures = context.getChildrenMeasures(CoreMetrics.FILES);
- Double sum = MeasureUtils.sum(false, childrenMeasures);
- if (sum != null) {
- context.saveMeasure(CoreMetrics.FILES, sum);
- }
- }
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/compute/DirectoriesDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/compute/DirectoriesDecoratorTest.java
deleted file mode 100644
index 5e854bc9913..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/compute/DirectoriesDecoratorTest.java
+++ /dev/null
@@ -1,90 +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.compute;
-
-import java.util.Arrays;
-import java.util.Collections;
-import org.junit.Test;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.File;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-
-import static org.mockito.Matchers.anyDouble;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class DirectoriesDecoratorTest {
-
- @Test
- public void doNotInsertZeroOnFiles() {
- DirectoriesDecorator decorator = new DirectoriesDecorator();
- Resource file = File.create("foo.php");
- DecoratorContext context = mock(DecoratorContext.class);
-
- decorator.decorate(file, context);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.DIRECTORIES), anyDouble());
- }
-
- @Test
- public void directoryCountsForOne() {
- DirectoriesDecorator decorator = new DirectoriesDecorator();
- Resource directory = Directory.create("org/foo");
- DecoratorContext context = mock(DecoratorContext.class);
- decorator.decorate(directory, context);
- verify(context).saveMeasure(CoreMetrics.DIRECTORIES, 1.0);
- }
-
- @Test
- public void countProjectDirectories() {
- DirectoriesDecorator decorator = new DirectoriesDecorator();
- Resource project = new Project("project");
- DecoratorContext context = mock(DecoratorContext.class);
-
- when(context.getChildrenMeasures(CoreMetrics.DIRECTORIES)).thenReturn(Arrays.<Measure>asList(
- new Measure(CoreMetrics.DIRECTORIES, 1.0),
- new Measure(CoreMetrics.DIRECTORIES, 1.0),
- new Measure(CoreMetrics.DIRECTORIES, 1.0)
- ));
- decorator.decorate(project, context);
- verify(context).saveMeasure(CoreMetrics.DIRECTORIES, 3.0);
- }
-
- @Test
- public void noProjectValueWhenOnlyPackages() {
- DirectoriesDecorator decorator = new DirectoriesDecorator();
- Resource project = new Project("project");
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getChildrenMeasures(CoreMetrics.DIRECTORIES)).thenReturn(Collections.<Measure>emptyList());
- when(context.getChildrenMeasures(CoreMetrics.PACKAGES)).thenReturn(Arrays.<Measure>asList(
- new Measure(CoreMetrics.PACKAGES, 1.0),
- new Measure(CoreMetrics.PACKAGES, 1.0)
- ));
- decorator.decorate(project, context);
- verify(context, never()).saveMeasure(eq(CoreMetrics.DIRECTORIES), anyDouble());
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/compute/FilesDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/compute/FilesDecoratorTest.java
deleted file mode 100644
index f750aebcdde..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/compute/FilesDecoratorTest.java
+++ /dev/null
@@ -1,111 +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.compute;
-
-import java.util.Arrays;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Resource;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.anyDouble;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class FilesDecoratorTest {
-
- private FilesDecorator decorator;
-
- @Mock
- private DecoratorContext context;
-
- @Mock
- private Resource resource;
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- decorator = new FilesDecorator();
- }
-
- @Test
- public void generatesMetrics() {
- assertThat(decorator.generateDirectoriesMetric()).isEqualTo(CoreMetrics.FILES);
- }
-
- @Test
- public void shouldExecute() {
- assertThat(decorator.shouldExecuteOnProject(mock(Project.class))).isEqualTo(true);
- }
-
- @Test
- public void shouldNotSaveIfMeasureAlreadyExists() {
- when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 1.0));
-
- decorator.decorate(resource, context);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.FILES), anyDouble());
- }
-
- @Test
- public void shouldSaveOneForFile() {
- when(resource.getQualifier()).thenReturn(Qualifiers.FILE);
-
- decorator.decorate(resource, context);
-
- verify(context, times(1)).saveMeasure(eq(CoreMetrics.FILES), eq(1d));
- }
-
- @Test
- public void shouldSaveOneForClass() {
- when(resource.getQualifier()).thenReturn(Qualifiers.CLASS);
-
- decorator.decorate(resource, context);
-
- verify(context, times(1)).saveMeasure(eq(CoreMetrics.FILES), eq(1d));
- }
-
- @Test
- public void shouldSumChildren() {
- when(context.getChildrenMeasures(CoreMetrics.FILES)).thenReturn(Arrays.asList(new Measure(CoreMetrics.FILES, 2.0), new Measure(CoreMetrics.FILES, 3.0)));
-
- decorator.decorate(resource, context);
-
- verify(context).saveMeasure(eq(CoreMetrics.FILES), eq(5.0));
- }
-
-}
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 895e95facad..10f7657e886 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(25);
+ assertThat(result.allMeasures()).hasSize(18);
}
@Test
@@ -94,7 +94,7 @@ public class MeasuresMediumTest {
.build())
.start();
- assertThat(result.allMeasures()).hasSize(9);
+ assertThat(result.allMeasures()).hasSize(4);
assertThat(result.allMeasures()).contains(new DefaultMeasure<Integer>()
.forMetric(CoreMetrics.LINES)