]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6680 Remove quality profile decorator from batch
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 3 Jul 2015 14:45:36 +0000 (16:45 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 7 Jul 2015 08:40:25 +0000 (10:40 +0200)
sonar-batch/src/main/java/org/sonar/batch/rule/QProfileDecorator.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java
sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
sonar-batch/src/test/java/org/sonar/batch/rule/QProfileDecoratorTest.java [deleted file]

diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileDecorator.java
deleted file mode 100644 (file)
index 05371f0..0000000
+++ /dev/null
@@ -1,70 +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.rule;
-
-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.Metric;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-
-/**
- * Aggregate which Quality profiles have been used on the current module.
- */
-public class QProfileDecorator implements Decorator {
-
-  @DependedUpon
-  public Metric provides() {
-    return CoreMetrics.QUALITY_PROFILES;
-  }
-
-  @Override
-  public boolean shouldExecuteOnProject(Project project) {
-    return !project.getModules().isEmpty();
-  }
-
-  @Override
-  public void decorate(Resource resource, DecoratorContext context) {
-    if (!ResourceUtils.isProject(resource)) {
-      return;
-    }
-    UsedQProfiles used = new UsedQProfiles();
-    for (Measure childProfilesMeasure : context.getChildrenMeasures(CoreMetrics.QUALITY_PROFILES)) {
-      String data = childProfilesMeasure.getData();
-      if (data != null) {
-        UsedQProfiles childProfiles = UsedQProfiles.fromJson(data);
-        used.add(childProfiles);
-      }
-    }
-
-    Measure detailsMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, used.toJson());
-    context.saveMeasure(detailsMeasure);
-  }
-
-  @Override
-  public String toString() {
-    return getClass().getSimpleName();
-  }
-
-}
index 37455f5b58ad8233b7600b67a571c021480f75c0..ef602db802a89e0b88929575aca69a82d99eee18 100644 (file)
@@ -29,6 +29,8 @@ import org.sonar.api.resources.Project;
 
 /**
  * Stores which Quality profiles have been used on the current module.
+ *
+ * TODO This information should not be stored as a measure but should be send as metadata in the {@link org.sonar.batch.protocol.output.BatchReport}
  */
 public class QProfileSensor implements Sensor {
 
index c98d992a5cfeff2f5b777e31776783605f0146bc..fd03094668e6f2886e77be7fb6664aa8cb7bcb49 100644 (file)
@@ -57,7 +57,6 @@ import org.sonar.batch.phases.SensorsExecutor;
 import org.sonar.batch.postjob.DefaultPostJobContext;
 import org.sonar.batch.postjob.PostJobOptimizer;
 import org.sonar.batch.rule.ModuleQProfiles;
-import org.sonar.batch.rule.QProfileDecorator;
 import org.sonar.batch.rule.QProfileSensor;
 import org.sonar.batch.rule.QProfileVerifier;
 import org.sonar.batch.rule.RuleFinderCompatibility;
@@ -156,7 +155,6 @@ public class ModuleScanContainer extends ComponentContainer {
       ModuleQProfiles.class,
       new RulesProfileProvider(),
       QProfileSensor.class,
-      QProfileDecorator.class,
       CheckFactory.class,
 
       // report
diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileDecoratorTest.java
deleted file mode 100644 (file)
index a0b8a8e..0000000
+++ /dev/null
@@ -1,91 +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.rule;
-
-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.Project;
-import org.sonar.api.resources.Scopes;
-import org.sonar.api.test.IsMeasure;
-
-import java.util.Arrays;
-import java.util.Collections;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class QProfileDecoratorTest {
-
-  static final String JAVA_JSON = "{\"key\":\"J1\",\"language\":\"java\",\"name\":\"Java One\",\"rulesUpdatedAt\":\"2014-01-15T10:00:00+0000\"}";
-  static final String JAVA2_JSON = "{\"key\":\"J2\",\"language\":\"java\",\"name\":\"Java Two\",\"rulesUpdatedAt\":\"2014-01-15T10:00:00+0000\"}";
-  static final String PHP_JSON = "{\"key\":\"P1\",\"language\":\"php\",\"name\":\"Php One\",\"rulesUpdatedAt\":\"2014-01-15T10:00:00+0000\"}";
-
-  Project project = mock(Project.class);
-  Project moduleA = mock(Project.class);
-  Project moduleB = mock(Project.class);
-  Project moduleC = mock(Project.class);
-  DecoratorContext decoratorContext = mock(DecoratorContext.class);
-
-  @Test
-  public void don_t_run_on_leaf() {
-    QProfileDecorator decorator = new QProfileDecorator();
-    when(project.getModules()).thenReturn(Collections.<Project>emptyList());
-    assertThat(decorator.shouldExecuteOnProject(project)).isFalse();
-
-    when(project.getModules()).thenReturn(Arrays.asList(moduleA, moduleB, moduleC));
-    assertThat(decorator.shouldExecuteOnProject(project)).isTrue();
-  }
-
-  @Test
-  public void aggregate() {
-    Measure measureModuleA = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_JSON + "]");
-    Measure measureModuleB = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_JSON + "]");
-    Measure measureModuleC = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + PHP_JSON + "]");
-    when(decoratorContext.getChildrenMeasures(CoreMetrics.QUALITY_PROFILES)).thenReturn(Arrays.asList(measureModuleA, measureModuleB, measureModuleC));
-
-    when(project.getScope()).thenReturn(Scopes.PROJECT);
-
-    QProfileDecorator decorator = new QProfileDecorator();
-    decorator.decorate(project, decoratorContext);
-
-    verify(decoratorContext).saveMeasure(
-      argThat(new IsMeasure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_JSON + "," + PHP_JSON + "]")));
-  }
-
-  @Test
-  public void aggregate_different_profiles_with_same_language() {
-    Measure measureModuleA = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_JSON + "]");
-    Measure measureModuleB = new Measure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA2_JSON + "]");
-    when(decoratorContext.getChildrenMeasures(CoreMetrics.QUALITY_PROFILES)).thenReturn(Arrays.asList(measureModuleA, measureModuleB));
-
-    when(project.getScope()).thenReturn(Scopes.PROJECT);
-
-    QProfileDecorator decorator = new QProfileDecorator();
-    decorator.decorate(project, decoratorContext);
-
-    verify(decoratorContext).saveMeasure(
-      argThat(new IsMeasure(CoreMetrics.QUALITY_PROFILES, "[" + JAVA_JSON + "," + JAVA2_JSON + "]")));
-  }
-}