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