diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-06-19 09:50:35 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-06-22 12:45:26 +0200 |
commit | cd6658145a3eaadf3d10c106e06999e3c8a3d512 (patch) | |
tree | 445fdb800519f5aba9be186cd30400abdd7c682d /sonar-batch | |
parent | 89071b4bdb0e13afa58588dbb46b370e01e1f0ad (diff) | |
download | sonarqube-cd6658145a3eaadf3d10c106e06999e3c8a3d512.tar.gz sonarqube-cd6658145a3eaadf3d10c106e06999e3c8a3d512.zip |
SONAR-6646 Remove CountFalsePositivesDecorator from batch
Diffstat (limited to 'sonar-batch')
3 files changed, 0 insertions, 169 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 53041fab9e1..ff5f1ca03db 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 @@ -25,7 +25,6 @@ import java.util.List; import org.sonar.batch.components.TimeMachineConfiguration; import org.sonar.batch.compute.BranchCoverageDecorator; import org.sonar.batch.compute.CommentDensityDecorator; -import org.sonar.batch.compute.CountFalsePositivesDecorator; import org.sonar.batch.compute.CoverageDecorator; import org.sonar.batch.compute.DirectoriesDecorator; import org.sonar.batch.compute.FilesDecorator; @@ -107,7 +106,6 @@ public class BatchComponents { InitialOpenIssuesSensor.class, // to be moved to compute engine - CountFalsePositivesDecorator.class, UnitTestDecorator.class, LineCoverageDecorator.class, CoverageDecorator.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/compute/CountFalsePositivesDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/compute/CountFalsePositivesDecorator.java deleted file mode 100644 index 1eb5456457d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/compute/CountFalsePositivesDecorator.java +++ /dev/null @@ -1,86 +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 org.sonar.api.batch.Decorator; -import org.sonar.api.batch.DecoratorBarriers; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependedUpon; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.component.ResourcePerspectives; -import org.sonar.api.issue.Issuable; -import org.sonar.api.issue.Issue; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.MeasureUtils; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; - -/** - * Computes the number of false-positives - * - * @since 3.6 - */ -@DependsUpon(DecoratorBarriers.END_OF_VIOLATION_TRACKING) -public class CountFalsePositivesDecorator implements Decorator { - - private final ResourcePerspectives perspectives; - - public CountFalsePositivesDecorator(ResourcePerspectives perspectives) { - this.perspectives = perspectives; - } - - @Override - public boolean shouldExecuteOnProject(Project project) { - return true; - } - - @DependedUpon - public Metric generatesFalsePositiveMeasure() { - return CoreMetrics.FALSE_POSITIVE_ISSUES; - } - - @Override - public void decorate(Resource resource, DecoratorContext context) { - Issuable issuable = perspectives.as(Issuable.class, resource); - if (issuable != null) { - int falsePositives = 0; - for (Issue issue : issuable.resolvedIssues()) { - if (Issue.RESOLUTION_FALSE_POSITIVE.equals(issue.resolution())) { - falsePositives++; - } - } - saveMeasure(context, CoreMetrics.FALSE_POSITIVE_ISSUES, falsePositives); - } - } - - private void saveMeasure(DecoratorContext context, Metric metric, int value) { - context.saveMeasure(metric, (double) (value + sumChildren(context, metric))); - } - - private int sumChildren(DecoratorContext context, Metric metric) { - return MeasureUtils.sum(true, context.getChildrenMeasures(metric)).intValue(); - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/compute/CountFalsePositivesDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/compute/CountFalsePositivesDecoratorTest.java deleted file mode 100644 index 37eea57e8e6..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/compute/CountFalsePositivesDecoratorTest.java +++ /dev/null @@ -1,81 +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.Test; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.component.ResourcePerspectives; -import org.sonar.api.issue.Issuable; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.internal.DefaultIssue; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.resources.File; -import org.sonar.api.resources.Project; -import org.sonar.api.rule.RuleKey; -import org.sonar.java.api.JavaClass; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -public class CountFalsePositivesDecoratorTest { - - ResourcePerspectives perspectives = mock(ResourcePerspectives.class); - CountFalsePositivesDecorator decorator = new CountFalsePositivesDecorator(perspectives); - - @Test - public void should_count_false_positives() { - DefaultIssue falsePositive = new DefaultIssue().setRuleKey(RuleKey.parse("squid:AvoidCycles")) - .setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setStatus(Issue.STATUS_RESOLVED); - DefaultIssue fixed = new DefaultIssue().setRuleKey(RuleKey.parse("squid:AvoidCycles")) - .setResolution(Issue.RESOLUTION_FIXED).setStatus(Issue.STATUS_RESOLVED); - - File file = File.create("foo.c"); - Issuable issuable = mock(Issuable.class); - when(perspectives.as(Issuable.class, file)).thenReturn(issuable); - when(issuable.resolvedIssues()).thenReturn(Arrays.<Issue>asList(falsePositive, fixed)); - - DecoratorContext context = mock(DecoratorContext.class); - decorator.decorate(file, context); - - verify(context).saveMeasure(CoreMetrics.FALSE_POSITIVE_ISSUES, 1.0); - } - - @Test - public void should_declare_metadata() { - assertThat(decorator.shouldExecuteOnProject(new Project("foo"))).isTrue(); - assertThat(decorator.generatesFalsePositiveMeasure()).isEqualTo(CoreMetrics.FALSE_POSITIVE_ISSUES); - assertThat(decorator.toString()).isEqualTo("CountFalsePositivesDecorator"); - } - - @Test - public void should_ignore_classes_and_methods() { - JavaClass javaClass = JavaClass.create("Foo.java"); - when(perspectives.as(Issuable.class, javaClass)).thenReturn(null); - - DecoratorContext context = mock(DecoratorContext.class); - decorator.decorate(javaClass, context); - - verifyZeroInteractions(context); - } -} |