]> source.dussan.org Git - sonarqube.git/blob
13c85036c1d8b9a466e9e86fa12da136abe81321
[sonarqube.git] /
1 /*
2  * SonarQube, open source software quality management tool.
3  * Copyright (C) 2008-2014 SonarSource
4  * mailto:contact AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.server.dashboard.template;
21
22 import org.sonar.api.measures.CoreMetrics;
23 import org.sonar.api.web.Dashboard;
24 import org.sonar.api.web.Dashboard.Widget;
25 import org.sonar.api.web.DashboardLayout;
26 import org.sonar.api.web.DashboardTemplate;
27
28 /**
29  * Time Machine dashboard
30  *
31  * @since 3.0
32  */
33 public final class ProjectTimeMachineDashboard extends DashboardTemplate {
34
35   private static final String METRIC1 = "metric1";
36   private static final String METRIC2 = "metric2";
37   private static final String METRIC3 = "metric3";
38   private static final String METRIC4 = "metric4";
39   private static final String METRIC5 = "metric5";
40   private static final String METRIC6 = "metric6";
41   private static final String METRIC7 = "metric7";
42   private static final String METRIC8 = "metric8";
43
44   @Override
45   public String getName() {
46     return "TimeMachine";
47   }
48
49   @Override
50   public Dashboard createDashboard() {
51     Dashboard dashboard = Dashboard.create();
52     dashboard.setLayout(DashboardLayout.TWO_COLUMNS);
53     addFirstColumn(dashboard);
54     addSecondColumn(dashboard);
55     return dashboard;
56   }
57
58   private static void addFirstColumn(Dashboard dashboard) {
59     Widget timelineWidget = dashboard.addWidget("timeline", 1);
60     timelineWidget.setProperty(METRIC1, CoreMetrics.COMPLEXITY_KEY);
61     timelineWidget.setProperty(METRIC2, CoreMetrics.TECHNICAL_DEBT_KEY);
62     timelineWidget.setProperty(METRIC3, CoreMetrics.COVERAGE_KEY);
63
64     Widget sizeTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard);
65     sizeTimeMachineWidget.setProperty(METRIC1, CoreMetrics.NCLOC_KEY);
66     sizeTimeMachineWidget.setProperty(METRIC2, CoreMetrics.LINES_KEY);
67     sizeTimeMachineWidget.setProperty(METRIC3, CoreMetrics.STATEMENTS_KEY);
68     sizeTimeMachineWidget.setProperty(METRIC4, CoreMetrics.FILES_KEY);
69     sizeTimeMachineWidget.setProperty(METRIC5, CoreMetrics.CLASSES_KEY);
70     sizeTimeMachineWidget.setProperty(METRIC6, CoreMetrics.FUNCTIONS_KEY);
71     sizeTimeMachineWidget.setProperty(METRIC7, CoreMetrics.ACCESSORS_KEY);
72
73     Widget commentsTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard);
74     commentsTimeMachineWidget.setProperty(METRIC1, CoreMetrics.COMMENT_LINES_DENSITY_KEY);
75     commentsTimeMachineWidget.setProperty(METRIC2, CoreMetrics.COMMENT_LINES_KEY);
76     commentsTimeMachineWidget.setProperty(METRIC3, CoreMetrics.PUBLIC_DOCUMENTED_API_DENSITY_KEY);
77     commentsTimeMachineWidget.setProperty(METRIC4, CoreMetrics.PUBLIC_UNDOCUMENTED_API_KEY);
78
79     Widget duplicationTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard);
80     duplicationTimeMachineWidget.setProperty(METRIC1, CoreMetrics.DUPLICATED_LINES_DENSITY_KEY);
81     duplicationTimeMachineWidget.setProperty(METRIC2, CoreMetrics.DUPLICATED_LINES_KEY);
82     duplicationTimeMachineWidget.setProperty(METRIC3, CoreMetrics.DUPLICATED_BLOCKS_KEY);
83     duplicationTimeMachineWidget.setProperty(METRIC4, CoreMetrics.DUPLICATED_FILES_KEY);
84   }
85
86   private static void addSecondColumn(Dashboard dashboard) {
87     Widget rulesTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard);
88     rulesTimeMachineWidget.setProperty(METRIC1, CoreMetrics.VIOLATIONS_KEY);
89     rulesTimeMachineWidget.setProperty(METRIC2, CoreMetrics.BLOCKER_VIOLATIONS_KEY);
90     rulesTimeMachineWidget.setProperty(METRIC3, CoreMetrics.CRITICAL_VIOLATIONS_KEY);
91     rulesTimeMachineWidget.setProperty(METRIC4, CoreMetrics.MAJOR_VIOLATIONS_KEY);
92     rulesTimeMachineWidget.setProperty(METRIC5, CoreMetrics.MINOR_VIOLATIONS_KEY);
93     rulesTimeMachineWidget.setProperty(METRIC6, CoreMetrics.INFO_VIOLATIONS_KEY);
94     rulesTimeMachineWidget.setProperty(METRIC7, CoreMetrics.TECHNICAL_DEBT_KEY);
95
96     Widget complexityTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard);
97     complexityTimeMachineWidget.setProperty(METRIC1, CoreMetrics.COMPLEXITY_KEY);
98     complexityTimeMachineWidget.setProperty(METRIC2, CoreMetrics.FUNCTION_COMPLEXITY_KEY);
99     complexityTimeMachineWidget.setProperty(METRIC3, CoreMetrics.CLASS_COMPLEXITY_KEY);
100     complexityTimeMachineWidget.setProperty(METRIC4, CoreMetrics.FILE_COMPLEXITY_KEY);
101
102     Widget testsTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard);
103     testsTimeMachineWidget.setProperty(METRIC1, CoreMetrics.COVERAGE_KEY);
104     testsTimeMachineWidget.setProperty(METRIC2, CoreMetrics.LINE_COVERAGE_KEY);
105     testsTimeMachineWidget.setProperty(METRIC3, CoreMetrics.BRANCH_COVERAGE_KEY);
106     testsTimeMachineWidget.setProperty(METRIC4, CoreMetrics.TEST_SUCCESS_DENSITY_KEY);
107     testsTimeMachineWidget.setProperty(METRIC5, CoreMetrics.TEST_FAILURES_KEY);
108     testsTimeMachineWidget.setProperty(METRIC6, CoreMetrics.TEST_ERRORS_KEY);
109     testsTimeMachineWidget.setProperty(METRIC7, CoreMetrics.TESTS_KEY);
110     testsTimeMachineWidget.setProperty(METRIC8, CoreMetrics.TEST_EXECUTION_TIME_KEY);
111   }
112
113   private static Widget addTimeMachineWidgetOnFirstColumn(Dashboard dashboard) {
114     return addTimeMachineWidget(dashboard, 1);
115   }
116
117   private static Widget addTimeMachineWidgetOnSecondColumn(Dashboard dashboard) {
118     return addTimeMachineWidget(dashboard, 2);
119   }
120
121   private static Widget addTimeMachineWidget(Dashboard dashboard, int columnIndex) {
122     Widget widget = dashboard.addWidget("time_machine", columnIndex);
123     widget.setProperty("displaySparkLine", "true");
124     return widget;
125   }
126
127 }