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.
21 package org.sonar.api.batch;
23 import org.sonar.api.measures.CoreMetrics;
24 import org.sonar.api.measures.CountDistributionBuilder;
25 import org.sonar.api.measures.Measure;
26 import org.sonar.api.measures.Metric;
27 import org.sonar.api.resources.Language;
28 import org.sonar.api.resources.Project;
29 import org.sonar.api.resources.Resource;
32 * @deprecated since 2.1, a formula has been implemented on the metric, so no need to have decorator anymore
36 public abstract class AbstractFunctionComplexityDistributionDecorator implements Decorator {
38 private CountDistributionBuilder builder = new CountDistributionBuilder(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
39 private Language language;
41 public AbstractFunctionComplexityDistributionDecorator(Language language) {
42 this.language = language;
46 public Metric generatesMetrics() {
47 return CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION;
50 public boolean shouldExecuteOnProject(Project project) {
51 return language.equals(project.getLanguage());
54 public void decorate(Resource resource, DecoratorContext context) {
55 if (shouldDecorateResource(context)) {
57 saveDistribution(context);
61 private void saveDistribution(DecoratorContext context) {
62 for (Measure childMeasure : context.getChildrenMeasures(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION)) {
63 builder.add(childMeasure);
66 if (!builder.isEmpty()) {
67 context.saveMeasure(builder.build());
71 private void reset() {
75 private boolean shouldDecorateResource(DecoratorContext context) {
76 return context.getMeasure(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION) == null;
80 public String toString() {
81 return getClass().getSimpleName();