From: Simon Brandhof Date: Wed, 10 Jan 2018 19:41:48 +0000 (+0100) Subject: SONAR-10138 remove deprecated API AbstractSumChildrenDecorator X-Git-Tag: 7.0-RC1~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=93c6c4ccda2bf18fc651b215576172810a1f8725;p=sonarqube.git SONAR-10138 remove deprecated API AbstractSumChildrenDecorator --- diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSumChildrenDecorator.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSumChildrenDecorator.java deleted file mode 100644 index bec9fca8267..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSumChildrenDecorator.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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.api.batch; - -import java.util.List; -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; - -/** - * Sum measures of child resources. - * - * @since 1.10 - * @deprecated since 5.2 there's no more decorator on batch side - */ -@Deprecated -public abstract class AbstractSumChildrenDecorator implements Decorator { - - /** - * Each metric is used individually. There are as many generated measures than metrics. - *

Important : annotations are not inherited, so you have to copy the @DependedUpon annotation - * when implementing this method. - * - * @return not null list of metrics - */ - @DependedUpon - public abstract List generatesMetrics(); - - /** - * {@inheritDoc} - */ - @Override - public boolean shouldExecuteOnProject(Project project) { - return true; - } - - /** - * @return whether it should save zero if no child measures - */ - protected abstract boolean shouldSaveZeroIfNoChildMeasures(); - - /** - * {@inheritDoc} - */ - @Override - public void decorate(Resource resource, DecoratorContext context) { - if (!shouldDecorateResource(resource)) { - return; - } - for (Metric metric : generatesMetrics()) { - if (context.getMeasure(metric) == null) { - Double sum = MeasureUtils.sum(shouldSaveZeroIfNoChildMeasures(), context.getChildrenMeasures(metric)); - if (sum != null) { - context.saveMeasure(new Measure(metric, sum)); - } - } - } - } - - /** - * @return whether the resource should be decorated or not - */ - public boolean shouldDecorateResource(Resource resource) { - return true; - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSumChildrenDecoratorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSumChildrenDecoratorTest.java deleted file mode 100644 index a2e4c89d3a0..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSumChildrenDecoratorTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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.api.batch; - -import org.junit.Test; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.Metric; -import org.sonar.api.test.IsMeasure; - -import java.util.Arrays; -import java.util.List; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.argThat; -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 AbstractSumChildrenDecoratorTest { - - @Test - public void sumChildren() { - DecoratorContext context = mock(DecoratorContext.class); - when(context.getChildrenMeasures(CoreMetrics.LINES)).thenReturn(Arrays.asList( - new Measure(CoreMetrics.LINES, 100.0), - new Measure(CoreMetrics.LINES, 50.0))); - - create(false).decorate(null, context); - - verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.LINES, 150.0))); - } - - @Test - public void doNotSaveZeroIfNoChildren() { - DecoratorContext context = mock(DecoratorContext.class); - when(context.getChildrenMeasures(CoreMetrics.LINES)).thenReturn(Arrays.asList()); - - create(false).decorate(null, context); - - verify(context, never()).saveMeasure(any(Measure.class)); - } - - @Test - public void saveZeroIfNoChildren() { - DecoratorContext context = mock(DecoratorContext.class); - when(context.getChildrenMeasures(CoreMetrics.LINES)).thenReturn(Arrays.asList()); - - create(true).decorate(null, context); - - verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.LINES, 0.0))); - } - - private AbstractSumChildrenDecorator create(final boolean zeroIfNoChildMeasures) { - return new AbstractSumChildrenDecorator() { - - @Override - @DependedUpon - public List generatesMetrics() { - return Arrays.asList(CoreMetrics.LINES); - } - - @Override - protected boolean shouldSaveZeroIfNoChildMeasures() { - return zeroIfNoChildMeasures; - } - }; - } -}