From: Julien Lancelot Date: Fri, 3 Jul 2015 14:45:36 +0000 (+0200) Subject: SONAR-6680 Remove quality profile decorator from batch X-Git-Tag: 5.2-RC1~1195 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7787674e7c193b0e7f6fbaac7212c30f1a0797ee;p=sonarqube.git SONAR-6680 Remove quality profile decorator from batch --- 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 index 05371f00828..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileDecorator.java +++ /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(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java index 37455f5b58a..ef602db802a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java @@ -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 { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java index c98d992a5cf..fd03094668e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java @@ -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 index a0b8a8e57b9..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileDecoratorTest.java +++ /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.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 + "]"))); - } -}