aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-01-21 17:55:47 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-01-21 17:55:47 +0100
commit9eaac602f7f0759ce8f67bcbb20f22d14bf3cfd1 (patch)
tree95a996dc071c91efe2a4547b1851845889727517 /plugins
parent67245675f16f9b185cf858f4209ef49b89ab03f6 (diff)
downloadsonarqube-9eaac602f7f0759ce8f67bcbb20f22d14bf3cfd1.tar.gz
sonarqube-9eaac602f7f0759ce8f67bcbb20f22d14bf3cfd1.zip
SONAR-1526 ResourceFilters are not used by Squid
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/CommentLinesDensityBridge.java43
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/CopyBasicMeasuresBridge.java72
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/OneToOneBridge.java49
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/PublicUndocumentedApiBridge.java23
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeFactoryTest.java4
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/CommentLinesDensityBridgeTest.java42
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/PublicUndocumentedApiBridgeTest.java9
7 files changed, 96 insertions, 146 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/CommentLinesDensityBridge.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/CommentLinesDensityBridge.java
deleted file mode 100644
index 1390403e08a..00000000000
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/CommentLinesDensityBridge.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.squid.bridges;
-
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.utils.ParsingUtils;
-import org.sonar.squid.api.SourceCode;
-import org.sonar.squid.measures.Metric;
-
-public class CommentLinesDensityBridge extends BasicBridge {
-
- protected CommentLinesDensityBridge() {
- super(false);
- }
-
- @Override
- protected final void onResource(SourceCode squidResource, Resource sonarResource) {
- if (squidResource.getDouble(Metric.LINES) > 0) {
- context.saveMeasure(
- sonarResource,
- CoreMetrics.COMMENT_LINES_DENSITY,
- ParsingUtils.scaleValue(squidResource.getDouble(Metric.COMMENT_LINES_DENSITY) * 100, 2));
- }
- }
-}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/CopyBasicMeasuresBridge.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/CopyBasicMeasuresBridge.java
new file mode 100644
index 00000000000..94f7b3bdd65
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/CopyBasicMeasuresBridge.java
@@ -0,0 +1,72 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.squid.bridges;
+
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.utils.ParsingUtils;
+import org.sonar.java.api.JavaClass;
+import org.sonar.java.api.JavaMethod;
+import org.sonar.squid.api.SourceClass;
+import org.sonar.squid.api.SourceCode;
+import org.sonar.squid.api.SourceFile;
+import org.sonar.squid.api.SourceMethod;
+import org.sonar.squid.measures.Metric;
+
+public final class CopyBasicMeasuresBridge extends Bridge {
+
+ protected CopyBasicMeasuresBridge() {
+ super(false);
+ }
+
+ @Override
+ public void onFile(SourceFile squidFile, Resource sonarResource) {
+ copyStandard(squidFile, sonarResource);
+ copy(squidFile, sonarResource, Metric.CLASSES, CoreMetrics.CLASSES);
+ copy(squidFile, sonarResource, Metric.FILES, CoreMetrics.FILES);
+ context.saveMeasure(sonarResource, CoreMetrics.PUBLIC_DOCUMENTED_API_DENSITY, ParsingUtils.scaleValue(squidFile.getDouble(Metric.PUBLIC_DOCUMENTED_API_DENSITY) * 100, 2));
+ }
+
+ @Override
+ public void onClass(SourceClass squidClass, JavaClass sonarClass) {
+ copyStandard(squidClass, sonarClass);
+ }
+
+ @Override
+ public void onMethod(SourceMethod squidMethod, JavaMethod sonarMethod) {
+ copyStandard(squidMethod, sonarMethod);
+ }
+
+ private void copyStandard(SourceCode squidCode, Resource sonarResource) {
+ copy(squidCode, sonarResource, Metric.LINES_OF_CODE, CoreMetrics.NCLOC);
+ copy(squidCode, sonarResource, Metric.LINES, CoreMetrics.LINES);
+ copy(squidCode, sonarResource, Metric.COMMENT_LINES_WITHOUT_HEADER, CoreMetrics.COMMENT_LINES);
+ copy(squidCode, sonarResource, Metric.METHODS, CoreMetrics.FUNCTIONS);
+ copy(squidCode, sonarResource, Metric.ACCESSORS, CoreMetrics.ACCESSORS);
+ copy(squidCode, sonarResource, Metric.PUBLIC_API, CoreMetrics.PUBLIC_API);
+ copy(squidCode, sonarResource, Metric.COMPLEXITY, CoreMetrics.COMPLEXITY);
+ copy(squidCode, sonarResource, Metric.STATEMENTS, CoreMetrics.STATEMENTS);
+ copy(squidCode, sonarResource, Metric.COMMENTED_OUT_CODE_LINES, CoreMetrics.COMMENTED_OUT_CODE_LINES);
+ }
+
+ private void copy(SourceCode squidResource, Resource sonarResource, Metric squidMetric, org.sonar.api.measures.Metric sonarMetric) {
+ context.saveMeasure(sonarResource, sonarMetric, squidResource.getDouble(squidMetric));
+ }
+}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/OneToOneBridge.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/OneToOneBridge.java
deleted file mode 100644
index 705a70fa1f0..00000000000
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/OneToOneBridge.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.squid.bridges;
-
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.utils.ParsingUtils;
-import org.sonar.squid.api.SourceCode;
-import org.sonar.squid.measures.Metric;
-
-public class OneToOneBridge extends BasicBridge {
-
- protected OneToOneBridge() {
- super(false);
- }
-
- @Override
- protected void onResource(SourceCode squidResource, Resource sonarResource) {
- context.saveMeasure(sonarResource, CoreMetrics.NCLOC, squidResource.getDouble(Metric.LINES_OF_CODE));
- context.saveMeasure(sonarResource, CoreMetrics.LINES, squidResource.getDouble(Metric.LINES));
- context.saveMeasure(sonarResource, CoreMetrics.COMMENT_LINES, squidResource.getDouble(Metric.COMMENT_LINES_WITHOUT_HEADER));
- context.saveMeasure(sonarResource, CoreMetrics.FUNCTIONS, squidResource.getDouble(Metric.METHODS));
- context.saveMeasure(sonarResource, CoreMetrics.ACCESSORS, squidResource.getDouble(Metric.ACCESSORS));
- context.saveMeasure(sonarResource, CoreMetrics.PUBLIC_API, squidResource.getDouble(Metric.PUBLIC_API));
- context.saveMeasure(sonarResource, CoreMetrics.CLASSES, squidResource.getDouble(Metric.CLASSES));
- context.saveMeasure(sonarResource, CoreMetrics.COMPLEXITY, squidResource.getDouble(Metric.COMPLEXITY));
- context.saveMeasure(sonarResource, CoreMetrics.STATEMENTS, squidResource.getDouble(Metric.STATEMENTS));
- context.saveMeasure(sonarResource, CoreMetrics.FILES, squidResource.getDouble(Metric.FILES));
- context.saveMeasure(sonarResource, CoreMetrics.COMMENTED_OUT_CODE_LINES, squidResource.getDouble(Metric.COMMENTED_OUT_CODE_LINES));
- context.saveMeasure(sonarResource, CoreMetrics.PUBLIC_DOCUMENTED_API_DENSITY, ParsingUtils.scaleValue(squidResource.getDouble(Metric.PUBLIC_DOCUMENTED_API_DENSITY) * 100, 2));
- }
-}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/PublicUndocumentedApiBridge.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/PublicUndocumentedApiBridge.java
index c0c4ca0af86..bd455b46187 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/PublicUndocumentedApiBridge.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/PublicUndocumentedApiBridge.java
@@ -21,17 +21,36 @@ package org.sonar.plugins.squid.bridges;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.resources.Resource;
+import org.sonar.java.api.JavaClass;
+import org.sonar.java.api.JavaMethod;
+import org.sonar.squid.api.SourceClass;
import org.sonar.squid.api.SourceCode;
+import org.sonar.squid.api.SourceFile;
+import org.sonar.squid.api.SourceMethod;
import org.sonar.squid.measures.Metric;
-public class PublicUndocumentedApiBridge extends BasicBridge {
+public final class PublicUndocumentedApiBridge extends Bridge {
protected PublicUndocumentedApiBridge() {
super(false);
}
@Override
- protected void onResource(SourceCode squidResource, Resource sonarResource) {
+ public void onFile(SourceFile squidFile, Resource sonarFile) {
+ copyValue(squidFile, sonarFile);
+ }
+
+ @Override
+ public void onClass(SourceClass squidClass, JavaClass sonarClass) {
+ copyValue(squidClass, sonarClass);
+ }
+
+ @Override
+ public void onMethod(SourceMethod squidMethod, JavaMethod sonarMethod) {
+ copyValue(squidMethod, sonarMethod);
+ }
+
+ private void copyValue(SourceCode squidResource, Resource sonarResource) {
double undocumentedApi = squidResource.getDouble(Metric.PUBLIC_API) - squidResource.getInt(Metric.PUBLIC_DOC_API);
context.saveMeasure(sonarResource, CoreMetrics.PUBLIC_UNDOCUMENTED_API, undocumentedApi);
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeFactoryTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeFactoryTest.java
index cbf4ed923ad..9b5e847bfc1 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeFactoryTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeFactoryTest.java
@@ -32,14 +32,14 @@ public class BridgeFactoryTest {
public void createForSourceAnalysis() {
List<Bridge> astBridges = BridgeFactory.create(false, null, null, null, null, null);
assertFalse(has(astBridges, DesignBridge.class));
- assertTrue(has(astBridges, OneToOneBridge.class));
+ assertTrue(has(astBridges, CopyBasicMeasuresBridge.class));
}
@Test
public void createForSourceAndBytecodeAnalysis() {
List<Bridge> allBridges = BridgeFactory.create(true, null, null, null, null, null);
assertTrue(has(allBridges, DesignBridge.class));
- assertTrue(has(allBridges, OneToOneBridge.class));
+ assertTrue(has(allBridges, CopyBasicMeasuresBridge.class));
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/CommentLinesDensityBridgeTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/CommentLinesDensityBridgeTest.java
deleted file mode 100644
index eac3a5017e1..00000000000
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/CommentLinesDensityBridgeTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.squid.bridges;
-
-import org.junit.Test;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.JavaPackage;
-
-import static org.hamcrest.number.IsCloseTo.closeTo;
-import static org.mockito.Matchers.anyDouble;
-import static org.mockito.Matchers.doubleThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-
-public class CommentLinesDensityBridgeTest extends BridgeTestCase {
-
- @Test
- public void commentLineDensity() {
- verify(context).saveMeasure(eq(new JavaFile("org.apache.struts.config.BaseConfig")), eq(CoreMetrics.COMMENT_LINES_DENSITY), doubleThat(closeTo(48.0, 0.1)));
- verify(context).saveMeasure(eq(new JavaPackage("org.apache.struts.config")), eq(CoreMetrics.COMMENT_LINES_DENSITY), doubleThat(closeTo(35.2, 0.1)));
- verify(context).saveMeasure(eq(project), eq(CoreMetrics.COMMENT_LINES_DENSITY), anyDouble());
- }
-
-}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/PublicUndocumentedApiBridgeTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/PublicUndocumentedApiBridgeTest.java
index 193cb8efd28..435af35c529 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/PublicUndocumentedApiBridgeTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/PublicUndocumentedApiBridgeTest.java
@@ -22,22 +22,15 @@ package org.sonar.plugins.squid.bridges;
import org.junit.Test;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.JavaPackage;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.mockito.Matchers.doubleThat;
-import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
public class PublicUndocumentedApiBridgeTest extends BridgeTestCase {
@Test
- public void commentLineDensity() {
+ public void publicUndocumentedApi() {
verify(context).saveMeasure(new JavaFile("org.apache.struts.config.BaseConfig"), CoreMetrics.PUBLIC_UNDOCUMENTED_API, 0.0);
verify(context).saveMeasure(new JavaFile("org.apache.struts.config.ConfigHelper"), CoreMetrics.PUBLIC_UNDOCUMENTED_API, 4.0);
-
- verify(context).saveMeasure(eq(new JavaPackage("org.apache.struts.config")), eq(CoreMetrics.PUBLIC_UNDOCUMENTED_API), doubleThat(greaterThan(50.0)));
- verify(context).saveMeasure(eq(project), eq(CoreMetrics.PUBLIC_UNDOCUMENTED_API), doubleThat(greaterThan(200.0)));
}
}