001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2008-2011 SonarSource
004     * mailto:contact AT sonarsource DOT com
005     *
006     * Sonar is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 3 of the License, or (at your option) any later version.
010     *
011     * Sonar is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public
017     * License along with Sonar; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
019     */
020    package org.sonar.api.measures;
021    
022    import com.google.common.collect.Lists;
023    import org.apache.commons.lang.StringUtils;
024    import org.sonar.api.resources.Scopes;
025    import org.sonar.api.utils.SonarException;
026    
027    import java.lang.reflect.Field;
028    import java.util.List;
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_SCM = "SCM";
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    
111      //--------------------------------------------------------------------------------------------------------------------
112      //
113      // DOCUMENTATION
114      //
115      //--------------------------------------------------------------------------------------------------------------------
116    
117      public static final String COMMENT_LINES_KEY = "comment_lines";
118      public static final Metric COMMENT_LINES = new Metric(COMMENT_LINES_KEY, "Comment lines", "Number of comment lines",
119          Metric.ValueType.INT, Metric.DIRECTION_BETTER, false, DOMAIN_DOCUMENTATION).setFormula(new SumChildValuesFormula(false));
120    
121      public static final String COMMENT_LINES_DENSITY_KEY = "comment_lines_density";
122      public static final Metric COMMENT_LINES_DENSITY = new Metric(COMMENT_LINES_DENSITY_KEY, "Comments (%)",
123          "Comments balanced by ncloc + comment lines", Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, true, DOMAIN_DOCUMENTATION);
124    
125      public static final String COMMENT_BLANK_LINES_KEY = "comment_blank_lines";
126      public static final Metric COMMENT_BLANK_LINES = new Metric(COMMENT_BLANK_LINES_KEY, "Blank comments",
127          "Comments that do not contain comments", Metric.ValueType.INT, Metric.DIRECTION_WORST, false, CoreMetrics.DOMAIN_DOCUMENTATION)
128          .setFormula(new SumChildValuesFormula(false)).setBestValue(0.0).setOptimizedBestValue(true);
129    
130      public static final String PUBLIC_DOCUMENTED_API_DENSITY_KEY = "public_documented_api_density";
131      public static final Metric PUBLIC_DOCUMENTED_API_DENSITY = new Metric(PUBLIC_DOCUMENTED_API_DENSITY_KEY, "Public documented API (%)",
132          "Public documented classes and methods balanced by ncloc", Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, true,
133          DOMAIN_DOCUMENTATION).setWorstValue(0.0).setBestValue(100.0).setOptimizedBestValue(true);
134    
135      public static final String PUBLIC_UNDOCUMENTED_API_KEY = "public_undocumented_api";
136      public static final Metric PUBLIC_UNDOCUMENTED_API = new Metric(PUBLIC_UNDOCUMENTED_API_KEY, "Public undocumented API",
137          "Public undocumented classes, methods and variables", Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_DOCUMENTATION)
138          .setBestValue(0.0).setDirection(Metric.DIRECTION_WORST).setOptimizedBestValue(true).setFormula(
139              new SumChildValuesFormula(false));
140    
141      public static final String COMMENTED_OUT_CODE_LINES_KEY = "commented_out_code_lines";
142      public static final Metric COMMENTED_OUT_CODE_LINES = new Metric(COMMENTED_OUT_CODE_LINES_KEY, "Commented LOCs",
143          "Commented lines of code", Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_DOCUMENTATION).setFormula(
144          new SumChildValuesFormula(false)).setBestValue(0.0).setOptimizedBestValue(true);
145    
146    
147      //--------------------------------------------------------------------------------------------------------------------
148      //
149      // COMPLEXITY
150      //
151      //--------------------------------------------------------------------------------------------------------------------
152    
153      public static final String COMPLEXITY_KEY = "complexity";
154      public static final Metric COMPLEXITY = new Metric(COMPLEXITY_KEY, "Complexity", "Cyclomatic complexity", Metric.ValueType.INT,
155          Metric.DIRECTION_WORST, false, DOMAIN_COMPLEXITY).setFormula(new SumChildValuesFormula(false));
156    
157      public static final String CLASS_COMPLEXITY_KEY = "class_complexity";
158      public static final Metric CLASS_COMPLEXITY = new Metric(CLASS_COMPLEXITY_KEY, "Complexity /class", "Complexity average by class",
159          Metric.ValueType.FLOAT, Metric.DIRECTION_WORST, true, DOMAIN_COMPLEXITY)
160          .setFormula(new AverageComplexityFormula(CoreMetrics.CLASSES));
161    
162      public static final String FUNCTION_COMPLEXITY_KEY = "function_complexity";
163      public static final Metric FUNCTION_COMPLEXITY = new Metric(FUNCTION_COMPLEXITY_KEY, "Complexity /method",
164          "Complexity average by method", Metric.ValueType.FLOAT, Metric.DIRECTION_WORST, true, DOMAIN_COMPLEXITY)
165          .setFormula(new AverageComplexityFormula(CoreMetrics.FUNCTIONS));
166    
167      public static final String FILE_COMPLEXITY_KEY = "file_complexity";
168      public static final Metric FILE_COMPLEXITY = new Metric(FILE_COMPLEXITY_KEY, "Complexity /file", "Complexity average by file",
169          Metric.ValueType.FLOAT, Metric.DIRECTION_WORST, true, DOMAIN_COMPLEXITY).setFormula(new AverageComplexityFormula(CoreMetrics.FILES));
170    
171      public static final String PARAGRAPH_COMPLEXITY_KEY = "paragraph_complexity";
172      public static final Metric PARAGRAPH_COMPLEXITY = new Metric(PARAGRAPH_COMPLEXITY_KEY, "Complexity /paragraph",
173          "Complexity average by paragraph", Metric.ValueType.FLOAT, Metric.DIRECTION_WORST, true, DOMAIN_COMPLEXITY)
174          .setFormula(new AverageComplexityFormula(CoreMetrics.PARAGRAPHS));
175    
176      public static final String CLASS_COMPLEXITY_DISTRIBUTION_KEY = "class_complexity_distribution";
177      public static final Metric CLASS_COMPLEXITY_DISTRIBUTION = new Metric(CLASS_COMPLEXITY_DISTRIBUTION_KEY,
178          "Classes distribution /complexity", "Classes distribution /complexity", Metric.ValueType.DISTRIB, Metric.DIRECTION_NONE, true,
179          DOMAIN_COMPLEXITY).setFormula(new SumChildDistributionFormula().setMinimumScopeToPersist(Scopes.DIRECTORY));
180    
181      public static final String FUNCTION_COMPLEXITY_DISTRIBUTION_KEY = "function_complexity_distribution";
182      public static final Metric FUNCTION_COMPLEXITY_DISTRIBUTION = new Metric(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY,
183          "Functions distribution /complexity", "Functions distribution /complexity", Metric.ValueType.DISTRIB, Metric.DIRECTION_NONE, true,
184          DOMAIN_COMPLEXITY).setFormula(new SumChildDistributionFormula().setMinimumScopeToPersist(Scopes.DIRECTORY));
185    
186      public static final String FILE_COMPLEXITY_DISTRIBUTION_KEY = "file_complexity_distribution";
187      public static final Metric FILE_COMPLEXITY_DISTRIBUTION = new Metric(FILE_COMPLEXITY_DISTRIBUTION_KEY, "Files distribution /complexity",
188          "Files distribution /complexity", Metric.ValueType.DISTRIB, Metric.DIRECTION_NONE, true, DOMAIN_COMPLEXITY)
189          .setFormula(new SumChildDistributionFormula().setMinimumScopeToPersist(Scopes.DIRECTORY));
190    
191      public static final String PARAGRAPH_COMPLEXITY_DISTRIBUTION_KEY = "paragraph_complexity_distribution";
192      public static final Metric PARAGRAPH_COMPLEXITY_DISTRIBUTION = new Metric(PARAGRAPH_COMPLEXITY_DISTRIBUTION_KEY,
193          "Paragraph distribution /complexity", "Paragraph distribution /complexity", Metric.ValueType.DISTRIB, Metric.DIRECTION_NONE, true,
194          DOMAIN_COMPLEXITY).setFormula(new SumChildDistributionFormula().setMinimumScopeToPersist(Scopes.DIRECTORY));
195    
196    
197      //--------------------------------------------------------------------------------------------------------------------
198      //
199      // UNIT TESTS
200      //
201      //--------------------------------------------------------------------------------------------------------------------
202    
203      public static final String TESTS_KEY = "tests";
204    
205      /**
206       * Value of measure for this metric can be saved from Sensor, taking into account following rules:
207       * <ul>
208       * <li>If tool (like Maven Surefire Plugin) has not been activated to run unit tests, then Sensor should not save anything. For example there is no such tool for COBOL.</li>
209       * <li>If tool has been activated, but there was no unit tests to run, then zero value should be saved for project.</li>
210       * <li>Non-zero value should be saved for resources representing tests. And Sonar provides default Decorator, which will decorate parent resources.</li>
211       * <li>Should include {@link #TEST_FAILURES} and {@link #TEST_ERRORS}, but should not include {@link #SKIPPED_TESTS}.</li>
212       * </ul>
213       */
214      public static final Metric TESTS = new Metric(TESTS_KEY, "Unit tests", "Number of unit tests", Metric.ValueType.INT,
215          Metric.DIRECTION_WORST, false, DOMAIN_TESTS);
216    
217      public static final String TEST_EXECUTION_TIME_KEY = "test_execution_time";
218      public static final Metric TEST_EXECUTION_TIME = new Metric(TEST_EXECUTION_TIME_KEY, "Unit tests duration",
219          "Execution duration of unit tests ", Metric.ValueType.MILLISEC, Metric.DIRECTION_WORST, false, DOMAIN_TESTS);
220    
221      public static final String TEST_ERRORS_KEY = "test_errors";
222      public static final Metric TEST_ERRORS = new Metric(TEST_ERRORS_KEY, "Unit test errors", "Number of unit test errors",
223          Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_TESTS).setBestValue(0.0).setOptimizedBestValue(true);
224      public static final String SKIPPED_TESTS_KEY = "skipped_tests";
225      public static final Metric SKIPPED_TESTS = new Metric(SKIPPED_TESTS_KEY, "Skipped unit tests", "Number of skipped unit tests",
226          Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_TESTS).setBestValue(0.0).setOptimizedBestValue(true);
227      public static final String TEST_FAILURES_KEY = "test_failures";
228      public static final Metric TEST_FAILURES = new Metric(TEST_FAILURES_KEY, "Unit test failures", "Number of unit test failures",
229          Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_TESTS).setBestValue(0.0).setOptimizedBestValue(true);
230    
231      public static final String TEST_SUCCESS_DENSITY_KEY = "test_success_density";
232      public static final Metric TEST_SUCCESS_DENSITY = new Metric.Builder(TEST_SUCCESS_DENSITY_KEY, "Unit test success (%)", Metric.ValueType.PERCENT)
233          .setDescription("Density of successful unit tests")
234          .setDirection(Metric.DIRECTION_BETTER)
235          .setQualitative(true)
236          .setDomain(DOMAIN_TESTS)
237          .setWorstValue(0.0)
238          .setBestValue(100.0)
239          .setOptimizedBestValue(true)
240          .create();
241    
242      public static final String TEST_DATA_KEY = "test_data";
243      public static final Metric TEST_DATA = new Metric.Builder(TEST_DATA_KEY, "Unit tests details", Metric.ValueType.DATA)
244          .setDescription("Unit tests details")
245          .setDirection(Metric.DIRECTION_WORST)
246          .setDomain(DOMAIN_TESTS)
247          .create();
248    
249      public static final String COVERAGE_KEY = "coverage";
250      public static final Metric COVERAGE = new Metric.Builder(COVERAGE_KEY, "Coverage", Metric.ValueType.PERCENT)
251          .setDescription("Coverage by unit tests")
252          .setDirection(Metric.DIRECTION_BETTER)
253          .setQualitative(true)
254          .setDomain(DOMAIN_TESTS)
255          .setWorstValue(0.0)
256          .setBestValue(100.0)
257          .create();
258    
259      public static final String NEW_COVERAGE_KEY = "new_coverage";
260      public static final Metric NEW_COVERAGE = new Metric.Builder(NEW_COVERAGE_KEY, "New coverage", Metric.ValueType.PERCENT)
261          .setDescription("Coverage of new/changed code")
262          .setDirection(Metric.DIRECTION_BETTER)
263          .setQualitative(true)
264          .setDomain(DOMAIN_TESTS)
265          .setWorstValue(0.0)
266          .setBestValue(100.0)
267          .create();
268    
269      public static final String LINES_TO_COVER_KEY = "lines_to_cover";
270    
271      /**
272       * Use {@link CoverageMeasuresBuilder} to build measure for this metric.
273       */
274      public static final Metric LINES_TO_COVER = new Metric.Builder(LINES_TO_COVER_KEY, "Lines to cover", Metric.ValueType.INT)
275          .setDescription("Lines to cover")
276          .setDirection(Metric.DIRECTION_BETTER)
277          .setQualitative(false)
278          .setDomain(DOMAIN_TESTS)
279          .setFormula(new SumChildValuesFormula(false))
280          .setHidden(true)
281          .create();
282    
283      public static final String NEW_LINES_TO_COVER_KEY = "new_lines_to_cover";
284      public static final Metric NEW_LINES_TO_COVER = new Metric.Builder(NEW_LINES_TO_COVER_KEY, "New lines to cover", Metric.ValueType.INT)
285          .setDescription("New lines to cover")
286          .setDirection(Metric.DIRECTION_WORST)
287          .setQualitative(false)
288          .setDomain(DOMAIN_TESTS)
289          .setFormula(new SumChildValuesFormula(false))
290          .create();
291    
292      public static final String UNCOVERED_LINES_KEY = "uncovered_lines";
293    
294      /**
295       * Use {@link CoverageMeasuresBuilder} to build measure for this metric.
296       */
297      public static final Metric UNCOVERED_LINES = new Metric.Builder(UNCOVERED_LINES_KEY, "Uncovered lines", Metric.ValueType.INT)
298          .setDescription("Uncovered lines")
299          .setDirection(Metric.DIRECTION_WORST)
300          .setDomain(DOMAIN_TESTS)
301          .setFormula(new SumChildValuesFormula(false))
302          .create();
303    
304      public static final String NEW_UNCOVERED_LINES_KEY = "new_uncovered_lines";
305      public static final Metric NEW_UNCOVERED_LINES = new Metric.Builder(NEW_UNCOVERED_LINES_KEY, "New uncovered lines", Metric.ValueType.INT)
306          .setDescription("New uncovered lines")
307          .setDirection(Metric.DIRECTION_WORST)
308          .setDomain(DOMAIN_TESTS)
309          .setFormula(new SumChildValuesFormula(false))
310          .create();
311    
312      public static final String LINE_COVERAGE_KEY = "line_coverage";
313      public static final Metric LINE_COVERAGE = new Metric.Builder(LINE_COVERAGE_KEY, "Line coverage", Metric.ValueType.PERCENT)
314          .setDescription("Line coverage")
315          .setDirection(Metric.DIRECTION_BETTER)
316          .setQualitative(true)
317          .setDomain(DOMAIN_TESTS)
318          .create();
319    
320      public static final String NEW_LINE_COVERAGE_KEY = "new_line_coverage";
321      public static final Metric NEW_LINE_COVERAGE = new Metric.Builder(NEW_LINE_COVERAGE_KEY, "New line coverage", Metric.ValueType.PERCENT)
322          .setDescription("Line coverage of added/changed code")
323          .setDirection(Metric.DIRECTION_BETTER)
324          .setQualitative(true)
325          .setWorstValue(0.0)
326          .setBestValue(100.0)
327          .setDomain(DOMAIN_TESTS)
328          .create();
329    
330      public static final String COVERAGE_LINE_HITS_DATA_KEY = "coverage_line_hits_data";
331    
332      /**
333       * Use {@link CoverageMeasuresBuilder} to build measure for this metric.
334       */
335      public static final Metric COVERAGE_LINE_HITS_DATA = new Metric.Builder(COVERAGE_LINE_HITS_DATA_KEY, "Coverage hits by line", Metric.ValueType.DATA)
336          .setDomain(DOMAIN_TESTS)
337          .create();
338    
339      public static final String CONDITIONS_TO_COVER_KEY = "conditions_to_cover";
340    
341      /**
342       * Use {@link CoverageMeasuresBuilder} to build measure for this metric.
343       */
344      public static final Metric CONDITIONS_TO_COVER = new Metric.Builder(CONDITIONS_TO_COVER_KEY, "Conditions to cover", Metric.ValueType.INT)
345          .setDescription("Conditions to cover")
346          .setDomain(DOMAIN_TESTS)
347          .setFormula(new SumChildValuesFormula(false))
348          .setHidden(true)
349          .create();
350    
351      public static final String NEW_CONDITIONS_TO_COVER_KEY = "new_conditions_to_cover";
352      public static final Metric NEW_CONDITIONS_TO_COVER = new Metric.Builder(NEW_CONDITIONS_TO_COVER_KEY, "New conditions to cover", Metric.ValueType.INT)
353          .setDescription("New conditions to cover")
354          .setDomain(DOMAIN_TESTS)
355          .setFormula(new SumChildValuesFormula(false))
356          .create();
357    
358      public static final String UNCOVERED_CONDITIONS_KEY = "uncovered_conditions";
359    
360      /**
361       * Use {@link CoverageMeasuresBuilder} to build measure for this metric.
362       */
363      public static final Metric UNCOVERED_CONDITIONS = new Metric.Builder(UNCOVERED_CONDITIONS_KEY, "Uncovered conditions", Metric.ValueType.INT)
364          .setDescription("Uncovered conditions")
365          .setDirection(Metric.DIRECTION_WORST)
366          .setDomain(DOMAIN_TESTS)
367          .setFormula(new SumChildValuesFormula(false))
368          .create();
369    
370      public static final String NEW_UNCOVERED_CONDITIONS_KEY = "new_uncovered_conditions";
371      public static final Metric NEW_UNCOVERED_CONDITIONS = new Metric.Builder(NEW_UNCOVERED_CONDITIONS_KEY, "New uncovered conditions", Metric.ValueType.INT)
372          .setDescription("New uncovered conditions")
373          .setDirection(Metric.DIRECTION_WORST)
374          .setDomain(DOMAIN_TESTS)
375          .setFormula(new SumChildValuesFormula(false))
376          .create();
377    
378      public static final String BRANCH_COVERAGE_KEY = "branch_coverage";
379      public static final Metric BRANCH_COVERAGE = new Metric.Builder(BRANCH_COVERAGE_KEY, "Branch coverage", Metric.ValueType.PERCENT)
380          .setDescription("Branch coverage")
381          .setDirection(Metric.DIRECTION_BETTER)
382          .setQualitative(true)
383          .setDomain(DOMAIN_TESTS)
384          .setWorstValue(0.0)
385          .setBestValue(100.0)
386          .create();
387    
388      public static final String NEW_BRANCH_COVERAGE_KEY = "new_branch_coverage";
389      public static final Metric NEW_BRANCH_COVERAGE = new Metric.Builder(NEW_BRANCH_COVERAGE_KEY, "New branch coverage", Metric.ValueType.PERCENT)
390          .setDescription("Branch coverage of new/changed code")
391          .setDirection(Metric.DIRECTION_BETTER)
392          .setQualitative(true)
393          .setDomain(DOMAIN_TESTS)
394          .setWorstValue(0.0)
395          .setBestValue(100.0)
396          .create();
397    
398      /**
399       * @deprecated in 2.7. Replaced by {@link #CONDITIONS_BY_LINE_KEY} and {@link #COVERED_CONDITIONS_BY_LINE_KEY}
400       */
401      @Deprecated
402      public static final String BRANCH_COVERAGE_HITS_DATA_KEY = "branch_coverage_hits_data";
403    
404      /**
405       * @deprecated in 2.7. Replaced by metrics {@link #CONDITIONS_BY_LINE} and {@link #COVERED_CONDITIONS_BY_LINE}
406       */
407      @Deprecated
408      public static final Metric BRANCH_COVERAGE_HITS_DATA = new Metric.Builder(BRANCH_COVERAGE_HITS_DATA_KEY, "Branch coverage hits", Metric.ValueType.DATA)
409          .setDomain(DOMAIN_TESTS)
410          .create();
411    
412      public static final String CONDITIONS_BY_LINE_KEY = "conditions_by_line";
413    
414      /**
415       * Use {@link CoverageMeasuresBuilder} to build measure for this metric.
416       *
417       * @since 2.7
418       */
419      public static final Metric CONDITIONS_BY_LINE = new Metric.Builder(CONDITIONS_BY_LINE_KEY, "Conditions by line", Metric.ValueType.DATA)
420          .setDomain(DOMAIN_TESTS)
421          .create();
422    
423      public static final String COVERED_CONDITIONS_BY_LINE_KEY = "covered_conditions_by_line";
424    
425      /**
426       * Use {@link CoverageMeasuresBuilder} to build measure for this metric.
427       *
428       * @since 2.7
429       */
430      public static final Metric COVERED_CONDITIONS_BY_LINE = new Metric.Builder(COVERED_CONDITIONS_BY_LINE_KEY, "Covered conditions by line", Metric.ValueType.DATA)
431          .setDomain(DOMAIN_TESTS)
432          .create();
433    
434    
435      //--------------------------------------------------------------------------------------------------------------------
436      //
437      // DUPLICATIONS
438      //
439      //--------------------------------------------------------------------------------------------------------------------
440    
441      public static final String DUPLICATED_LINES_KEY = "duplicated_lines";
442      public static final Metric DUPLICATED_LINES = new Metric.Builder(DUPLICATED_LINES_KEY, "Duplicated lines", Metric.ValueType.INT)
443          .setDescription("Duplicated lines")
444          .setDirection(Metric.DIRECTION_WORST)
445          .setDomain(DOMAIN_DUPLICATION)
446          .setBestValue(0.0)
447          .setOptimizedBestValue(true)
448          .create();
449    
450      public static final String DUPLICATED_BLOCKS_KEY = "duplicated_blocks";
451      public static final Metric DUPLICATED_BLOCKS = new Metric.Builder(DUPLICATED_BLOCKS_KEY, "Duplicated blocks", Metric.ValueType.INT)
452          .setDescription("Duplicated blocks")
453          .setDirection(Metric.DIRECTION_WORST)
454          .setDomain(DOMAIN_DUPLICATION)
455          .setBestValue(0.0)
456          .setOptimizedBestValue(true)
457          .create();
458    
459      public static final String DUPLICATED_FILES_KEY = "duplicated_files";
460      public static final Metric DUPLICATED_FILES = new Metric(DUPLICATED_FILES_KEY, "Duplicated files", "Duplicated files",
461          Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_DUPLICATION).setBestValue(0.0).setOptimizedBestValue(true);
462    
463      public static final String DUPLICATED_LINES_DENSITY_KEY = "duplicated_lines_density";
464      public static final Metric DUPLICATED_LINES_DENSITY = new Metric(DUPLICATED_LINES_DENSITY_KEY, "Duplicated lines (%)",
465          "Duplicated lines balanced by statements", Metric.ValueType.PERCENT, Metric.DIRECTION_WORST, true, DOMAIN_DUPLICATION).setWorstValue(
466          50.0).setBestValue(0.0).setOptimizedBestValue(true);
467    
468      public static final String DUPLICATIONS_DATA_KEY = "duplications_data";
469      public static final Metric DUPLICATIONS_DATA = new Metric(DUPLICATIONS_DATA_KEY, "Duplications details", "Duplications details",
470          Metric.ValueType.DATA, Metric.DIRECTION_NONE, false, DOMAIN_DUPLICATION);
471    
472    
473      //--------------------------------------------------------------------------------------------------------------------
474      //
475      // CODING RULES
476      //
477      //--------------------------------------------------------------------------------------------------------------------
478      /**
479       * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
480       */
481      @Deprecated
482      public static final String USABILITY_KEY = "usability";
483    
484      /**
485       * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
486       */
487      @Deprecated
488      public static final Metric USABILITY = new Metric(USABILITY_KEY, "Usability", "Usability", Metric.ValueType.PERCENT,
489          Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true);
490    
491      /**
492       * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
493       */
494      @Deprecated
495      public static final String RELIABILITY_KEY = "reliability";
496    
497      /**
498       * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
499       */
500      @Deprecated
501      public static final Metric RELIABILITY = new Metric(RELIABILITY_KEY, "Reliability", "Reliability", Metric.ValueType.PERCENT,
502          Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true);
503    
504      /**
505       * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
506       */
507      @Deprecated
508      public static final String EFFICIENCY_KEY = "efficiency";
509    
510      /**
511       * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
512       */
513      @Deprecated
514      public static final Metric EFFICIENCY = new Metric(EFFICIENCY_KEY, "Efficiency", "Efficiency", Metric.ValueType.PERCENT,
515          Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true);
516    
517      /**
518       * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
519       */
520      @Deprecated
521      public static final String PORTABILITY_KEY = "portability";
522    
523      /**
524       * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
525       */
526      @Deprecated
527      public static final Metric PORTABILITY = new Metric(PORTABILITY_KEY, "Portability", "Portability", Metric.ValueType.PERCENT,
528          Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true);
529    
530      /**
531       * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
532       */
533      @Deprecated
534      public static final String MAINTAINABILITY_KEY = "maintainability";
535    
536      /**
537       * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007
538       */
539      @Deprecated
540      public static final Metric MAINTAINABILITY = new Metric(MAINTAINABILITY_KEY, "Maintainability", "Maintainability",
541          Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true);
542    
543      public static final String WEIGHTED_VIOLATIONS_KEY = "weighted_violations";
544      public static final Metric WEIGHTED_VIOLATIONS = new Metric(WEIGHTED_VIOLATIONS_KEY, "Weighted violations", "Weighted Violations",
545          Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true);
546    
547      public static final String VIOLATIONS_DENSITY_KEY = "violations_density";
548      public static final Metric VIOLATIONS_DENSITY = new Metric(VIOLATIONS_DENSITY_KEY, "Rules compliance", "Rules compliance",
549          Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, true, DOMAIN_RULES);
550    
551      public static final String VIOLATIONS_KEY = "violations";
552      public static final Metric VIOLATIONS = new Metric(VIOLATIONS_KEY, "Violations", "Violations", Metric.ValueType.INT,
553          Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true);
554    
555      public static final String BLOCKER_VIOLATIONS_KEY = "blocker_violations";
556      public static final Metric BLOCKER_VIOLATIONS = new Metric(BLOCKER_VIOLATIONS_KEY, "Blocker violations", "Blocker violations",
557          Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true);
558    
559      public static final String CRITICAL_VIOLATIONS_KEY = "critical_violations";
560      public static final Metric CRITICAL_VIOLATIONS = new Metric(CRITICAL_VIOLATIONS_KEY, "Critical violations", "Critical violations",
561          Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true);
562    
563      public static final String MAJOR_VIOLATIONS_KEY = "major_violations";
564      public static final Metric MAJOR_VIOLATIONS = new Metric(MAJOR_VIOLATIONS_KEY, "Major violations", "Major violations",
565          Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true);
566    
567      public static final String MINOR_VIOLATIONS_KEY = "minor_violations";
568      public static final Metric MINOR_VIOLATIONS = new Metric(MINOR_VIOLATIONS_KEY, "Minor violations", "Minor violations",
569          Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true);
570    
571      public static final String INFO_VIOLATIONS_KEY = "info_violations";
572      public static final Metric INFO_VIOLATIONS = new Metric(INFO_VIOLATIONS_KEY, "Info violations", "Info violations", Metric.ValueType.INT,
573          Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true);
574    
575      public static final String NEW_VIOLATIONS_KEY = "new_violations";
576      public static final Metric NEW_VIOLATIONS = new Metric.Builder(NEW_VIOLATIONS_KEY, "New Violations", Metric.ValueType.INT)
577          .setDescription("New Violations")
578          .setDirection(Metric.DIRECTION_WORST)
579          .setQualitative(true)
580          .setDomain(DOMAIN_RULES)
581          .setBestValue(0.0)
582          .setOptimizedBestValue(true)
583          .create();
584    
585      public static final String NEW_BLOCKER_VIOLATIONS_KEY = "new_blocker_violations";
586      public static final Metric NEW_BLOCKER_VIOLATIONS = new Metric.Builder(NEW_BLOCKER_VIOLATIONS_KEY, "New Blocker violations", Metric.ValueType.INT)
587          .setDescription("New Blocker violations")
588          .setDirection(Metric.DIRECTION_WORST)
589          .setQualitative(true)
590          .setDomain(DOMAIN_RULES)
591          .setBestValue(0.0)
592          .setOptimizedBestValue(true)
593          .create();
594    
595      public static final String NEW_CRITICAL_VIOLATIONS_KEY = "new_critical_violations";
596      public static final Metric NEW_CRITICAL_VIOLATIONS = new Metric.Builder(NEW_CRITICAL_VIOLATIONS_KEY, "New Critical violations", Metric.ValueType.INT)
597          .setDescription("New Critical violations")
598          .setDirection(Metric.DIRECTION_WORST)
599          .setQualitative(true)
600          .setDomain(DOMAIN_RULES)
601          .setBestValue(0.0)
602          .setOptimizedBestValue(true)
603          .create();
604    
605      public static final String NEW_MAJOR_VIOLATIONS_KEY = "new_major_violations";
606      public static final Metric NEW_MAJOR_VIOLATIONS = new Metric.Builder(NEW_MAJOR_VIOLATIONS_KEY, "New Major violations", Metric.ValueType.INT)
607          .setDescription("New Major violations")
608          .setDirection(Metric.DIRECTION_WORST)
609          .setQualitative(true)
610          .setDomain(DOMAIN_RULES)
611          .setBestValue(0.0)
612          .setOptimizedBestValue(true)
613          .create();
614    
615      public static final String NEW_MINOR_VIOLATIONS_KEY = "new_minor_violations";
616      public static final Metric NEW_MINOR_VIOLATIONS = new Metric.Builder(NEW_MINOR_VIOLATIONS_KEY, "New Minor violations", Metric.ValueType.INT)
617          .setDescription("New Minor violations")
618          .setDirection(Metric.DIRECTION_WORST)
619          .setQualitative(true)
620          .setDomain(DOMAIN_RULES)
621          .setBestValue(0.0)
622          .setOptimizedBestValue(true)
623          .create();
624    
625      public static final String NEW_INFO_VIOLATIONS_KEY = "new_info_violations";
626      public static final Metric NEW_INFO_VIOLATIONS = new Metric.Builder(NEW_INFO_VIOLATIONS_KEY, "New Info violations", Metric.ValueType.INT)
627          .setDescription("New Info violations")
628          .setDirection(Metric.DIRECTION_WORST)
629          .setQualitative(true)
630          .setDomain(DOMAIN_RULES)
631          .setBestValue(0.0)
632          .setOptimizedBestValue(true)
633          .create();
634    
635    
636      //--------------------------------------------------------------------------------------------------------------------
637      //
638      // DESIGN
639      //
640      //--------------------------------------------------------------------------------------------------------------------
641    
642      public static final String ABSTRACTNESS_KEY = "abstractness";
643      public static final Metric ABSTRACTNESS = new Metric(ABSTRACTNESS_KEY, "Abstractness", "Abstractness", Metric.ValueType.PERCENT,
644          Metric.DIRECTION_NONE, false, DOMAIN_DESIGN);
645      public static final String INSTABILITY_KEY = "instability";
646      public static final Metric INSTABILITY = new Metric(INSTABILITY_KEY, "Instability", "Instability", Metric.ValueType.PERCENT,
647          Metric.DIRECTION_NONE, false, DOMAIN_DESIGN);
648      public static final String DISTANCE_KEY = "distance";
649      public static final Metric DISTANCE = new Metric(DISTANCE_KEY, "Distance", "Distance", Metric.ValueType.FLOAT, Metric.DIRECTION_NONE,
650          false, DOMAIN_DESIGN);
651    
652      public static final String DEPTH_IN_TREE_KEY = "dit";
653      public static final Metric DEPTH_IN_TREE = new Metric(DEPTH_IN_TREE_KEY, "Depth in Tree", "Depth in Inheritance Tree",
654          Metric.ValueType.INT, Metric.DIRECTION_NONE, false, DOMAIN_DESIGN);
655    
656      public static final String NUMBER_OF_CHILDREN_KEY = "noc";
657      public static final Metric NUMBER_OF_CHILDREN = new Metric(NUMBER_OF_CHILDREN_KEY, "Number of Children", "Number of Children",
658          Metric.ValueType.INT, Metric.DIRECTION_NONE, false, DOMAIN_DESIGN);
659    
660      public static final String RFC_KEY = "rfc";
661      public static final Metric RFC = new Metric(RFC_KEY, "RFC", "Response for Class", Metric.ValueType.INT, Metric.DIRECTION_WORST, false,
662          DOMAIN_DESIGN).setFormula(new WeightedMeanAggregationFormula(CoreMetrics.FILES, false));
663    
664      public static final String RFC_DISTRIBUTION_KEY = "rfc_distribution";
665      public static final Metric RFC_DISTRIBUTION = new Metric(RFC_DISTRIBUTION_KEY, "Class distribution /RFC", "Class distribution /RFC",
666          Metric.ValueType.DISTRIB, Metric.DIRECTION_NONE, true, DOMAIN_DESIGN)
667          .setFormula(new SumChildDistributionFormula().setMinimumScopeToPersist(Scopes.DIRECTORY));
668    
669      public static final String LCOM4_KEY = "lcom4";
670      public static final Metric LCOM4 = new Metric(LCOM4_KEY, "LCOM4", "Lack of Cohesion of Methods", Metric.ValueType.FLOAT,
671          Metric.DIRECTION_WORST, true, DOMAIN_DESIGN).setFormula(new WeightedMeanAggregationFormula(CoreMetrics.FILES, false));
672    
673      public static final String LCOM4_BLOCKS_KEY = "lcom4_blocks";
674      public static final Metric LCOM4_BLOCKS = new Metric(LCOM4_BLOCKS_KEY, "LCOM4 blocks", "LCOM4 blocks", Metric.ValueType.DATA,
675          Metric.DIRECTION_NONE, false, DOMAIN_DESIGN).setHidden(true);
676    
677      public static final String LCOM4_DISTRIBUTION_KEY = "lcom4_distribution";
678      public static final Metric LCOM4_DISTRIBUTION = new Metric(LCOM4_DISTRIBUTION_KEY, "Class distribution /LCOM4",
679          "Class distribution /LCOM4", Metric.ValueType.DISTRIB, Metric.DIRECTION_NONE, true, DOMAIN_DESIGN)
680          .setFormula(new SumChildDistributionFormula().setMinimumScopeToPersist(Scopes.DIRECTORY));
681    
682      public static final String SUSPECT_LCOM4_DENSITY_KEY = "suspect_lcom4_density";
683      public static final Metric SUSPECT_LCOM4_DENSITY = new Metric(SUSPECT_LCOM4_DENSITY_KEY, "Suspect LCOM4 density",
684          "Density of classes having LCOM4>1", Metric.ValueType.PERCENT, Metric.DIRECTION_WORST, true, DOMAIN_DESIGN);
685    
686      public static final String AFFERENT_COUPLINGS_KEY = "ca";
687      public static final Metric AFFERENT_COUPLINGS = new Metric(AFFERENT_COUPLINGS_KEY, "Afferent couplings", "Afferent couplings",
688          Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_DESIGN);
689      public static final String EFFERENT_COUPLINGS_KEY = "ce";
690      public static final Metric EFFERENT_COUPLINGS = new Metric(EFFERENT_COUPLINGS_KEY, "Efferent couplings", "Efferent couplings",
691          Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_DESIGN);
692    
693      public static final String DEPENDENCY_MATRIX_KEY = "dsm";
694      public static final Metric DEPENDENCY_MATRIX = new Metric(DEPENDENCY_MATRIX_KEY, "Dependency Matrix", "Dependency Matrix",
695          Metric.ValueType.DATA, Metric.DIRECTION_NONE, false, DOMAIN_DESIGN);
696    
697      public static final String PACKAGE_CYCLES_KEY = "package_cycles";
698      public static final Metric PACKAGE_CYCLES = new Metric(PACKAGE_CYCLES_KEY, "Package cycles", "Package cycles", Metric.ValueType.INT,
699          Metric.DIRECTION_WORST, true, DOMAIN_DESIGN).setFormula(new SumChildValuesFormula(false));
700    
701      public static final String PACKAGE_TANGLE_INDEX_KEY = "package_tangle_index";
702      public static final Metric PACKAGE_TANGLE_INDEX = new Metric(PACKAGE_TANGLE_INDEX_KEY, "Package tangle index", "Package tangle index",
703          Metric.ValueType.PERCENT, Metric.DIRECTION_WORST, true, DOMAIN_DESIGN);
704    
705      public static final String PACKAGE_TANGLES_KEY = "package_tangles";
706      public static final Metric PACKAGE_TANGLES = new Metric(PACKAGE_TANGLES_KEY, "File dependencies to cut", "File dependencies to cut",
707          Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_DESIGN).setFormula(new SumChildValuesFormula(false));
708    
709      public static final String PACKAGE_FEEDBACK_EDGES_KEY = "package_feedback_edges";
710      public static final Metric PACKAGE_FEEDBACK_EDGES = new Metric(PACKAGE_FEEDBACK_EDGES_KEY, "Package dependencies to cut",
711          "Package dependencies to cut", Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_DESIGN)
712          .setFormula(new SumChildValuesFormula(false));
713    
714      public static final String PACKAGE_EDGES_WEIGHT_KEY = "package_edges_weight";
715      public static final Metric PACKAGE_EDGES_WEIGHT = new Metric(PACKAGE_EDGES_WEIGHT_KEY, "Package edges weight", "Package edges weight",
716          Metric.ValueType.INT, Metric.DIRECTION_BETTER, false, DOMAIN_DESIGN).setFormula(new SumChildValuesFormula(false)).setHidden(true);
717    
718      public static final String FILE_CYCLES_KEY = "file_cycles";
719      public static final Metric FILE_CYCLES = new Metric(FILE_CYCLES_KEY, "File cycles", "File cycles", Metric.ValueType.INT,
720          Metric.DIRECTION_WORST, true, DOMAIN_DESIGN).setHidden(true);
721    
722      public static final String FILE_TANGLE_INDEX_KEY = "file_tangle_index";
723      public static final Metric FILE_TANGLE_INDEX = new Metric(FILE_TANGLE_INDEX_KEY, "File tangle index", "File tangle index",
724          Metric.ValueType.PERCENT, Metric.DIRECTION_WORST, true, DOMAIN_DESIGN).setHidden(true);
725    
726      public static final String FILE_TANGLES_KEY = "file_tangles";
727      public static final Metric FILE_TANGLES = new Metric(FILE_TANGLES_KEY, "File tangles", "Files tangles", Metric.ValueType.INT,
728          Metric.DIRECTION_WORST, false, DOMAIN_DESIGN).setHidden(true);
729    
730      public static final String FILE_FEEDBACK_EDGES_KEY = "file_feedback_edges";
731      public static final Metric FILE_FEEDBACK_EDGES = new Metric(FILE_FEEDBACK_EDGES_KEY, "Suspect file dependencies",
732          "Suspect file dependencies", Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_DESIGN).setHidden(true);
733    
734      public static final String FILE_EDGES_WEIGHT_KEY = "file_edges_weight";
735      public static final Metric FILE_EDGES_WEIGHT = new Metric(FILE_EDGES_WEIGHT_KEY, "File edges weight", "File edges weight",
736          Metric.ValueType.INT, Metric.DIRECTION_BETTER, false, DOMAIN_DESIGN).setHidden(true);
737    
738    
739      //--------------------------------------------------------------------------------------------------------------------
740      //
741      // SCM
742      // These metrics are computed by the SCM Activity plugin, since version 1.2.
743      //
744      //--------------------------------------------------------------------------------------------------------------------
745    
746      public static final String SCM_COMMITS_KEY = "commits";
747      public static final Metric SCM_COMMITS = new Metric.Builder(SCM_COMMITS_KEY, "Commits", Metric.ValueType.INT)
748          .setDomain(DOMAIN_SCM)
749          .create();
750    
751      public static final String SCM_LAST_COMMIT_DATE_KEY = "last_commit_date";
752      public static final Metric SCM_LAST_COMMIT_DATE = new Metric.Builder(SCM_LAST_COMMIT_DATE_KEY, "Last commit", Metric.ValueType.STRING /* TODO: move to date */)
753          .setDomain(DOMAIN_SCM)
754          .create();
755    
756      public static final String SCM_REVISION_KEY = "revision";
757      public static final Metric SCM_REVISION = new Metric.Builder(SCM_REVISION_KEY, "Revision", Metric.ValueType.STRING)
758          .setDomain(DOMAIN_SCM)
759          .create();
760    
761      public static final String SCM_AUTHORS_BY_LINE_KEY = "authors_by_line";
762      public static final Metric SCM_AUTHORS_BY_LINE = new Metric.Builder(SCM_AUTHORS_BY_LINE_KEY, "Authors by line", Metric.ValueType.DATA)
763          .setDomain(DOMAIN_SCM)
764          .create();
765    
766      public static final String SCM_REVISIONS_BY_LINE_KEY = "revisions_by_line";
767      public static final Metric SCM_REVISIONS_BY_LINE = new Metric.Builder(SCM_REVISIONS_BY_LINE_KEY, "Revisions by line", Metric.ValueType.DATA)
768          .setDomain(DOMAIN_SCM)
769          .create();
770    
771      public static final String SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY = "last_commit_datetimes_by_line";
772      public static final Metric SCM_LAST_COMMIT_DATETIMES_BY_LINE = new Metric.Builder(SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY, "Last commit dates by line", Metric.ValueType.DATA)
773          .setDomain(DOMAIN_SCM)
774          .create();
775    
776    
777      //--------------------------------------------------------------------------------------------------------------------
778      //
779      // OTHERS
780      //
781      //--------------------------------------------------------------------------------------------------------------------
782      public static final String ALERT_STATUS_KEY = "alert_status";
783      public static final Metric ALERT_STATUS = new Metric.Builder(ALERT_STATUS_KEY, "Alert", Metric.ValueType.LEVEL)
784          .setDescription("Alert")
785          .setDirection(Metric.DIRECTION_BETTER)
786          .setQualitative(true)
787          .setDomain(DOMAIN_GENERAL)
788          .create();
789    
790    
791      public static final String PROFILE_KEY = "profile";
792      public static final Metric PROFILE = new Metric.Builder(PROFILE_KEY, "Profile", Metric.ValueType.DATA)
793          .setDescription("Selected quality profile")
794          .setDomain(DOMAIN_GENERAL)
795          .create();
796    
797    
798      public static List<Metric> metrics = Lists.newLinkedList();
799    
800      public static List<Metric> getMetrics() {
801        if (metrics.isEmpty()) {
802          for (Field field : CoreMetrics.class.getFields()) {
803            if (Metric.class.isAssignableFrom(field.getType())) {
804              try {
805                Metric metric = (Metric) field.get(null);
806                if (!StringUtils.equals(metric.getDomain(), DOMAIN_RULE_CATEGORIES)) {
807                  metrics.add(metric);
808                }
809              } catch (IllegalAccessException e) {
810                throw new SonarException("can not load metrics from " + CoreMetrics.class.getSimpleName(), e);
811              }
812            }
813          }
814        }
815        return metrics;
816      }
817    }