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