]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6676 remove Decorators for FILES and DIRECTORIES metrics
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 21 Jul 2015 15:30:13 +0000 (17:30 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 23 Jul 2015 09:06:03 +0000 (11:06 +0200)
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
sonar-batch/src/main/java/org/sonar/batch/compute/DirectoriesDecorator.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/compute/FilesDecorator.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/compute/DirectoriesDecoratorTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/compute/FilesDecoratorTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java

index 40ece5d78d0cb2af29987d55dfe1037c7b2ad704..1704d30352052adbc1780d1b4b391beb00b845f3 100644 (file)
@@ -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 (file)
index e1dc25e..0000000
+++ /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 (file)
index 27b0cbd..0000000
+++ /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 (file)
index 5e854bc..0000000
+++ /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 (file)
index f750aeb..0000000
+++ /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));
-  }
-
-}
index 895e95facade6f0e2375d9a5b6d6d7dc0c87c8ad..10f7657e886a39820a9e4c78a4c975937e0274a0 100644 (file)
@@ -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)