001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.plugins.core.dashboards;
021
022 import org.sonar.api.web.Dashboard;
023 import org.sonar.api.web.Dashboard.Widget;
024 import org.sonar.api.web.DashboardLayout;
025 import org.sonar.api.web.DashboardTemplate;
026
027 /**
028 * Time Machine dashboard for Sonar
029 *
030 * @since 3.0
031 */
032 public final class TimeMachineDashboard extends DashboardTemplate {
033
034 private static final String METRIC1 = "metric1";
035 private static final String METRIC2 = "metric2";
036 private static final String METRIC3 = "metric3";
037 private static final String METRIC4 = "metric4";
038 private static final String METRIC5 = "metric5";
039 private static final String METRIC6 = "metric6";
040 private static final String METRIC7 = "metric7";
041
042 @Override
043 public String getName() {
044 return "TimeMachine";
045 }
046
047 @Override
048 public Dashboard createDashboard() {
049 Dashboard dashboard = Dashboard.create();
050 dashboard.setLayout(DashboardLayout.TWO_COLUMNS);
051 addFirstColumn(dashboard);
052 addSecondColumn(dashboard);
053 return dashboard;
054 }
055
056 private void addFirstColumn(Dashboard dashboard) {
057 Widget timelineWidget = dashboard.addWidget("timeline", 1);
058 timelineWidget.setProperty(METRIC1, "complexity");
059 timelineWidget.setProperty(METRIC2, "violations_density");
060 timelineWidget.setProperty(METRIC3, "coverage");
061
062 Widget sizeTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard);
063 sizeTimeMachineWidget.setProperty(METRIC1, "ncloc");
064 sizeTimeMachineWidget.setProperty(METRIC2, "lines");
065 sizeTimeMachineWidget.setProperty(METRIC3, "statements");
066 sizeTimeMachineWidget.setProperty(METRIC4, "files");
067 sizeTimeMachineWidget.setProperty(METRIC5, "classes");
068 sizeTimeMachineWidget.setProperty(METRIC6, "functions");
069 sizeTimeMachineWidget.setProperty(METRIC7, "accessors");
070
071 Widget commentsTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard);
072 commentsTimeMachineWidget.setProperty(METRIC1, "comment_lines_density");
073 commentsTimeMachineWidget.setProperty(METRIC2, "comment_lines");
074 commentsTimeMachineWidget.setProperty(METRIC3, "public_documented_api_density");
075 commentsTimeMachineWidget.setProperty(METRIC4, "public_undocumented_api");
076
077 Widget duplicationTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard);
078 duplicationTimeMachineWidget.setProperty(METRIC1, "duplicated_lines_density");
079 duplicationTimeMachineWidget.setProperty(METRIC2, "duplicated_lines");
080 duplicationTimeMachineWidget.setProperty(METRIC3, "duplicated_blocks");
081 duplicationTimeMachineWidget.setProperty(METRIC4, "duplicated_files");
082 }
083
084 private void addSecondColumn(Dashboard dashboard) {
085 Widget rulesTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard);
086 rulesTimeMachineWidget.setProperty(METRIC1, "violations");
087 rulesTimeMachineWidget.setProperty(METRIC2, "violation_density");
088 rulesTimeMachineWidget.setProperty(METRIC3, "blocker_violations");
089 rulesTimeMachineWidget.setProperty(METRIC4, "critical_violations");
090 rulesTimeMachineWidget.setProperty(METRIC5, "major_violations");
091 rulesTimeMachineWidget.setProperty(METRIC6, "minor_violations");
092 rulesTimeMachineWidget.setProperty(METRIC7, "info_violations");
093 rulesTimeMachineWidget.setProperty(METRIC7, "weighted_violations");
094
095 Widget complexityTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard);
096 complexityTimeMachineWidget.setProperty(METRIC1, "complexity");
097 complexityTimeMachineWidget.setProperty(METRIC2, "function_complexity");
098 complexityTimeMachineWidget.setProperty(METRIC3, "class_complexity");
099 complexityTimeMachineWidget.setProperty(METRIC4, "file_complexity");
100
101 Widget testsTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard);
102 testsTimeMachineWidget.setProperty(METRIC1, "coverage");
103 testsTimeMachineWidget.setProperty(METRIC2, "line_coverage");
104 testsTimeMachineWidget.setProperty(METRIC3, "branch_coverage");
105 testsTimeMachineWidget.setProperty(METRIC4, "test_success_density");
106 testsTimeMachineWidget.setProperty(METRIC5, "test_failures");
107 testsTimeMachineWidget.setProperty(METRIC6, "test_errors");
108 testsTimeMachineWidget.setProperty(METRIC7, "tests");
109 testsTimeMachineWidget.setProperty(METRIC7, "test_execution_time");
110 }
111
112 private Widget addTimeMachineWidgetOnFirstColumn(Dashboard dashboard) {
113 return addTimeMachineWidget(dashboard, 1);
114 }
115
116 private Widget addTimeMachineWidgetOnSecondColumn(Dashboard dashboard) {
117 return addTimeMachineWidget(dashboard, 2);
118 }
119
120 private Widget addTimeMachineWidget(Dashboard dashboard, int columnIndex) {
121 Widget widget = dashboard.addWidget("time_machine", columnIndex);
122 widget.setProperty("displaySparkLine", "true");
123 return widget;
124 }
125
126 }