2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2008-2011 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * Sonar 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 * Sonar 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
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.plugins.squid.bridges;
22 import org.sonar.api.measures.CoreMetrics;
23 import org.sonar.api.resources.Resource;
24 import org.sonar.api.utils.ParsingUtils;
25 import org.sonar.java.api.JavaClass;
26 import org.sonar.java.api.JavaMethod;
27 import org.sonar.squid.api.SourceClass;
28 import org.sonar.squid.api.SourceCode;
29 import org.sonar.squid.api.SourceFile;
30 import org.sonar.squid.api.SourceMethod;
31 import org.sonar.squid.measures.Metric;
33 public final class CopyBasicMeasuresBridge extends Bridge {
35 protected CopyBasicMeasuresBridge() {
40 public void onFile(SourceFile squidFile, Resource sonarResource) {
41 copyStandard(squidFile, sonarResource);
42 copy(squidFile, sonarResource, Metric.FILES, CoreMetrics.FILES);
43 context.saveMeasure(sonarResource, CoreMetrics.PUBLIC_DOCUMENTED_API_DENSITY, ParsingUtils.scaleValue(squidFile.getDouble(Metric.PUBLIC_DOCUMENTED_API_DENSITY) * 100, 2));
47 public void onClass(SourceClass squidClass, JavaClass sonarClass) {
48 copyStandard(squidClass, sonarClass);
52 public void onMethod(SourceMethod squidMethod, JavaMethod sonarMethod) {
53 copyStandard(squidMethod, sonarMethod);
56 private void copyStandard(SourceCode squidCode, Resource sonarResource) {
57 copy(squidCode, sonarResource, Metric.LINES_OF_CODE, CoreMetrics.NCLOC);
58 copy(squidCode, sonarResource, Metric.LINES, CoreMetrics.LINES);
59 copy(squidCode, sonarResource, Metric.COMMENT_LINES_WITHOUT_HEADER, CoreMetrics.COMMENT_LINES);
60 copy(squidCode, sonarResource, Metric.PUBLIC_API, CoreMetrics.PUBLIC_API);
61 copy(squidCode, sonarResource, Metric.COMPLEXITY, CoreMetrics.COMPLEXITY);
62 copy(squidCode, sonarResource, Metric.STATEMENTS, CoreMetrics.STATEMENTS);
63 copy(squidCode, sonarResource, Metric.COMMENTED_OUT_CODE_LINES, CoreMetrics.COMMENTED_OUT_CODE_LINES);
68 private void copy(SourceCode squidResource, Resource sonarResource, Metric squidMetric, org.sonar.api.measures.Metric sonarMetric) {
69 context.saveMeasure(sonarResource, sonarMetric, squidResource.getDouble(squidMetric));