001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2009 SonarSource SA
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.api.measures;
021
022 import org.apache.commons.lang.StringUtils;
023 import org.sonar.api.utils.SonarException;
024
025 import java.lang.reflect.Field;
026 import java.util.ArrayList;
027 import java.util.HashSet;
028 import java.util.List;
029 import java.util.Set;
030
031 /**
032 * @since 1.10
033 */
034 public final class CoreMetrics {
035
036 private CoreMetrics() {
037 // only static stuff
038 }
039
040 public static final String DOMAIN_SIZE = "Size";
041 public static final String DOMAIN_TESTS = "Tests";
042 public static final String DOMAIN_COMPLEXITY = "Complexity";
043 public static final String DOMAIN_DOCUMENTATION = "Documentation";
044 public static final String DOMAIN_RULES = "Rules";
045
046 /**
047 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
048 */
049 @Deprecated
050 public static final String DOMAIN_RULE_CATEGORIES = "Rule categories";
051
052 public static final String DOMAIN_GENERAL = "General";
053 public static final String DOMAIN_DUPLICATION = "Duplication";
054 public static final String DOMAIN_DESIGN = "Design";
055
056 public static final String LINES_KEY = "lines";
057 public static final Metric LINES = new Metric(LINES_KEY, "Lines", "Lines", Metric.ValueType.INT, Metric.DIRECTION_WORST, false,
058 DOMAIN_SIZE).setFormula(new SumChildValuesFormula(false));
059
060 public static final String GENERATED_LINES_KEY = "generated_lines";
061 public static final Metric GENERATED_LINES = new Metric(GENERATED_LINES_KEY, "Generated Lines", "Number of generated lines",
062 Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_SIZE).setBestValue(0.0).setOptimizedBestValue(true).setFormula(
063 new SumChildValuesFormula(false));
064
065 public static final String NCLOC_KEY = "ncloc";
066 public static final Metric NCLOC = new Metric(NCLOC_KEY, "Lines of code", "Non Commenting Lines of Code", Metric.ValueType.INT,
067 Metric.DIRECTION_WORST, false, DOMAIN_SIZE).setFormula(new SumChildValuesFormula(false));
068
069 public static final String GENERATED_NCLOC_KEY = "generated_ncloc";
070 public static final Metric GENERATED_NCLOC = new Metric(GENERATED_NCLOC_KEY, "Generated lines of code",
071 "Generated non Commenting Lines of Code", Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_SIZE).setBestValue(0.0)
072 .setOptimizedBestValue(true).setFormula(new SumChildValuesFormula(false));
073
074 public static final String CLASSES_KEY = "classes";
075 public static final Metric CLASSES = new Metric(CLASSES_KEY, "Classes", "Classes", Metric.ValueType.INT, Metric.DIRECTION_WORST, false,
076 DOMAIN_SIZE).setFormula(new SumChildValuesFormula(false));
077
078 public static final String FILES_KEY = "files";
079 public static final Metric FILES = new Metric(FILES_KEY, "Files", "Number of files", Metric.ValueType.INT, Metric.DIRECTION_WORST, false,
080 DOMAIN_SIZE);
081
082 public static final String DIRECTORIES_KEY = "directories";
083 public static final Metric DIRECTORIES = new Metric(DIRECTORIES_KEY, "Directories", "Directories", Metric.ValueType.INT,
084 Metric.DIRECTION_WORST, false, DOMAIN_SIZE);
085
086 public static final String PACKAGES_KEY = "packages";
087 public static final Metric PACKAGES = new Metric(PACKAGES_KEY, "Packages", "Packages", Metric.ValueType.INT, Metric.DIRECTION_WORST,
088 false, DOMAIN_SIZE).setFormula(new SumChildValuesFormula(false));
089
090 public static final String FUNCTIONS_KEY = "functions";
091 public static final Metric FUNCTIONS = new Metric(FUNCTIONS_KEY, "Methods", "Methods", Metric.ValueType.INT, Metric.DIRECTION_WORST,
092 false, DOMAIN_SIZE).setFormula(new SumChildValuesFormula(false));
093
094 public static final String ACCESSORS_KEY = "accessors";
095 public static final Metric ACCESSORS = new Metric(ACCESSORS_KEY, "Accessors", "Accessors", Metric.ValueType.INT, Metric.DIRECTION_WORST,
096 false, DOMAIN_SIZE).setFormula(new SumChildValuesFormula(false));
097
098 public static final String PARAGRAPHS_KEY = "paragraphs";
099 public static final Metric PARAGRAPHS = new Metric(PARAGRAPHS_KEY, "Paragraphs", "Number of paragraphs", Metric.ValueType.INT,
100 Metric.DIRECTION_WORST, false, DOMAIN_SIZE).setFormula(new SumChildValuesFormula(false));
101
102 public static final String STATEMENTS_KEY = "statements";
103 public static final Metric STATEMENTS = new Metric(STATEMENTS_KEY, "Statements", "Number of statements", Metric.ValueType.INT,
104 Metric.DIRECTION_WORST, false, DOMAIN_SIZE).setFormula(new SumChildValuesFormula(false));
105
106 public static final String PUBLIC_API_KEY = "public_api";
107 public static final Metric PUBLIC_API = new Metric(PUBLIC_API_KEY, "Public API", "Public API", Metric.ValueType.INT,
108 Metric.DIRECTION_WORST, false, DOMAIN_SIZE).setFormula(new SumChildValuesFormula(false));
109
110 public static final String COMPLEXITY_KEY = "complexity";
111 public static final Metric COMPLEXITY = new Metric(COMPLEXITY_KEY, "Complexity", "Cyclomatic complexity", Metric.ValueType.INT,
112 Metric.DIRECTION_WORST, false, DOMAIN_COMPLEXITY).setFormula(new SumChildValuesFormula(false));
113
114 public static final String CLASS_COMPLEXITY_KEY = "class_complexity";
115 public static final Metric CLASS_COMPLEXITY = new Metric(CLASS_COMPLEXITY_KEY, "Complexity /class", "Complexity average by class",
116 Metric.ValueType.FLOAT, Metric.DIRECTION_WORST, true, DOMAIN_COMPLEXITY)
117 .setFormula(new AverageComplexityFormula(CoreMetrics.CLASSES));
118
119 public static final String FUNCTION_COMPLEXITY_KEY = "function_complexity";
120 public static final Metric FUNCTION_COMPLEXITY = new Metric(FUNCTION_COMPLEXITY_KEY, "Complexity /method",
121 "Complexity average by method", Metric.ValueType.FLOAT, Metric.DIRECTION_WORST, true, DOMAIN_COMPLEXITY)
122 .setFormula(new AverageComplexityFormula(CoreMetrics.FUNCTIONS));
123
124 public static final String FILE_COMPLEXITY_KEY = "file_complexity";
125 public static final Metric FILE_COMPLEXITY = new Metric(FILE_COMPLEXITY_KEY, "Complexity /file", "Complexity average by file",
126 Metric.ValueType.FLOAT, Metric.DIRECTION_WORST, true, DOMAIN_COMPLEXITY).setFormula(new AverageComplexityFormula(CoreMetrics.FILES));
127
128 public static final String PARAGRAPH_COMPLEXITY_KEY = "paragraph_complexity";
129 public static final Metric PARAGRAPH_COMPLEXITY = new Metric(PARAGRAPH_COMPLEXITY_KEY, "Complexity /paragraph",
130 "Complexity average by paragraph", Metric.ValueType.FLOAT, Metric.DIRECTION_WORST, true, DOMAIN_COMPLEXITY)
131 .setFormula(new AverageComplexityFormula(CoreMetrics.PARAGRAPHS));
132
133 public static final String CLASS_COMPLEXITY_DISTRIBUTION_KEY = "class_complexity_distribution";
134 public static final Metric CLASS_COMPLEXITY_DISTRIBUTION = new Metric(CLASS_COMPLEXITY_DISTRIBUTION_KEY,
135 "Classes distribution /complexity", "Classes distribution /complexity", Metric.ValueType.DISTRIB, Metric.DIRECTION_NONE, true,
136 DOMAIN_COMPLEXITY).setFormula(new SumChildDistributionFormula());
137
138 public static final String FUNCTION_COMPLEXITY_DISTRIBUTION_KEY = "function_complexity_distribution";
139 public static final Metric FUNCTION_COMPLEXITY_DISTRIBUTION = new Metric(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY,
140 "Functions distribution /complexity", "Functions distribution /complexity", Metric.ValueType.DISTRIB, Metric.DIRECTION_NONE, true,
141 DOMAIN_COMPLEXITY).setFormula(new SumChildDistributionFormula());
142
143 public static final String FILE_COMPLEXITY_DISTRIBUTION_KEY = "file_complexity_distribution";
144 public static final Metric FILE_COMPLEXITY_DISTRIBUTION = new Metric(FILE_COMPLEXITY_DISTRIBUTION_KEY, "Files distribution /complexity",
145 "Files distribution /complexity", Metric.ValueType.DISTRIB, Metric.DIRECTION_NONE, true, DOMAIN_COMPLEXITY)
146 .setFormula(new SumChildDistributionFormula());
147
148 public static final String PARAGRAPH_COMPLEXITY_DISTRIBUTION_KEY = "paragraph_complexity_distribution";
149 public static final Metric PARAGRAPH_COMPLEXITY_DISTRIBUTION = new Metric(PARAGRAPH_COMPLEXITY_DISTRIBUTION_KEY,
150 "Paragraph distribution /complexity", "Paragraph distribution /complexity", Metric.ValueType.DISTRIB, Metric.DIRECTION_NONE, true,
151 DOMAIN_COMPLEXITY).setFormula(new SumChildDistributionFormula());
152
153 public static final String COMMENT_LINES_KEY = "comment_lines";
154 public static final Metric COMMENT_LINES = new Metric(COMMENT_LINES_KEY, "Comment lines", "Number of comment lines",
155 Metric.ValueType.INT, Metric.DIRECTION_BETTER, false, DOMAIN_DOCUMENTATION).setFormula(new SumChildValuesFormula(false));
156
157 public static final String COMMENT_LINES_DENSITY_KEY = "comment_lines_density";
158 public static final Metric COMMENT_LINES_DENSITY = new Metric(COMMENT_LINES_DENSITY_KEY, "Comments (%)",
159 "Comments balanced by ncloc + comment lines", Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, true, DOMAIN_DOCUMENTATION);
160
161 public static final String COMMENT_BLANK_LINES_KEY = "comment_blank_lines";
162 public static final Metric COMMENT_BLANK_LINES = new Metric(COMMENT_BLANK_LINES_KEY, "Blank comments",
163 "Comments that do not contain comments", Metric.ValueType.INT, Metric.DIRECTION_WORST, false, CoreMetrics.DOMAIN_DOCUMENTATION)
164 .setFormula(new SumChildValuesFormula(false)).setBestValue(0.0).setOptimizedBestValue(true);
165
166 public static final String PUBLIC_DOCUMENTED_API_DENSITY_KEY = "public_documented_api_density";
167 public static final Metric PUBLIC_DOCUMENTED_API_DENSITY = new Metric(PUBLIC_DOCUMENTED_API_DENSITY_KEY, "Public documented API (%)",
168 "Public documented classes and methods balanced by ncloc", Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, true,
169 DOMAIN_DOCUMENTATION).setWorstValue(0.0).setBestValue(100.0).setOptimizedBestValue(true);
170
171 public static final String PUBLIC_UNDOCUMENTED_API_KEY = "public_undocumented_api";
172 public static final Metric PUBLIC_UNDOCUMENTED_API = new Metric(PUBLIC_UNDOCUMENTED_API_KEY, "Public undocumented API",
173 "Public undocumented classes, methods and variables", Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_DOCUMENTATION)
174 .setBestValue(0.0).setDirection(Metric.DIRECTION_WORST).setOptimizedBestValue(true).setFormula(
175 new SumChildValuesFormula(false));
176
177 public static final String COMMENTED_OUT_CODE_LINES_KEY = "commented_out_code_lines";
178 public static final Metric COMMENTED_OUT_CODE_LINES = new Metric(COMMENTED_OUT_CODE_LINES_KEY, "Commented LOCs",
179 "Commented lines of code", Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_DOCUMENTATION).setFormula(
180 new SumChildValuesFormula(false)).setBestValue(0.0).setOptimizedBestValue(true);
181
182 /* unit tests */
183 public static final String TESTS_KEY = "tests";
184 public static final Metric TESTS = new Metric(TESTS_KEY, "Unit tests", "Number of unit tests", Metric.ValueType.INT,
185 Metric.DIRECTION_WORST, false, DOMAIN_TESTS);
186
187 public static final String TEST_EXECUTION_TIME_KEY = "test_execution_time";
188 public static final Metric TEST_EXECUTION_TIME = new Metric(TEST_EXECUTION_TIME_KEY, "Unit tests duration",
189 "Execution duration of unit tests ", Metric.ValueType.MILLISEC, Metric.DIRECTION_WORST, false, DOMAIN_TESTS);
190
191 public static final String TEST_ERRORS_KEY = "test_errors";
192 public static final Metric TEST_ERRORS = new Metric(TEST_ERRORS_KEY, "Unit test errors", "Number of unit test errors",
193 Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_TESTS).setBestValue(0.0).setOptimizedBestValue(true);
194 public static final String SKIPPED_TESTS_KEY = "skipped_tests";
195 public static final Metric SKIPPED_TESTS = new Metric(SKIPPED_TESTS_KEY, "Skipped unit tests", "Number of skipped unit tests",
196 Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_TESTS).setBestValue(0.0).setOptimizedBestValue(true);
197 public static final String TEST_FAILURES_KEY = "test_failures";
198 public static final Metric TEST_FAILURES = new Metric(TEST_FAILURES_KEY, "Unit test failures", "Number of unit test failures",
199 Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_TESTS).setBestValue(0.0).setOptimizedBestValue(true);
200 public static final String TEST_SUCCESS_DENSITY_KEY = "test_success_density";
201 public static final Metric TEST_SUCCESS_DENSITY = new Metric(TEST_SUCCESS_DENSITY_KEY, "Unit test success (%)",
202 "Density of successful unit tests", Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, true, DOMAIN_TESTS).setWorstValue(0.0)
203 .setBestValue(100.0).setOptimizedBestValue(true);
204 public static final String TEST_DATA_KEY = "test_data";
205 public static final Metric TEST_DATA = new Metric(TEST_DATA_KEY, "Unit tests details", "Unit tests details", Metric.ValueType.DATA,
206 Metric.DIRECTION_WORST, false, DOMAIN_TESTS);
207
208 public static final String COVERAGE_KEY = "coverage";
209 public static final Metric COVERAGE = new Metric(COVERAGE_KEY, "Coverage", "Coverage by unit tests", Metric.ValueType.PERCENT,
210 Metric.DIRECTION_BETTER, true, DOMAIN_TESTS).setWorstValue(0.0).setBestValue(100.0);
211
212 public static final String LINES_TO_COVER_KEY = "lines_to_cover";
213 public static final Metric LINES_TO_COVER = new Metric(LINES_TO_COVER_KEY, "Lines to cover", "Lines to cover", Metric.ValueType.INT,
214 Metric.DIRECTION_BETTER, false, DOMAIN_TESTS).setFormula(new SumChildValuesFormula(false)).setHidden(true);
215
216 public static final String UNCOVERED_LINES_KEY = "uncovered_lines";
217 public static final Metric UNCOVERED_LINES = new Metric(UNCOVERED_LINES_KEY, "Uncovered lines", "Uncovered lines", Metric.ValueType.INT,
218 Metric.DIRECTION_WORST, false, DOMAIN_TESTS).setFormula(new SumChildValuesFormula(false));
219
220 public static final String LINE_COVERAGE_KEY = "line_coverage";
221 public static final Metric LINE_COVERAGE = new Metric(LINE_COVERAGE_KEY, "Line coverage", "Line coverage", Metric.ValueType.PERCENT,
222 Metric.DIRECTION_BETTER, true, DOMAIN_TESTS);
223
224 public static final String COVERAGE_LINE_HITS_DATA_KEY = "coverage_line_hits_data";
225 public static final Metric COVERAGE_LINE_HITS_DATA = new Metric(COVERAGE_LINE_HITS_DATA_KEY, "Coverage hits data",
226 "Code coverage line hits data", Metric.ValueType.DATA, Metric.DIRECTION_NONE, false, DOMAIN_TESTS);
227
228 public static final String CONDITIONS_TO_COVER_KEY = "conditions_to_cover";
229 public static final Metric CONDITIONS_TO_COVER = new Metric(CONDITIONS_TO_COVER_KEY, "Conditions to cover", "Conditions to cover",
230 Metric.ValueType.INT, Metric.DIRECTION_BETTER, false, DOMAIN_TESTS).setFormula(new SumChildValuesFormula(false)).setHidden(true);
231
232 public static final String UNCOVERED_CONDITIONS_KEY = "uncovered_conditions";
233 public static final Metric UNCOVERED_CONDITIONS = new Metric(UNCOVERED_CONDITIONS_KEY, "Uncovered conditions", "Uncovered conditions",
234 Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_TESTS).setFormula(new SumChildValuesFormula(false));
235
236 public static final String BRANCH_COVERAGE_KEY = "branch_coverage";
237 public static final Metric BRANCH_COVERAGE = new Metric(BRANCH_COVERAGE_KEY, "Branch coverage", "Branch coverage",
238 Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, true, DOMAIN_TESTS).setWorstValue(0.0).setBestValue(100.0);
239
240 public static final String BRANCH_COVERAGE_HITS_DATA_KEY = "branch_coverage_hits_data";
241 public static final Metric BRANCH_COVERAGE_HITS_DATA = new Metric(BRANCH_COVERAGE_HITS_DATA_KEY, "Branch coverage hits",
242 "Branch coverage hits", Metric.ValueType.DATA, Metric.DIRECTION_NONE, false, DOMAIN_TESTS);
243
244 /**
245 * @deprecated replaced since 1.11 by UNCOVERED_LINES and UNCOVERED_CONDITIONS
246 */
247 @Deprecated
248 public static final String UNCOVERED_COMPLEXITY_BY_TESTS_KEY = "uncovered_complexity_by_tests";
249 /**
250 * @deprecated replaced since 1.11 by UNCOVERED_LINES and UNCOVERED_CONDITIONS
251 */
252 @Deprecated
253 public static final Metric UNCOVERED_COMPLEXITY_BY_TESTS = new Metric(UNCOVERED_COMPLEXITY_BY_TESTS_KEY, "Uncovered complexity",
254 "Uncovered complexity", Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_COMPLEXITY).setFormula(new SumChildValuesFormula(
255 false));
256
257 public static final String DUPLICATED_LINES_KEY = "duplicated_lines";
258 public static final Metric DUPLICATED_LINES = new Metric(DUPLICATED_LINES_KEY, "Duplicated lines", "Duplicated lines",
259 Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_DUPLICATION).setBestValue(0.0).setOptimizedBestValue(true);
260
261 public static final String DUPLICATED_BLOCKS_KEY = "duplicated_blocks";
262 public static final Metric DUPLICATED_BLOCKS = new Metric(DUPLICATED_BLOCKS_KEY, "Duplicated blocks", "Duplicated blocks",
263 Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_DUPLICATION).setBestValue(0.0).setOptimizedBestValue(true);
264
265 public static final String DUPLICATED_FILES_KEY = "duplicated_files";
266 public static final Metric DUPLICATED_FILES = new Metric(DUPLICATED_FILES_KEY, "Duplicated files", "Duplicated files",
267 Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_DUPLICATION).setBestValue(0.0).setOptimizedBestValue(true);
268
269 public static final String DUPLICATED_LINES_DENSITY_KEY = "duplicated_lines_density";
270 public static final Metric DUPLICATED_LINES_DENSITY = new Metric(DUPLICATED_LINES_DENSITY_KEY, "Duplicated lines (%)",
271 "Duplicated lines balanced by statements", Metric.ValueType.PERCENT, Metric.DIRECTION_WORST, true, DOMAIN_DUPLICATION).setWorstValue(
272 50.0).setBestValue(0.0).setOptimizedBestValue(true);
273
274 public static final String DUPLICATIONS_DATA_KEY = "duplications_data";
275 public static final Metric DUPLICATIONS_DATA = new Metric(DUPLICATIONS_DATA_KEY, "Duplications details", "Duplications details",
276 Metric.ValueType.DATA, Metric.DIRECTION_NONE, false, DOMAIN_DUPLICATION);
277
278 /* coding rules */
279 /**
280 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
281 */
282 @Deprecated
283 public static final String USABILITY_KEY = "usability";
284
285 /**
286 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
287 */
288 @Deprecated
289 public static final Metric USABILITY = new Metric(USABILITY_KEY, "Usability", "Usability", Metric.ValueType.PERCENT,
290 Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true);
291
292 /**
293 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
294 */
295 @Deprecated
296 public static final String RELIABILITY_KEY = "reliability";
297
298 /**
299 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
300 */
301 @Deprecated
302 public static final Metric RELIABILITY = new Metric(RELIABILITY_KEY, "Reliability", "Reliability", Metric.ValueType.PERCENT,
303 Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true);
304
305 /**
306 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
307 */
308 @Deprecated
309 public static final String EFFICIENCY_KEY = "efficiency";
310
311 /**
312 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
313 */
314 @Deprecated
315 public static final Metric EFFICIENCY = new Metric(EFFICIENCY_KEY, "Efficiency", "Efficiency", Metric.ValueType.PERCENT,
316 Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true);
317
318 /**
319 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
320 */
321 @Deprecated
322 public static final String PORTABILITY_KEY = "portability";
323
324 /**
325 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
326 */
327 @Deprecated
328 public static final Metric PORTABILITY = new Metric(PORTABILITY_KEY, "Portability", "Portability", Metric.ValueType.PERCENT,
329 Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true);
330
331 /**
332 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
333 */
334 @Deprecated
335 public static final String MAINTAINABILITY_KEY = "maintainability";
336
337 /**
338 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
339 */
340 @Deprecated
341 public static final Metric MAINTAINABILITY = new Metric(MAINTAINABILITY_KEY, "Maintainability", "Maintainability",
342 Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true);
343
344 public static final String WEIGHTED_VIOLATIONS_KEY = "weighted_violations";
345 public static final Metric WEIGHTED_VIOLATIONS = new Metric(WEIGHTED_VIOLATIONS_KEY, "Weighted violations", "Weighted Violations",
346 Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true);
347
348 public static final String VIOLATIONS_DENSITY_KEY = "violations_density";
349 public static final Metric VIOLATIONS_DENSITY = new Metric(VIOLATIONS_DENSITY_KEY, "Rules compliance", "Rules compliance",
350 Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, true, DOMAIN_RULES);
351
352 public static final String VIOLATIONS_KEY = "violations";
353 public static final Metric VIOLATIONS = new Metric(VIOLATIONS_KEY, "Violations", "Violations", Metric.ValueType.INT,
354 Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true);
355
356 public static final String BLOCKER_VIOLATIONS_KEY = "blocker_violations";
357 public static final Metric BLOCKER_VIOLATIONS = new Metric(BLOCKER_VIOLATIONS_KEY, "Blocker violations", "Blocker violations",
358 Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true);
359
360 public static final String CRITICAL_VIOLATIONS_KEY = "critical_violations";
361 public static final Metric CRITICAL_VIOLATIONS = new Metric(CRITICAL_VIOLATIONS_KEY, "Critical violations", "Critical violations",
362 Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true);
363
364 public static final String MAJOR_VIOLATIONS_KEY = "major_violations";
365 public static final Metric MAJOR_VIOLATIONS = new Metric(MAJOR_VIOLATIONS_KEY, "Major violations", "Major violations",
366 Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true);
367
368 public static final String MINOR_VIOLATIONS_KEY = "minor_violations";
369 public static final Metric MINOR_VIOLATIONS = new Metric(MINOR_VIOLATIONS_KEY, "Minor violations", "Minor violations",
370 Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true);
371
372 public static final String INFO_VIOLATIONS_KEY = "info_violations";
373 public static final Metric INFO_VIOLATIONS = new Metric(INFO_VIOLATIONS_KEY, "Info violations", "Info violations", Metric.ValueType.INT,
374 Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true);
375
376 public static final String NEW_VIOLATIONS_KEY = "new_violations";
377 public static final Metric NEW_VIOLATIONS = new Metric(NEW_VIOLATIONS_KEY, "New Violations", "New Violations", Metric.ValueType.INT,
378 Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true).setBestValue(0.0).setOptimizedBestValue(true);
379
380 public static final String NEW_BLOCKER_VIOLATIONS_KEY = "new_blocker_violations";
381 public static final Metric NEW_BLOCKER_VIOLATIONS = new Metric(NEW_BLOCKER_VIOLATIONS_KEY, "New Blocker violations", "New Blocker violations",
382 Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true).setBestValue(0.0).setOptimizedBestValue(true);
383
384 public static final String NEW_CRITICAL_VIOLATIONS_KEY = "new_critical_violations";
385 public static final Metric NEW_CRITICAL_VIOLATIONS = new Metric(NEW_CRITICAL_VIOLATIONS_KEY, "New Critical violations", "New Critical violations",
386 Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true).setBestValue(0.0).setOptimizedBestValue(true);
387
388 public static final String NEW_MAJOR_VIOLATIONS_KEY = "new_major_violations";
389 public static final Metric NEW_MAJOR_VIOLATIONS = new Metric(NEW_MAJOR_VIOLATIONS_KEY, "New Major violations", "New Major violations",
390 Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true).setBestValue(0.0).setOptimizedBestValue(true);
391
392 public static final String NEW_MINOR_VIOLATIONS_KEY = "new_minor_violations";
393 public static final Metric NEW_MINOR_VIOLATIONS = new Metric(NEW_MINOR_VIOLATIONS_KEY, "New Minor violations", "New Minor violations",
394 Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true).setBestValue(0.0).setOptimizedBestValue(true);
395
396 public static final String NEW_INFO_VIOLATIONS_KEY = "new_info_violations";
397 public static final Metric NEW_INFO_VIOLATIONS = new Metric(NEW_INFO_VIOLATIONS_KEY, "New Info violations", "New Info violations",
398 Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true).setBestValue(0.0).setOptimizedBestValue(true);
399
400 /* Design */
401
402 public static final String ABSTRACTNESS_KEY = "abstractness";
403 public static final Metric ABSTRACTNESS = new Metric(ABSTRACTNESS_KEY, "Abstractness", "Abstractness", Metric.ValueType.PERCENT,
404 Metric.DIRECTION_NONE, false, DOMAIN_DESIGN);
405 public static final String INSTABILITY_KEY = "instability";
406 public static final Metric INSTABILITY = new Metric(INSTABILITY_KEY, "Instability", "Instability", Metric.ValueType.PERCENT,
407 Metric.DIRECTION_NONE, false, DOMAIN_DESIGN);
408 public static final String DISTANCE_KEY = "distance";
409 public static final Metric DISTANCE = new Metric(DISTANCE_KEY, "Distance", "Distance", Metric.ValueType.FLOAT, Metric.DIRECTION_NONE,
410 false, DOMAIN_DESIGN);
411
412 public static final String DEPTH_IN_TREE_KEY = "dit";
413 public static final Metric DEPTH_IN_TREE = new Metric(DEPTH_IN_TREE_KEY, "Depth in Tree", "Depth in Inheritance Tree",
414 Metric.ValueType.INT, Metric.DIRECTION_NONE, false, DOMAIN_DESIGN);
415
416 public static final String NUMBER_OF_CHILDREN_KEY = "noc";
417 public static final Metric NUMBER_OF_CHILDREN = new Metric(NUMBER_OF_CHILDREN_KEY, "Number of Children", "Number of Children",
418 Metric.ValueType.INT, Metric.DIRECTION_NONE, false, DOMAIN_DESIGN);
419
420 public static final String RFC_KEY = "rfc";
421 public static final Metric RFC = new Metric(RFC_KEY, "RFC", "Response for Class", Metric.ValueType.INT, Metric.DIRECTION_WORST, false,
422 DOMAIN_DESIGN).setFormula(new WeightedMeanAggregationFormula(CoreMetrics.FILES, false));
423
424 public static final String RFC_DISTRIBUTION_KEY = "rfc_distribution";
425 public static final Metric RFC_DISTRIBUTION = new Metric(RFC_DISTRIBUTION_KEY, "Class distribution /RFC", "Class distribution /RFC",
426 Metric.ValueType.DISTRIB, Metric.DIRECTION_NONE, true, DOMAIN_DESIGN).setFormula(new SumChildDistributionFormula());
427
428 public static final String LCOM4_KEY = "lcom4";
429 public static final Metric LCOM4 = new Metric(LCOM4_KEY, "LCOM4", "Lack of Cohesion of Methods", Metric.ValueType.FLOAT,
430 Metric.DIRECTION_WORST, true, DOMAIN_DESIGN).setFormula(new WeightedMeanAggregationFormula(CoreMetrics.FILES, false));
431
432 public static final String LCOM4_BLOCKS_KEY = "lcom4_blocks";
433 public static final Metric LCOM4_BLOCKS = new Metric(LCOM4_BLOCKS_KEY, "LCOM4 blocks", "LCOM4 blocks", Metric.ValueType.DATA,
434 Metric.DIRECTION_NONE, false, DOMAIN_DESIGN).setHidden(true);
435
436 public static final String LCOM4_DISTRIBUTION_KEY = "lcom4_distribution";
437 public static final Metric LCOM4_DISTRIBUTION = new Metric(LCOM4_DISTRIBUTION_KEY, "Class distribution /LCOM4",
438 "Class distribution /LCOM4", Metric.ValueType.DISTRIB, Metric.DIRECTION_NONE, true, DOMAIN_DESIGN)
439 .setFormula(new SumChildDistributionFormula());
440
441 public static final String SUSPECT_LCOM4_DENSITY_KEY = "suspect_lcom4_density";
442 public static final Metric SUSPECT_LCOM4_DENSITY = new Metric(SUSPECT_LCOM4_DENSITY_KEY, "Suspect LCOM4 density",
443 "Density of classes having LCOM4>1", Metric.ValueType.PERCENT, Metric.DIRECTION_WORST, true, DOMAIN_DESIGN);
444
445 public static final String AFFERENT_COUPLINGS_KEY = "ca";
446 public static final Metric AFFERENT_COUPLINGS = new Metric(AFFERENT_COUPLINGS_KEY, "Afferent couplings", "Afferent couplings",
447 Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_DESIGN);
448 public static final String EFFERENT_COUPLINGS_KEY = "ce";
449 public static final Metric EFFERENT_COUPLINGS = new Metric(EFFERENT_COUPLINGS_KEY, "Efferent couplings", "Efferent couplings",
450 Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_DESIGN);
451
452 public static final String DEPENDENCY_MATRIX_KEY = "dsm";
453 public static final Metric DEPENDENCY_MATRIX = new Metric(DEPENDENCY_MATRIX_KEY, "Dependency Matrix", "Dependency Matrix",
454 Metric.ValueType.DATA, Metric.DIRECTION_NONE, false, DOMAIN_DESIGN);
455
456 public static final String PACKAGE_CYCLES_KEY = "package_cycles";
457 public static final Metric PACKAGE_CYCLES = new Metric(PACKAGE_CYCLES_KEY, "Package cycles", "Package cycles", Metric.ValueType.INT,
458 Metric.DIRECTION_WORST, true, DOMAIN_DESIGN).setFormula(new SumChildValuesFormula(false));
459
460 public static final String PACKAGE_TANGLE_INDEX_KEY = "package_tangle_index";
461 public static final Metric PACKAGE_TANGLE_INDEX = new Metric(PACKAGE_TANGLE_INDEX_KEY, "Package tangle index", "Package tangle index",
462 Metric.ValueType.PERCENT, Metric.DIRECTION_WORST, true, DOMAIN_DESIGN);
463
464 public static final String PACKAGE_TANGLES_KEY = "package_tangles";
465 public static final Metric PACKAGE_TANGLES = new Metric(PACKAGE_TANGLES_KEY, "File dependencies to cut", "File dependencies to cut",
466 Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_DESIGN).setFormula(new SumChildValuesFormula(false));
467
468 public static final String PACKAGE_FEEDBACK_EDGES_KEY = "package_feedback_edges";
469 public static final Metric PACKAGE_FEEDBACK_EDGES = new Metric(PACKAGE_FEEDBACK_EDGES_KEY, "Package dependencies to cut",
470 "Package dependencies to cut", Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_DESIGN)
471 .setFormula(new SumChildValuesFormula(false));
472
473 public static final String PACKAGE_EDGES_WEIGHT_KEY = "package_edges_weight";
474 public static final Metric PACKAGE_EDGES_WEIGHT = new Metric(PACKAGE_EDGES_WEIGHT_KEY, "Package edges weight", "Package edges weight",
475 Metric.ValueType.INT, Metric.DIRECTION_BETTER, false, DOMAIN_DESIGN).setFormula(new SumChildValuesFormula(false)).setHidden(true);
476
477 public static final String FILE_CYCLES_KEY = "file_cycles";
478 public static final Metric FILE_CYCLES = new Metric(FILE_CYCLES_KEY, "File cycles", "File cycles", Metric.ValueType.INT,
479 Metric.DIRECTION_WORST, true, DOMAIN_DESIGN).setHidden(true);
480
481 public static final String FILE_TANGLE_INDEX_KEY = "file_tangle_index";
482 public static final Metric FILE_TANGLE_INDEX = new Metric(FILE_TANGLE_INDEX_KEY, "File tangle index", "File tangle index",
483 Metric.ValueType.PERCENT, Metric.DIRECTION_WORST, true, DOMAIN_DESIGN).setHidden(true);
484
485 public static final String FILE_TANGLES_KEY = "file_tangles";
486 public static final Metric FILE_TANGLES = new Metric(FILE_TANGLES_KEY, "File tangles", "Files tangles", Metric.ValueType.INT,
487 Metric.DIRECTION_WORST, false, DOMAIN_DESIGN).setHidden(true);
488
489 public static final String FILE_FEEDBACK_EDGES_KEY = "file_feedback_edges";
490 public static final Metric FILE_FEEDBACK_EDGES = new Metric(FILE_FEEDBACK_EDGES_KEY, "Suspect file dependencies",
491 "Suspect file dependencies", Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_DESIGN).setHidden(true);
492
493 public static final String FILE_EDGES_WEIGHT_KEY = "file_edges_weight";
494 public static final Metric FILE_EDGES_WEIGHT = new Metric(FILE_EDGES_WEIGHT_KEY, "File edges weight", "File edges weight",
495 Metric.ValueType.INT, Metric.DIRECTION_BETTER, false, DOMAIN_DESIGN).setHidden(true);
496
497 /* alerts */
498 public static final String ALERT_STATUS_KEY = "alert_status";
499 public static final Metric ALERT_STATUS = new Metric(ALERT_STATUS_KEY, "Alert", "Alert", Metric.ValueType.LEVEL, Metric.DIRECTION_BETTER,
500 true, DOMAIN_GENERAL);
501
502 /* quality profile */
503 public static final String PROFILE_KEY = "profile";
504 public static final Metric PROFILE = new Metric(PROFILE_KEY, "Profile", "Selected quality profile", Metric.ValueType.DATA,
505 Metric.DIRECTION_NONE, false, DOMAIN_GENERAL);
506
507 public static List<Metric> metrics = new ArrayList<Metric>();
508
509 public static Set<String> metricKeys = new HashSet<String>();
510
511 public static List<Metric> getMetrics() {
512 if (metrics.isEmpty()) {
513 for (Field field : CoreMetrics.class.getFields()) {
514 if (Metric.class.isAssignableFrom(field.getType())) {
515 try {
516 Metric metric = (Metric) field.get(null);
517 if (!StringUtils.equals(metric.getDomain(), DOMAIN_RULE_CATEGORIES)) {
518 metrics.add(metric);
519 }
520 } catch (IllegalAccessException e) {
521 throw new SonarException("can not load metrics from " + CoreMetrics.class.getSimpleName(), e);
522 }
523 }
524 }
525 }
526 return metrics;
527 }
528 }