aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2012-04-02 12:10:09 +0200
committerFabrice Bellingard <bellingard@gmail.com>2012-04-02 12:10:09 +0200
commit3cc4c6560d6839656bdc80346ab2bdd5e3e7406e (patch)
treef706551c5ec800e9387e65dc26e5f8a810ed726e /plugins
parente6d39ea35a03bb60abdad7e31b427c6763ab0d9d (diff)
parent21fd3dd8ad5bb8868edc53c9b53bf30be8b2d748 (diff)
downloadsonarqube-3cc4c6560d6839656bdc80346ab2bdd5e3e7406e.tar.gz
sonarqube-3cc4c6560d6839656bdc80346ab2bdd5e3e7406e.zip
Merge branch 'current'
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TimeMachineDashboard.java42
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TimeMachineDashboardTest.java47
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/JavaSourceImporter.java17
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java2
4 files changed, 86 insertions, 22 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TimeMachineDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TimeMachineDashboard.java
index e57df8edb6f..257e17abe8f 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TimeMachineDashboard.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TimeMachineDashboard.java
@@ -31,8 +31,6 @@ import org.sonar.api.web.DashboardTemplate;
*/
public final class TimeMachineDashboard extends DashboardTemplate {
- private static final String TIME_MACHINE_ID = "time_machine";
- private static final String DISPLAY_SPARK_LINE = "displaySparkLine";
private static final String METRIC1 = "metric1";
private static final String METRIC2 = "metric2";
private static final String METRIC3 = "metric3";
@@ -60,9 +58,8 @@ public final class TimeMachineDashboard extends DashboardTemplate {
timelineWidget.setProperty(METRIC1, "complexity");
timelineWidget.setProperty(METRIC2, "violations_density");
timelineWidget.setProperty(METRIC3, "coverage");
-
- Widget sizeTimeMachineWidget = dashboard.addWidget(TIME_MACHINE_ID, 1);
- sizeTimeMachineWidget.setProperty(DISPLAY_SPARK_LINE, "true");
+
+ Widget sizeTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard);
sizeTimeMachineWidget.setProperty(METRIC1, "ncloc");
sizeTimeMachineWidget.setProperty(METRIC2, "lines");
sizeTimeMachineWidget.setProperty(METRIC3, "statements");
@@ -70,16 +67,14 @@ public final class TimeMachineDashboard extends DashboardTemplate {
sizeTimeMachineWidget.setProperty(METRIC5, "classes");
sizeTimeMachineWidget.setProperty(METRIC6, "functions");
sizeTimeMachineWidget.setProperty(METRIC7, "accessors");
-
- Widget commentsTimeMachineWidget = dashboard.addWidget(TIME_MACHINE_ID, 1);
- commentsTimeMachineWidget.setProperty(DISPLAY_SPARK_LINE, "true");
+
+ Widget commentsTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard);
commentsTimeMachineWidget.setProperty(METRIC1, "comment_lines_density");
commentsTimeMachineWidget.setProperty(METRIC2, "comment_lines");
commentsTimeMachineWidget.setProperty(METRIC3, "public_documented_api_density");
commentsTimeMachineWidget.setProperty(METRIC4, "public_undocumented_api");
-
- Widget duplicationTimeMachineWidget = dashboard.addWidget(TIME_MACHINE_ID, 1);
- duplicationTimeMachineWidget.setProperty(DISPLAY_SPARK_LINE, "true");
+
+ Widget duplicationTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard);
duplicationTimeMachineWidget.setProperty(METRIC1, "duplicated_lines_density");
duplicationTimeMachineWidget.setProperty(METRIC2, "duplicated_lines");
duplicationTimeMachineWidget.setProperty(METRIC3, "duplicated_blocks");
@@ -87,8 +82,7 @@ public final class TimeMachineDashboard extends DashboardTemplate {
}
private void addSecondColumn(Dashboard dashboard) {
- Widget rulesTimeMachineWidget = dashboard.addWidget(TIME_MACHINE_ID, 2);
- rulesTimeMachineWidget.setProperty(DISPLAY_SPARK_LINE, "true");
+ Widget rulesTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard);
rulesTimeMachineWidget.setProperty(METRIC1, "violations");
rulesTimeMachineWidget.setProperty(METRIC2, "violation_density");
rulesTimeMachineWidget.setProperty(METRIC3, "blocker_violations");
@@ -98,15 +92,13 @@ public final class TimeMachineDashboard extends DashboardTemplate {
rulesTimeMachineWidget.setProperty(METRIC7, "info_violations");
rulesTimeMachineWidget.setProperty(METRIC7, "weighted_violations");
- Widget complexityTimeMachineWidget = dashboard.addWidget(TIME_MACHINE_ID, 2);
- complexityTimeMachineWidget.setProperty(DISPLAY_SPARK_LINE, "true");
+ Widget complexityTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard);
complexityTimeMachineWidget.setProperty(METRIC1, "complexity");
complexityTimeMachineWidget.setProperty(METRIC2, "function_complexity");
complexityTimeMachineWidget.setProperty(METRIC3, "class_complexity");
complexityTimeMachineWidget.setProperty(METRIC4, "file_complexity");
- Widget testsTimeMachineWidget = dashboard.addWidget(TIME_MACHINE_ID, 2);
- testsTimeMachineWidget.setProperty(DISPLAY_SPARK_LINE, "true");
+ Widget testsTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard);
testsTimeMachineWidget.setProperty(METRIC1, "coverage");
testsTimeMachineWidget.setProperty(METRIC2, "line_coverage");
testsTimeMachineWidget.setProperty(METRIC3, "branch_coverage");
@@ -117,4 +109,18 @@ public final class TimeMachineDashboard extends DashboardTemplate {
testsTimeMachineWidget.setProperty(METRIC7, "test_execution_time");
}
-} \ No newline at end of file
+ private Widget addTimeMachineWidgetOnFirstColumn(Dashboard dashboard) {
+ return addTimeMachineWidget(dashboard, 1);
+ }
+
+ private Widget addTimeMachineWidgetOnSecondColumn(Dashboard dashboard) {
+ return addTimeMachineWidget(dashboard, 2);
+ }
+
+ private Widget addTimeMachineWidget(Dashboard dashboard, int columnIndex) {
+ Widget widget = dashboard.addWidget("time_machine", columnIndex);
+ widget.setProperty("displaySparkLine", "true");
+ return widget;
+ }
+
+}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TimeMachineDashboardTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TimeMachineDashboardTest.java
new file mode 100644
index 00000000000..59463ce21f3
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TimeMachineDashboardTest.java
@@ -0,0 +1,47 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * 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.core.dashboards;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.sonar.api.web.Dashboard;
+import org.sonar.api.web.Dashboard.Widget;
+import org.sonar.api.web.DashboardLayout;
+
+public class TimeMachineDashboardTest {
+ @Test
+ public void shouldCreateDashboard() {
+ TimeMachineDashboard template = new TimeMachineDashboard();
+ Dashboard hotspots = template.createDashboard();
+ assertThat(template.getName(), is("TimeMachine"));
+ assertThat(hotspots.getLayout(), is(DashboardLayout.TWO_COLUMNS));
+ Collection<Widget> widgets = hotspots.getWidgets();
+ assertThat(widgets.size(), is(7));
+ for (Widget widget : widgets) {
+ if (widget.getId().equals("time_machine")) {
+ assertThat(widget.getProperty("displaySparkLine"), is("true"));
+ }
+ }
+ }
+}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/JavaSourceImporter.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/JavaSourceImporter.java
index 3adb55000fd..2845c2ac94d 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/JavaSourceImporter.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/JavaSourceImporter.java
@@ -79,15 +79,24 @@ public final class JavaSourceImporter implements Sensor {
}
void importSource(SensorContext context, JavaFile javaFile, InputFile inputFile, Charset sourcesEncoding) {
+ String source = null;
+ if (importSources) {
+ source = loadSourceFromFile(inputFile, sourcesEncoding);
+ }
+
try {
context.index(javaFile);
-
- if (importSources) {
- String source = FileUtils.readFileToString(inputFile.getFile(), sourcesEncoding.name());
+ if (source != null) {
context.saveSource(javaFile, source);
}
} catch (SonarException e) {
- throw e;
+ throw new SonarException(e.getMessage() + ", on file: " + inputFile.getFile().getAbsolutePath(), e);
+ }
+ }
+
+ protected String loadSourceFromFile(InputFile inputFile, Charset sourcesEncoding) {
+ try {
+ return FileUtils.readFileToString(inputFile.getFile(), sourcesEncoding.name());
} catch (Exception e) {
throw new SonarException("Unable to read and import the source file : '" + inputFile.getFile().getAbsolutePath() + "' with the charset : '"
+ sourcesEncoding.name() + "'.", e);
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java
index 9727e5e525e..0cd45d4e473 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java
@@ -97,6 +97,8 @@ public class JavaSourceImporterTest {
thrown.expect(SonarException.class);
thrown.expectMessage("Duplicate source for resource");
+ thrown.expectMessage(", on file:");
+ thrown.expectMessage("UndocumentedApi.java");
importer.importSource(context, javaFile, inputFile, Charset.defaultCharset());
}