2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2013 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.plugins.core.issue;
22 import org.sonar.api.batch.*;
23 import org.sonar.api.component.ResourcePerspectives;
24 import org.sonar.api.issue.Issuable;
25 import org.sonar.api.issue.Issue;
26 import org.sonar.api.measures.CoreMetrics;
27 import org.sonar.api.measures.MeasureUtils;
28 import org.sonar.api.measures.Metric;
29 import org.sonar.api.resources.Project;
30 import org.sonar.api.resources.Resource;
33 * Computes the number of false-positives
37 @DependsUpon(DecoratorBarriers.END_OF_VIOLATION_TRACKING)
38 public class CountFalsePositivesDecorator implements Decorator {
40 private final ResourcePerspectives perspectives;
42 public CountFalsePositivesDecorator(ResourcePerspectives perspectives) {
43 this.perspectives = perspectives;
46 public boolean shouldExecuteOnProject(Project project) {
51 public Metric generatesFalsePositiveMeasure() {
52 return CoreMetrics.FALSE_POSITIVE_ISSUES;
55 public void decorate(Resource resource, DecoratorContext context) {
56 Issuable issuable = perspectives.as(Issuable.class, resource);
57 if (issuable != null) {
58 int falsePositives = 0;
59 for (Issue issue : issuable.issues()) {
60 if (Issue.RESOLUTION_FALSE_POSITIVE.equals(issue.resolution())) {
64 saveMeasure(context, CoreMetrics.FALSE_POSITIVE_ISSUES, falsePositives);
68 private void saveMeasure(DecoratorContext context, Metric metric, int value) {
69 context.saveMeasure(metric, (double) (value + sumChildren(context, metric)));
72 private int sumChildren(DecoratorContext context, Metric metric) {
73 return MeasureUtils.sum(true, context.getChildrenMeasures(metric)).intValue();
77 public String toString() {
78 return getClass().getSimpleName();