You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CoreMetrics.java 64KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.api.measures;
  21. import java.lang.reflect.Field;
  22. import java.lang.reflect.Modifier;
  23. import java.util.LinkedList;
  24. import java.util.List;
  25. import java.util.NoSuchElementException;
  26. import org.sonar.api.utils.SonarException;
  27. /**
  28. * @since 1.10
  29. */
  30. public final class CoreMetrics {
  31. // the following fields are not final to avoid compile-time constants used by plugins
  32. public static String DOMAIN_SIZE = "Size";
  33. public static String DOMAIN_COVERAGE = "Coverage";
  34. public static String DOMAIN_COMPLEXITY = "Complexity";
  35. /**
  36. * @deprecated since 6.2. Merged into {@link #DOMAIN_SIZE}
  37. */
  38. @Deprecated
  39. public static String DOMAIN_DOCUMENTATION = "Documentation";
  40. public static String DOMAIN_SCM = "SCM";
  41. public static String DOMAIN_ISSUES = "Issues";
  42. public static String DOMAIN_GENERAL = "General";
  43. public static String DOMAIN_DUPLICATIONS = "Duplications";
  44. /**
  45. * @deprecated in 5.5. Renamed to {@link #DOMAIN_DUPLICATIONS}
  46. */
  47. @Deprecated
  48. public static String DOMAIN_DUPLICATION = "Duplication";
  49. /**
  50. * SonarQube Quality Model
  51. *
  52. * @since 5.5
  53. */
  54. public static String DOMAIN_MAINTAINABILITY = "Maintainability";
  55. /**
  56. * SonarQube Quality Model
  57. *
  58. * @since 5.5
  59. */
  60. public static String DOMAIN_RELIABILITY = "Reliability";
  61. /**
  62. * SonarQube Quality Model
  63. *
  64. * @since 5.5
  65. */
  66. public static String DOMAIN_SECURITY = "Security";
  67. /**
  68. * @since 8.2
  69. */
  70. public static String DOMAIN_SECURITY_REVIEW = "SecurityReview";
  71. /**
  72. * @since 5.5
  73. */
  74. public static String DOMAIN_RELEASABILITY = "Releasability";
  75. /**
  76. * Computed by the platform since SQ 5.1
  77. */
  78. public static final String LINES_KEY = "lines";
  79. public static final Metric<Integer> LINES = new Metric.Builder(LINES_KEY, "Lines", Metric.ValueType.INT)
  80. .setDescription("Lines")
  81. .setDirection(Metric.DIRECTION_WORST)
  82. .setQualitative(false)
  83. .setDomain(DOMAIN_SIZE)
  84. .create();
  85. public static final String GENERATED_LINES_KEY = "generated_lines";
  86. public static final Metric<Integer> GENERATED_LINES = new Metric.Builder(GENERATED_LINES_KEY, "Generated Lines", Metric.ValueType.INT)
  87. .setDescription("Number of generated lines")
  88. .setDirection(Metric.DIRECTION_WORST)
  89. .setQualitative(false)
  90. .setDomain(DOMAIN_SIZE)
  91. .setBestValue(0.0)
  92. .setOptimizedBestValue(true)
  93. .create();
  94. public static final String NCLOC_KEY = "ncloc";
  95. public static final Metric<Integer> NCLOC = new Metric.Builder(NCLOC_KEY, "Lines of Code", Metric.ValueType.INT)
  96. .setDescription("Non commenting lines of code")
  97. .setDirection(Metric.DIRECTION_WORST)
  98. .setQualitative(false)
  99. .setDomain(DOMAIN_SIZE)
  100. .create();
  101. /**
  102. * @since 6.1
  103. */
  104. public static final String NEW_LINES_KEY = "new_lines";
  105. /**
  106. * @since 6.1
  107. */
  108. public static final Metric<Integer> NEW_LINES = new Metric.Builder(NEW_LINES_KEY, "New Lines", Metric.ValueType.INT)
  109. .setDescription("New lines")
  110. .setDirection(Metric.DIRECTION_WORST)
  111. .setQualitative(false)
  112. .setDomain(DOMAIN_SIZE)
  113. .setDeleteHistoricalData(true)
  114. .create();
  115. /**
  116. * @since 4.4
  117. */
  118. public static final String NCLOC_LANGUAGE_DISTRIBUTION_KEY = "ncloc_language_distribution";
  119. /**
  120. * @since 4.4
  121. */
  122. public static final Metric<String> NCLOC_LANGUAGE_DISTRIBUTION = new Metric.Builder(NCLOC_LANGUAGE_DISTRIBUTION_KEY, "Lines of Code Per Language", Metric.ValueType.DATA)
  123. .setDescription("Non Commenting Lines of Code Distributed By Language")
  124. .setDirection(Metric.DIRECTION_WORST)
  125. .setQualitative(false)
  126. .setDomain(DOMAIN_SIZE)
  127. .create();
  128. public static final String GENERATED_NCLOC_KEY = "generated_ncloc";
  129. public static final Metric<Integer> GENERATED_NCLOC = new Metric.Builder(GENERATED_NCLOC_KEY, "Generated Lines of Code", Metric.ValueType.INT)
  130. .setDescription("Generated non Commenting Lines of Code")
  131. .setDirection(Metric.DIRECTION_WORST)
  132. .setQualitative(false)
  133. .setDomain(DOMAIN_SIZE)
  134. .setBestValue(0.0)
  135. .setOptimizedBestValue(true)
  136. .create();
  137. public static final String CLASSES_KEY = "classes";
  138. public static final Metric<Integer> CLASSES = new Metric.Builder(CLASSES_KEY, "Classes", Metric.ValueType.INT)
  139. .setDescription("Classes")
  140. .setDirection(Metric.DIRECTION_WORST)
  141. .setQualitative(false)
  142. .setDomain(DOMAIN_SIZE)
  143. .create();
  144. public static final String FILES_KEY = "files";
  145. /**
  146. * Computed by the platform.
  147. */
  148. public static final Metric<Integer> FILES = new Metric.Builder(FILES_KEY, "Files", Metric.ValueType.INT)
  149. .setDescription("Number of files")
  150. .setDirection(Metric.DIRECTION_WORST)
  151. .setQualitative(false)
  152. .setDomain(DOMAIN_SIZE)
  153. .create();
  154. /**
  155. * @deprecated since 7.7 - no longer computed
  156. */
  157. @Deprecated
  158. public static final String DIRECTORIES_KEY = "directories";
  159. /**
  160. * @deprecated since 7.7 - no longer computed
  161. */
  162. @Deprecated
  163. public static final Metric<Integer> DIRECTORIES = new Metric.Builder(DIRECTORIES_KEY, "Directories", Metric.ValueType.INT)
  164. .setDescription("Directories")
  165. .setDirection(Metric.DIRECTION_WORST)
  166. .setQualitative(false)
  167. .setDomain(DOMAIN_SIZE)
  168. .create();
  169. /**
  170. * Computed by the platform.
  171. */
  172. public static final String FUNCTIONS_KEY = "functions";
  173. public static final Metric<Integer> FUNCTIONS = new Metric.Builder(FUNCTIONS_KEY, "Functions", Metric.ValueType.INT)
  174. .setDescription("Functions")
  175. .setDirection(Metric.DIRECTION_WORST)
  176. .setQualitative(false)
  177. .setDomain(DOMAIN_SIZE)
  178. .create();
  179. public static final String STATEMENTS_KEY = "statements";
  180. public static final Metric<Integer> STATEMENTS = new Metric.Builder(STATEMENTS_KEY, "Statements", Metric.ValueType.INT)
  181. .setDescription("Number of statements")
  182. .setDirection(Metric.DIRECTION_WORST)
  183. .setQualitative(false)
  184. .setDomain(DOMAIN_SIZE)
  185. .create();
  186. /**
  187. * @see <a href="https://jira.sonarsource.com/browse/SONAR-8328">SONAR-8328</a>
  188. * @deprecated since 6.2
  189. */
  190. @Deprecated
  191. public static final String PUBLIC_API_KEY = "public_api";
  192. public static final Metric<Integer> PUBLIC_API = new Metric.Builder(PUBLIC_API_KEY, "Public API", Metric.ValueType.INT)
  193. .setDescription("Public API")
  194. .setDirection(Metric.DIRECTION_WORST)
  195. .setQualitative(false)
  196. .setDomain(DOMAIN_DOCUMENTATION)
  197. .setHidden(true)
  198. .create();
  199. /**
  200. * @since 3.0
  201. */
  202. public static final String PROJECTS_KEY = "projects";
  203. /**
  204. * @since 3.0
  205. */
  206. public static final Metric<Integer> PROJECTS = new Metric.Builder(PROJECTS_KEY, "Project branches", Metric.ValueType.INT)
  207. .setDescription("Number of project branches")
  208. .setDirection(Metric.DIRECTION_WORST)
  209. .setQualitative(false)
  210. .setDomain(DOMAIN_SIZE)
  211. .create();
  212. /**
  213. * Moved to Size domain since 6.2
  214. */
  215. public static final String COMMENT_LINES_KEY = "comment_lines";
  216. public static final Metric<Integer> COMMENT_LINES = new Metric.Builder(COMMENT_LINES_KEY, "Comment Lines", Metric.ValueType.INT)
  217. .setDescription("Number of comment lines")
  218. .setDirection(Metric.DIRECTION_BETTER)
  219. .setQualitative(false)
  220. .setDomain(DOMAIN_SIZE)
  221. .create();
  222. /**
  223. * Moved to Size domain since 6.2
  224. */
  225. public static final String COMMENT_LINES_DENSITY_KEY = "comment_lines_density";
  226. public static final Metric<Double> COMMENT_LINES_DENSITY = new Metric.Builder(COMMENT_LINES_DENSITY_KEY, "Comments (%)", Metric.ValueType.PERCENT)
  227. .setDescription("Comments balanced by ncloc + comment lines")
  228. .setDirection(Metric.DIRECTION_BETTER)
  229. .setQualitative(true)
  230. .setDomain(DOMAIN_SIZE)
  231. .create();
  232. // --------------------------------------------------------------------------------------------------------------------
  233. //
  234. // DOCUMENTATION
  235. //
  236. // --------------------------------------------------------------------------------------------------------------------
  237. /**
  238. * @see <a href="https://jira.sonarsource.com/browse/SONAR-8328">SONAR-8328</a>
  239. * @deprecated since 6.2
  240. */
  241. @Deprecated
  242. public static final String PUBLIC_DOCUMENTED_API_DENSITY_KEY = "public_documented_api_density";
  243. public static final Metric<Double> PUBLIC_DOCUMENTED_API_DENSITY = new Metric.Builder(PUBLIC_DOCUMENTED_API_DENSITY_KEY, "Public Documented API (%)", Metric.ValueType.PERCENT)
  244. .setDescription("Public documented classes and functions balanced by ncloc")
  245. .setDirection(Metric.DIRECTION_BETTER)
  246. .setQualitative(true)
  247. .setDomain(DOMAIN_DOCUMENTATION)
  248. .setWorstValue(0.0)
  249. .setBestValue(100.0)
  250. .setOptimizedBestValue(true)
  251. .setHidden(true)
  252. .create();
  253. /**
  254. * @see <a href="https://jira.sonarsource.com/browse/SONAR-8328">SONAR-8328</a>
  255. * @deprecated since 6.2
  256. */
  257. @Deprecated
  258. public static final String PUBLIC_UNDOCUMENTED_API_KEY = "public_undocumented_api";
  259. public static final Metric<Integer> PUBLIC_UNDOCUMENTED_API = new Metric.Builder(PUBLIC_UNDOCUMENTED_API_KEY, "Public Undocumented API", Metric.ValueType.INT)
  260. .setDescription("Public undocumented classes, functions and variables")
  261. .setDirection(Metric.DIRECTION_WORST)
  262. .setQualitative(true)
  263. .setDomain(DOMAIN_DOCUMENTATION)
  264. .setBestValue(0.0)
  265. .setDirection(Metric.DIRECTION_WORST)
  266. .setOptimizedBestValue(true)
  267. .setHidden(true)
  268. .create();
  269. // --------------------------------------------------------------------------------------------------------------------
  270. //
  271. // COMPLEXITY
  272. //
  273. // --------------------------------------------------------------------------------------------------------------------
  274. public static final String COMPLEXITY_KEY = "complexity";
  275. public static final Metric<Integer> COMPLEXITY = new Metric.Builder(COMPLEXITY_KEY, "Cyclomatic Complexity", Metric.ValueType.INT)
  276. .setDescription("Cyclomatic complexity")
  277. .setDirection(Metric.DIRECTION_WORST)
  278. .setQualitative(false)
  279. .setDomain(DOMAIN_COMPLEXITY)
  280. .create();
  281. /**
  282. * @deprecated since 6.7
  283. */
  284. @Deprecated
  285. public static final String FILE_COMPLEXITY_KEY = "file_complexity";
  286. /**
  287. * Information about the cyclomatic complexity per file, calculated by divided the {@link #COMPLEXITY} by the number of {@link #FILES}.
  288. *
  289. * @deprecated since 6.7
  290. */
  291. @Deprecated
  292. public static final Metric<Double> FILE_COMPLEXITY = new Metric.Builder(FILE_COMPLEXITY_KEY, "Complexity / File", Metric.ValueType.FLOAT)
  293. .setDescription("Complexity average by file")
  294. .setDirection(Metric.DIRECTION_WORST)
  295. .setQualitative(true)
  296. .setDomain(DOMAIN_COMPLEXITY)
  297. .setHidden(true)
  298. .create();
  299. /**
  300. * @since 3.6
  301. * @deprecated since 6.7
  302. */
  303. @Deprecated
  304. public static final String COMPLEXITY_IN_CLASSES_KEY = "complexity_in_classes";
  305. /**
  306. * @since 3.6
  307. * @deprecated since 6.7
  308. */
  309. @Deprecated
  310. public static final Metric<Integer> COMPLEXITY_IN_CLASSES = new Metric.Builder(COMPLEXITY_IN_CLASSES_KEY, "Complexity in Classes", Metric.ValueType.INT)
  311. .setDescription("Cyclomatic complexity in classes")
  312. .setHidden(true)
  313. .setDirection(Metric.DIRECTION_WORST)
  314. .setQualitative(false)
  315. .setDomain(DOMAIN_COMPLEXITY)
  316. .setDeleteHistoricalData(true)
  317. .setHidden(true)
  318. .create();
  319. /**
  320. * @deprecated since 6.7
  321. */
  322. @Deprecated
  323. public static final String CLASS_COMPLEXITY_KEY = "class_complexity";
  324. /**
  325. * Information about the cyclomatic complexity per class, calculated by divided the {@link #COMPLEXITY_IN_CLASSES} by the number of {@link #CLASSES}.
  326. *
  327. * @deprecated since 6.7
  328. */
  329. @Deprecated
  330. public static final Metric<Double> CLASS_COMPLEXITY = new Metric.Builder(CLASS_COMPLEXITY_KEY, "Complexity / Class", Metric.ValueType.FLOAT)
  331. .setDescription("Complexity average by class")
  332. .setDirection(Metric.DIRECTION_WORST)
  333. .setQualitative(true)
  334. .setDomain(DOMAIN_COMPLEXITY)
  335. .setHidden(true)
  336. .create();
  337. /**
  338. * @since 3.6
  339. * @deprecated since 6.7
  340. */
  341. @Deprecated
  342. public static final String COMPLEXITY_IN_FUNCTIONS_KEY = "complexity_in_functions";
  343. /**
  344. * @since 3.6
  345. * @deprecated since 6.7
  346. */
  347. @Deprecated
  348. public static final Metric<Integer> COMPLEXITY_IN_FUNCTIONS = new Metric.Builder(COMPLEXITY_IN_FUNCTIONS_KEY, "Complexity in Functions", Metric.ValueType.INT)
  349. .setDescription("Cyclomatic complexity in functions")
  350. .setHidden(true)
  351. .setDirection(Metric.DIRECTION_WORST)
  352. .setQualitative(false)
  353. .setDomain(DOMAIN_COMPLEXITY)
  354. .setDeleteHistoricalData(true)
  355. .setHidden(true)
  356. .create();
  357. /**
  358. * @deprecated since 6.7
  359. */
  360. @Deprecated
  361. public static final String FUNCTION_COMPLEXITY_KEY = "function_complexity";
  362. /**
  363. * Information about the cyclomatic complexity per function, calculated by divided the {@link #COMPLEXITY_IN_FUNCTIONS} by the number of {@link #FUNCTIONS}.
  364. *
  365. * @deprecated since 6.7
  366. */
  367. @Deprecated
  368. public static final Metric<Double> FUNCTION_COMPLEXITY = new Metric.Builder(FUNCTION_COMPLEXITY_KEY, "Complexity / Function", Metric.ValueType.FLOAT)
  369. .setDescription("Complexity average by function")
  370. .setDirection(Metric.DIRECTION_WORST)
  371. .setQualitative(true)
  372. .setDomain(DOMAIN_COMPLEXITY)
  373. .setHidden(true)
  374. .create();
  375. /**
  376. * @deprecated since 6.7
  377. */
  378. @Deprecated
  379. public static final String FUNCTION_COMPLEXITY_DISTRIBUTION_KEY = "function_complexity_distribution";
  380. /**
  381. * @deprecated since 6.7
  382. */
  383. @Deprecated
  384. public static final Metric<String> FUNCTION_COMPLEXITY_DISTRIBUTION = new Metric.Builder(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, "Function Distribution / Complexity",
  385. Metric.ValueType.DISTRIB)
  386. .setDescription("Functions distribution /complexity")
  387. .setDirection(Metric.DIRECTION_NONE)
  388. .setQualitative(true)
  389. .setDomain(DOMAIN_COMPLEXITY)
  390. .setHidden(true)
  391. .create();
  392. /**
  393. * @deprecated since 6.7
  394. */
  395. @Deprecated
  396. public static final String FILE_COMPLEXITY_DISTRIBUTION_KEY = "file_complexity_distribution";
  397. /**
  398. * @deprecated since 6.7
  399. */
  400. @Deprecated
  401. public static final Metric<String> FILE_COMPLEXITY_DISTRIBUTION = new Metric.Builder(FILE_COMPLEXITY_DISTRIBUTION_KEY, "File Distribution / Complexity",
  402. Metric.ValueType.DISTRIB)
  403. .setDescription("Files distribution /complexity")
  404. .setDirection(Metric.DIRECTION_NONE)
  405. .setQualitative(true)
  406. .setDomain(DOMAIN_COMPLEXITY)
  407. .setHidden(true)
  408. .create();
  409. public static final String COGNITIVE_COMPLEXITY_KEY = "cognitive_complexity";
  410. public static final Metric<Integer> COGNITIVE_COMPLEXITY = new Metric.Builder(COGNITIVE_COMPLEXITY_KEY, "Cognitive Complexity", Metric.ValueType.INT)
  411. .setDescription("Cognitive complexity")
  412. .setDirection(Metric.DIRECTION_WORST)
  413. .setQualitative(false)
  414. .setDomain(DOMAIN_COMPLEXITY)
  415. .setBestValue(0.0)
  416. .setOptimizedBestValue(true)
  417. .create();
  418. // --------------------------------------------------------------------------------------------------------------------
  419. //
  420. // UNIT TESTS
  421. //
  422. // --------------------------------------------------------------------------------------------------------------------
  423. public static final String TESTS_KEY = "tests";
  424. /**
  425. * Value of measure for this metric can be saved from Sensor, taking into account following rules:
  426. * <ul>
  427. * <li>Non-zero value should be saved for resources representing tests. And Sonar provides default Decorator, which will decorate parent resources.</li>
  428. * <li>Should include {@link #TEST_FAILURES} and {@link #TEST_ERRORS}, but should not include {@link #SKIPPED_TESTS}.</li>
  429. * </ul>
  430. */
  431. public static final Metric<Integer> TESTS = new Metric.Builder(TESTS_KEY, "Unit Tests", Metric.ValueType.INT)
  432. .setDescription("Number of unit tests")
  433. .setDirection(Metric.DIRECTION_BETTER)
  434. .setQualitative(false)
  435. .setDomain(DOMAIN_COVERAGE)
  436. .create();
  437. public static final String TEST_EXECUTION_TIME_KEY = "test_execution_time";
  438. public static final Metric<Long> TEST_EXECUTION_TIME = new Metric.Builder(TEST_EXECUTION_TIME_KEY, "Unit Test Duration", Metric.ValueType.MILLISEC)
  439. .setDescription("Execution duration of unit tests")
  440. .setDirection(Metric.DIRECTION_WORST)
  441. .setQualitative(false)
  442. .setDomain(DOMAIN_COVERAGE)
  443. .create();
  444. public static final String TEST_ERRORS_KEY = "test_errors";
  445. public static final Metric<Integer> TEST_ERRORS = new Metric.Builder(TEST_ERRORS_KEY, "Unit Test Errors", Metric.ValueType.INT)
  446. .setDescription("Number of unit test errors")
  447. .setDirection(Metric.DIRECTION_WORST)
  448. .setQualitative(true)
  449. .setDomain(DOMAIN_COVERAGE)
  450. .setBestValue(0.0)
  451. .setOptimizedBestValue(true)
  452. .create();
  453. public static final String SKIPPED_TESTS_KEY = "skipped_tests";
  454. public static final Metric<Integer> SKIPPED_TESTS = new Metric.Builder(SKIPPED_TESTS_KEY, "Skipped Unit Tests", Metric.ValueType.INT)
  455. .setDescription("Number of skipped unit tests")
  456. .setDirection(Metric.DIRECTION_WORST)
  457. .setQualitative(true)
  458. .setDomain(DOMAIN_COVERAGE)
  459. .setBestValue(0.0)
  460. .setOptimizedBestValue(true)
  461. .create();
  462. public static final String TEST_FAILURES_KEY = "test_failures";
  463. public static final Metric<Integer> TEST_FAILURES = new Metric.Builder(TEST_FAILURES_KEY, "Unit Test Failures", Metric.ValueType.INT)
  464. .setDescription("Number of unit test failures")
  465. .setDirection(Metric.DIRECTION_WORST)
  466. .setQualitative(true)
  467. .setDomain(DOMAIN_COVERAGE)
  468. .setBestValue(0.0)
  469. .setOptimizedBestValue(true)
  470. .create();
  471. public static final String TEST_SUCCESS_DENSITY_KEY = "test_success_density";
  472. public static final Metric<Double> TEST_SUCCESS_DENSITY = new Metric.Builder(TEST_SUCCESS_DENSITY_KEY, "Unit Test Success (%)", Metric.ValueType.PERCENT)
  473. .setDescription("Density of successful unit tests")
  474. .setDirection(Metric.DIRECTION_BETTER)
  475. .setQualitative(true)
  476. .setDomain(DOMAIN_COVERAGE)
  477. .setWorstValue(0.0)
  478. .setBestValue(100.0)
  479. .setOptimizedBestValue(true)
  480. .create();
  481. public static final String COVERAGE_KEY = "coverage";
  482. public static final Metric<Double> COVERAGE = new Metric.Builder(COVERAGE_KEY, "Coverage", Metric.ValueType.PERCENT)
  483. .setDescription("Coverage by tests")
  484. .setDirection(Metric.DIRECTION_BETTER)
  485. .setQualitative(true)
  486. .setDomain(DOMAIN_COVERAGE)
  487. .setWorstValue(0.0)
  488. .setBestValue(100.0)
  489. .create();
  490. public static final String NEW_COVERAGE_KEY = "new_coverage";
  491. public static final Metric<Double> NEW_COVERAGE = new Metric.Builder(NEW_COVERAGE_KEY, "Coverage on New Code", Metric.ValueType.PERCENT)
  492. .setDescription("Coverage of new/changed code")
  493. .setDirection(Metric.DIRECTION_BETTER)
  494. .setQualitative(true)
  495. .setDomain(DOMAIN_COVERAGE)
  496. .setWorstValue(0.0)
  497. .setBestValue(100.0)
  498. .setDeleteHistoricalData(true)
  499. .create();
  500. public static final String LINES_TO_COVER_KEY = "lines_to_cover";
  501. public static final Metric<Integer> LINES_TO_COVER = new Metric.Builder(LINES_TO_COVER_KEY, "Lines to Cover", Metric.ValueType.INT)
  502. .setDescription("Lines to cover")
  503. .setDirection(Metric.DIRECTION_WORST)
  504. .setQualitative(false)
  505. .setDomain(DOMAIN_COVERAGE)
  506. .create();
  507. public static final String NEW_LINES_TO_COVER_KEY = "new_lines_to_cover";
  508. public static final Metric<Integer> NEW_LINES_TO_COVER = new Metric.Builder(NEW_LINES_TO_COVER_KEY, "Lines to Cover on New Code", Metric.ValueType.INT)
  509. .setDescription("Lines to cover on new code")
  510. .setDirection(Metric.DIRECTION_WORST)
  511. .setQualitative(false)
  512. .setDomain(DOMAIN_COVERAGE)
  513. .setDeleteHistoricalData(true)
  514. .create();
  515. public static final String UNCOVERED_LINES_KEY = "uncovered_lines";
  516. public static final Metric<Integer> UNCOVERED_LINES = new Metric.Builder(UNCOVERED_LINES_KEY, "Uncovered Lines", Metric.ValueType.INT)
  517. .setDescription("Uncovered lines")
  518. .setDirection(Metric.DIRECTION_WORST)
  519. .setDomain(DOMAIN_COVERAGE)
  520. .setBestValue(0.0)
  521. .create();
  522. public static final String NEW_UNCOVERED_LINES_KEY = "new_uncovered_lines";
  523. public static final Metric<Integer> NEW_UNCOVERED_LINES = new Metric.Builder(NEW_UNCOVERED_LINES_KEY, "Uncovered Lines on New Code", Metric.ValueType.INT)
  524. .setDescription("Uncovered lines on new code")
  525. .setDirection(Metric.DIRECTION_WORST)
  526. .setDomain(DOMAIN_COVERAGE)
  527. .setBestValue(0.0)
  528. .setDeleteHistoricalData(true)
  529. .create();
  530. public static final String LINE_COVERAGE_KEY = "line_coverage";
  531. public static final Metric<Double> LINE_COVERAGE = new Metric.Builder(LINE_COVERAGE_KEY, "Line Coverage", Metric.ValueType.PERCENT)
  532. .setDescription("Line coverage")
  533. .setDirection(Metric.DIRECTION_BETTER)
  534. .setQualitative(true)
  535. .setDomain(DOMAIN_COVERAGE)
  536. .setWorstValue(0.0)
  537. .setBestValue(100.0)
  538. .create();
  539. public static final String NEW_LINE_COVERAGE_KEY = "new_line_coverage";
  540. public static final Metric<Double> NEW_LINE_COVERAGE = new Metric.Builder(NEW_LINE_COVERAGE_KEY, "Line Coverage on New Code", Metric.ValueType.PERCENT)
  541. .setDescription("Line coverage of added/changed code")
  542. .setDirection(Metric.DIRECTION_BETTER)
  543. .setQualitative(true)
  544. .setWorstValue(0.0)
  545. .setBestValue(100.0)
  546. .setDomain(DOMAIN_COVERAGE)
  547. .setDeleteHistoricalData(true)
  548. .create();
  549. public static final String CONDITIONS_TO_COVER_KEY = "conditions_to_cover";
  550. public static final Metric<Integer> CONDITIONS_TO_COVER = new Metric.Builder(CONDITIONS_TO_COVER_KEY, "Conditions to Cover", Metric.ValueType.INT)
  551. .setDescription("Conditions to cover")
  552. .setDomain(DOMAIN_COVERAGE)
  553. .setDirection(Metric.DIRECTION_WORST)
  554. .create();
  555. public static final String NEW_CONDITIONS_TO_COVER_KEY = "new_conditions_to_cover";
  556. public static final Metric<Integer> NEW_CONDITIONS_TO_COVER = new Metric.Builder(NEW_CONDITIONS_TO_COVER_KEY, "Conditions to Cover on New Code", Metric.ValueType.INT)
  557. .setDescription("Conditions to cover on new code")
  558. .setDomain(DOMAIN_COVERAGE)
  559. .setDirection(Metric.DIRECTION_WORST)
  560. .setDeleteHistoricalData(true)
  561. .create();
  562. public static final String UNCOVERED_CONDITIONS_KEY = "uncovered_conditions";
  563. public static final Metric<Integer> UNCOVERED_CONDITIONS = new Metric.Builder(UNCOVERED_CONDITIONS_KEY, "Uncovered Conditions", Metric.ValueType.INT)
  564. .setDescription("Uncovered conditions")
  565. .setDirection(Metric.DIRECTION_WORST)
  566. .setDomain(DOMAIN_COVERAGE)
  567. .setBestValue(0.0)
  568. .create();
  569. public static final String NEW_UNCOVERED_CONDITIONS_KEY = "new_uncovered_conditions";
  570. public static final Metric<Integer> NEW_UNCOVERED_CONDITIONS = new Metric.Builder(NEW_UNCOVERED_CONDITIONS_KEY, "Uncovered Conditions on New Code", Metric.ValueType.INT)
  571. .setDescription("Uncovered conditions on new code")
  572. .setDirection(Metric.DIRECTION_WORST)
  573. .setDomain(DOMAIN_COVERAGE)
  574. .setBestValue(0.0)
  575. .setDeleteHistoricalData(true)
  576. .create();
  577. public static final String BRANCH_COVERAGE_KEY = "branch_coverage";
  578. public static final Metric<Double> BRANCH_COVERAGE = new Metric.Builder(BRANCH_COVERAGE_KEY, "Condition Coverage", Metric.ValueType.PERCENT)
  579. .setDescription("Condition coverage")
  580. .setDirection(Metric.DIRECTION_BETTER)
  581. .setQualitative(true)
  582. .setDomain(DOMAIN_COVERAGE)
  583. .setWorstValue(0.0)
  584. .setBestValue(100.0)
  585. .create();
  586. public static final String NEW_BRANCH_COVERAGE_KEY = "new_branch_coverage";
  587. public static final Metric<Double> NEW_BRANCH_COVERAGE = new Metric.Builder(NEW_BRANCH_COVERAGE_KEY, "Condition Coverage on New Code", Metric.ValueType.PERCENT)
  588. .setDescription("Condition coverage of new/changed code")
  589. .setDirection(Metric.DIRECTION_BETTER)
  590. .setQualitative(true)
  591. .setDomain(DOMAIN_COVERAGE)
  592. .setWorstValue(0.0)
  593. .setBestValue(100.0)
  594. .setDeleteHistoricalData(true)
  595. .create();
  596. // --------------------------------------------------------------------------------------------------------------------
  597. //
  598. // DUPLICATIONS
  599. //
  600. // --------------------------------------------------------------------------------------------------------------------
  601. public static final String DUPLICATED_LINES_KEY = "duplicated_lines";
  602. public static final Metric<Integer> DUPLICATED_LINES = new Metric.Builder(DUPLICATED_LINES_KEY, "Duplicated Lines", Metric.ValueType.INT)
  603. .setDescription("Duplicated lines")
  604. .setDirection(Metric.DIRECTION_WORST)
  605. .setQualitative(true)
  606. .setDomain(DOMAIN_DUPLICATIONS)
  607. .setBestValue(0.0)
  608. .setOptimizedBestValue(true)
  609. .create();
  610. /**
  611. * @since 6.1
  612. */
  613. public static final String NEW_DUPLICATED_LINES_KEY = "new_duplicated_lines";
  614. /**
  615. * @since 6.1
  616. */
  617. public static final Metric<Integer> NEW_DUPLICATED_LINES = new Metric.Builder(NEW_DUPLICATED_LINES_KEY, "Duplicated Lines on New Code", Metric.ValueType.INT)
  618. .setDescription("Duplicated Lines on New Code")
  619. .setDirection(Metric.DIRECTION_WORST)
  620. .setQualitative(true)
  621. .setDomain(DOMAIN_DUPLICATIONS)
  622. .setBestValue(0.0)
  623. .setDeleteHistoricalData(true)
  624. .create();
  625. public static final String DUPLICATED_BLOCKS_KEY = "duplicated_blocks";
  626. public static final Metric<Integer> DUPLICATED_BLOCKS = new Metric.Builder(DUPLICATED_BLOCKS_KEY, "Duplicated Blocks", Metric.ValueType.INT)
  627. .setDescription("Duplicated blocks")
  628. .setDirection(Metric.DIRECTION_WORST)
  629. .setQualitative(true)
  630. .setDomain(DOMAIN_DUPLICATIONS)
  631. .setBestValue(0.0)
  632. .setOptimizedBestValue(true)
  633. .create();
  634. /**
  635. * @since 6.1
  636. */
  637. public static final String NEW_BLOCKS_DUPLICATED_KEY = "new_duplicated_blocks";
  638. /**
  639. * @since 6.1
  640. */
  641. public static final Metric<Integer> NEW_BLOCKS_DUPLICATED = new Metric.Builder(NEW_BLOCKS_DUPLICATED_KEY, "Duplicated Blocks on New Code", Metric.ValueType.INT)
  642. .setDescription("Duplicated blocks on new code")
  643. .setDirection(Metric.DIRECTION_WORST)
  644. .setQualitative(true)
  645. .setDomain(DOMAIN_DUPLICATIONS)
  646. .setBestValue(0.0)
  647. .setDeleteHistoricalData(true)
  648. .create();
  649. public static final String DUPLICATED_FILES_KEY = "duplicated_files";
  650. /**
  651. * For files: if it contains duplicates, then 1, otherwise 0.
  652. * For other resources: amount of files under this resource with duplicates.
  653. */
  654. public static final Metric<Integer> DUPLICATED_FILES = new Metric.Builder(DUPLICATED_FILES_KEY, "Duplicated Files", Metric.ValueType.INT)
  655. .setDescription("Duplicated files")
  656. .setDirection(Metric.DIRECTION_WORST)
  657. .setQualitative(true)
  658. .setDomain(DOMAIN_DUPLICATIONS)
  659. .setBestValue(0.0)
  660. .setOptimizedBestValue(true)
  661. .create();
  662. public static final String DUPLICATED_LINES_DENSITY_KEY = "duplicated_lines_density";
  663. public static final Metric<Double> DUPLICATED_LINES_DENSITY = new Metric.Builder(DUPLICATED_LINES_DENSITY_KEY, "Duplicated Lines (%)", Metric.ValueType.PERCENT)
  664. .setDescription("Duplicated lines balanced by statements")
  665. .setDirection(Metric.DIRECTION_WORST)
  666. .setQualitative(true)
  667. .setDomain(DOMAIN_DUPLICATIONS)
  668. .setWorstValue(50.0)
  669. .setBestValue(0.0)
  670. .setOptimizedBestValue(true)
  671. .create();
  672. /**
  673. * @since 6.1
  674. */
  675. public static final String NEW_DUPLICATED_LINES_DENSITY_KEY = "new_duplicated_lines_density";
  676. /**
  677. * @since 6.1
  678. */
  679. public static final Metric<Integer> NEW_DUPLICATED_LINES_DENSITY = new Metric.Builder(NEW_DUPLICATED_LINES_DENSITY_KEY, "Duplicated Lines (%) on New Code",
  680. Metric.ValueType.PERCENT)
  681. .setDescription("Duplicated lines (%) on new code balanced by statements")
  682. .setDirection(Metric.DIRECTION_WORST)
  683. .setQualitative(true)
  684. .setDomain(DOMAIN_DUPLICATIONS)
  685. .setBestValue(0.0)
  686. .setDeleteHistoricalData(true)
  687. .create();
  688. /**
  689. * @deprecated since 4.5. Internal storage of duplication is not an API.
  690. */
  691. @Deprecated
  692. public static final String DUPLICATIONS_DATA_KEY = "duplications_data";
  693. /**
  694. * Information about duplications, which is represented as an XML string.
  695. * <p>
  696. * Here is the format (since Sonar 2.12):
  697. * <pre>
  698. * {@literal
  699. * <duplications>
  700. * <!-- Multiple groups: -->
  701. * <g>
  702. * <!-- Multiple blocks: -->
  703. * <b r="[resource key]" s="[first line]" l="[number of lines]" />
  704. * ...
  705. * </g>
  706. * ...
  707. * </duplications>
  708. * }
  709. * </pre>
  710. *
  711. * @deprecated since 4.5. Internal storage of duplication is not an API.
  712. */
  713. @Deprecated
  714. public static final Metric<String> DUPLICATIONS_DATA = new Metric.Builder(DUPLICATIONS_DATA_KEY, "Duplication Details", Metric.ValueType.DATA)
  715. .setDescription("Duplications details")
  716. .setDirection(Metric.DIRECTION_NONE)
  717. .setQualitative(false)
  718. .setDomain(DOMAIN_DUPLICATIONS)
  719. .setDeleteHistoricalData(true)
  720. .create();
  721. // --------------------------------------------------------------------------------------------------------------------
  722. //
  723. // CODING RULES
  724. //
  725. // --------------------------------------------------------------------------------------------------------------------
  726. public static final String VIOLATIONS_KEY = "violations";
  727. public static final Metric<Integer> VIOLATIONS = new Metric.Builder(VIOLATIONS_KEY, "Issues", Metric.ValueType.INT)
  728. .setDescription("Issues")
  729. .setDirection(Metric.DIRECTION_WORST)
  730. .setQualitative(true)
  731. .setDomain(DOMAIN_ISSUES)
  732. .setBestValue(0.0)
  733. .setOptimizedBestValue(true)
  734. .create();
  735. public static final String BLOCKER_VIOLATIONS_KEY = "blocker_violations";
  736. public static final Metric<Integer> BLOCKER_VIOLATIONS = new Metric.Builder(BLOCKER_VIOLATIONS_KEY, "Blocker Issues", Metric.ValueType.INT)
  737. .setDescription("Blocker issues")
  738. .setDirection(Metric.DIRECTION_WORST)
  739. .setQualitative(true)
  740. .setDomain(DOMAIN_ISSUES)
  741. .setBestValue(0.0)
  742. .setOptimizedBestValue(true)
  743. .create();
  744. public static final String CRITICAL_VIOLATIONS_KEY = "critical_violations";
  745. public static final Metric<Integer> CRITICAL_VIOLATIONS = new Metric.Builder(CRITICAL_VIOLATIONS_KEY, "Critical Issues", Metric.ValueType.INT)
  746. .setDescription("Critical issues")
  747. .setDirection(Metric.DIRECTION_WORST)
  748. .setQualitative(true)
  749. .setDomain(DOMAIN_ISSUES)
  750. .setBestValue(0.0)
  751. .setOptimizedBestValue(true)
  752. .create();
  753. public static final String MAJOR_VIOLATIONS_KEY = "major_violations";
  754. public static final Metric<Integer> MAJOR_VIOLATIONS = new Metric.Builder(MAJOR_VIOLATIONS_KEY, "Major Issues", Metric.ValueType.INT)
  755. .setDescription("Major issues")
  756. .setDirection(Metric.DIRECTION_WORST)
  757. .setQualitative(true)
  758. .setDomain(DOMAIN_ISSUES)
  759. .setBestValue(0.0)
  760. .setOptimizedBestValue(true)
  761. .create();
  762. public static final String MINOR_VIOLATIONS_KEY = "minor_violations";
  763. public static final Metric<Integer> MINOR_VIOLATIONS = new Metric.Builder(MINOR_VIOLATIONS_KEY, "Minor Issues", Metric.ValueType.INT)
  764. .setDescription("Minor issues")
  765. .setDirection(Metric.DIRECTION_WORST)
  766. .setQualitative(true)
  767. .setDomain(DOMAIN_ISSUES)
  768. .setBestValue(0.0)
  769. .setOptimizedBestValue(true)
  770. .create();
  771. public static final String INFO_VIOLATIONS_KEY = "info_violations";
  772. public static final Metric<Integer> INFO_VIOLATIONS = new Metric.Builder(INFO_VIOLATIONS_KEY, "Info Issues", Metric.ValueType.INT)
  773. .setDescription("Info issues")
  774. .setDirection(Metric.DIRECTION_WORST)
  775. .setQualitative(true)
  776. .setDomain(DOMAIN_ISSUES)
  777. .setBestValue(0.0)
  778. .setOptimizedBestValue(true)
  779. .create();
  780. public static final String NEW_VIOLATIONS_KEY = "new_violations";
  781. public static final Metric<Integer> NEW_VIOLATIONS = new Metric.Builder(NEW_VIOLATIONS_KEY, "New Issues", Metric.ValueType.INT)
  782. .setDescription("New issues")
  783. .setDirection(Metric.DIRECTION_WORST)
  784. .setQualitative(true)
  785. .setDomain(DOMAIN_ISSUES)
  786. .setBestValue(0.0)
  787. .setOptimizedBestValue(true)
  788. .setDeleteHistoricalData(true)
  789. .create();
  790. public static final String NEW_BLOCKER_VIOLATIONS_KEY = "new_blocker_violations";
  791. public static final Metric<Integer> NEW_BLOCKER_VIOLATIONS = new Metric.Builder(NEW_BLOCKER_VIOLATIONS_KEY, "New Blocker Issues", Metric.ValueType.INT)
  792. .setDescription("New Blocker issues")
  793. .setDirection(Metric.DIRECTION_WORST)
  794. .setQualitative(true)
  795. .setDomain(DOMAIN_ISSUES)
  796. .setBestValue(0.0)
  797. .setOptimizedBestValue(true)
  798. .setDeleteHistoricalData(true)
  799. .create();
  800. public static final String NEW_CRITICAL_VIOLATIONS_KEY = "new_critical_violations";
  801. public static final Metric<Integer> NEW_CRITICAL_VIOLATIONS = new Metric.Builder(NEW_CRITICAL_VIOLATIONS_KEY, "New Critical Issues", Metric.ValueType.INT)
  802. .setDescription("New Critical issues")
  803. .setDirection(Metric.DIRECTION_WORST)
  804. .setQualitative(true)
  805. .setDomain(DOMAIN_ISSUES)
  806. .setBestValue(0.0)
  807. .setOptimizedBestValue(true)
  808. .setDeleteHistoricalData(true)
  809. .create();
  810. public static final String NEW_MAJOR_VIOLATIONS_KEY = "new_major_violations";
  811. public static final Metric<Integer> NEW_MAJOR_VIOLATIONS = new Metric.Builder(NEW_MAJOR_VIOLATIONS_KEY, "New Major Issues", Metric.ValueType.INT)
  812. .setDescription("New Major issues")
  813. .setDirection(Metric.DIRECTION_WORST)
  814. .setQualitative(true)
  815. .setDomain(DOMAIN_ISSUES)
  816. .setBestValue(0.0)
  817. .setOptimizedBestValue(true)
  818. .setDeleteHistoricalData(true)
  819. .create();
  820. public static final String NEW_MINOR_VIOLATIONS_KEY = "new_minor_violations";
  821. public static final Metric<Integer> NEW_MINOR_VIOLATIONS = new Metric.Builder(NEW_MINOR_VIOLATIONS_KEY, "New Minor Issues", Metric.ValueType.INT)
  822. .setDescription("New Minor issues")
  823. .setDirection(Metric.DIRECTION_WORST)
  824. .setQualitative(true)
  825. .setDomain(DOMAIN_ISSUES)
  826. .setBestValue(0.0)
  827. .setOptimizedBestValue(true)
  828. .setDeleteHistoricalData(true)
  829. .create();
  830. public static final String NEW_INFO_VIOLATIONS_KEY = "new_info_violations";
  831. public static final Metric<Integer> NEW_INFO_VIOLATIONS = new Metric.Builder(NEW_INFO_VIOLATIONS_KEY, "New Info Issues", Metric.ValueType.INT)
  832. .setDescription("New Info issues")
  833. .setDirection(Metric.DIRECTION_WORST)
  834. .setQualitative(true)
  835. .setDomain(DOMAIN_ISSUES)
  836. .setBestValue(0.0)
  837. .setOptimizedBestValue(true)
  838. .setDeleteHistoricalData(true)
  839. .create();
  840. /**
  841. * @since 3.6
  842. */
  843. public static final String FALSE_POSITIVE_ISSUES_KEY = "false_positive_issues";
  844. /**
  845. * @since 3.6
  846. */
  847. public static final Metric<Integer> FALSE_POSITIVE_ISSUES = new Metric.Builder(FALSE_POSITIVE_ISSUES_KEY, "False Positive Issues", Metric.ValueType.INT)
  848. .setDescription("False positive issues")
  849. .setDirection(Metric.DIRECTION_WORST)
  850. .setDomain(DOMAIN_ISSUES)
  851. .setBestValue(0.0)
  852. .setOptimizedBestValue(true)
  853. .create();
  854. /**
  855. * @since 5.6
  856. */
  857. public static final String WONT_FIX_ISSUES_KEY = "wont_fix_issues";
  858. /**
  859. * @since 5.6
  860. */
  861. public static final Metric<Integer> WONT_FIX_ISSUES = new Metric.Builder(WONT_FIX_ISSUES_KEY, "Won't Fix Issues", Metric.ValueType.INT)
  862. .setDescription("Won't fix issues")
  863. .setDirection(Metric.DIRECTION_WORST)
  864. .setDomain(DOMAIN_ISSUES)
  865. .setBestValue(0.0)
  866. .setOptimizedBestValue(true)
  867. .create();
  868. /**
  869. * @since 3.6
  870. */
  871. public static final String OPEN_ISSUES_KEY = "open_issues";
  872. /**
  873. * @since 3.6
  874. */
  875. public static final Metric<Integer> OPEN_ISSUES = new Metric.Builder(OPEN_ISSUES_KEY, "Open Issues", Metric.ValueType.INT)
  876. .setDescription("Open issues")
  877. .setDirection(Metric.DIRECTION_WORST)
  878. .setDomain(DOMAIN_ISSUES)
  879. .setBestValue(0.0)
  880. .setOptimizedBestValue(true)
  881. .create();
  882. /**
  883. * @since 3.6
  884. */
  885. public static final String REOPENED_ISSUES_KEY = "reopened_issues";
  886. /**
  887. * @since 3.6
  888. */
  889. public static final Metric<Integer> REOPENED_ISSUES = new Metric.Builder(REOPENED_ISSUES_KEY, "Reopened Issues", Metric.ValueType.INT)
  890. .setDescription("Reopened issues")
  891. .setDirection(Metric.DIRECTION_WORST)
  892. .setQualitative(true)
  893. .setDomain(DOMAIN_ISSUES)
  894. .setBestValue(0.0)
  895. .setOptimizedBestValue(true)
  896. .create();
  897. /**
  898. * @since 3.6
  899. */
  900. public static final String CONFIRMED_ISSUES_KEY = "confirmed_issues";
  901. /**
  902. * @since 3.6
  903. */
  904. public static final Metric<Integer> CONFIRMED_ISSUES = new Metric.Builder(CONFIRMED_ISSUES_KEY, "Confirmed Issues", Metric.ValueType.INT)
  905. .setDescription("Confirmed issues")
  906. .setDirection(Metric.DIRECTION_WORST)
  907. .setQualitative(true)
  908. .setDomain(DOMAIN_ISSUES)
  909. .setBestValue(0.0)
  910. .setOptimizedBestValue(true)
  911. .create();
  912. /**
  913. * SonarQube Quality Model
  914. *
  915. * @since 5.5
  916. */
  917. public static final String CODE_SMELLS_KEY = "code_smells";
  918. /**
  919. * SonarQube Quality Model
  920. *
  921. * @since 5.5
  922. */
  923. public static final Metric<Integer> CODE_SMELLS = new Metric.Builder(CODE_SMELLS_KEY, "Code Smells", Metric.ValueType.INT)
  924. .setDescription("Code Smells")
  925. .setDirection(Metric.DIRECTION_WORST)
  926. .setQualitative(false)
  927. .setDomain(DOMAIN_MAINTAINABILITY)
  928. .setBestValue(0.0)
  929. .setOptimizedBestValue(true)
  930. .create();
  931. /**
  932. * SonarQube Quality Model
  933. *
  934. * @since 5.5
  935. */
  936. public static final String NEW_CODE_SMELLS_KEY = "new_code_smells";
  937. /**
  938. * SonarQube Quality Model
  939. *
  940. * @since 5.5
  941. */
  942. public static final Metric<Integer> NEW_CODE_SMELLS = new Metric.Builder(NEW_CODE_SMELLS_KEY, "New Code Smells", Metric.ValueType.INT)
  943. .setDescription("New Code Smells")
  944. .setDirection(Metric.DIRECTION_WORST)
  945. .setQualitative(true)
  946. .setDomain(DOMAIN_MAINTAINABILITY)
  947. .setBestValue(0.0)
  948. .setOptimizedBestValue(true)
  949. .setDeleteHistoricalData(true)
  950. .create();
  951. /**
  952. * SonarQube Quality Model
  953. *
  954. * @since 5.5
  955. */
  956. public static final String BUGS_KEY = "bugs";
  957. /**
  958. * SonarQube Quality Model
  959. *
  960. * @since 5.5
  961. */
  962. public static final Metric<Integer> BUGS = new Metric.Builder(BUGS_KEY, "Bugs", Metric.ValueType.INT)
  963. .setDescription("Bugs")
  964. .setDirection(Metric.DIRECTION_WORST)
  965. .setQualitative(false)
  966. .setDomain(DOMAIN_RELIABILITY)
  967. .setBestValue(0.0)
  968. .setOptimizedBestValue(true)
  969. .create();
  970. /**
  971. * SonarQube Quality Model
  972. *
  973. * @since 5.5
  974. */
  975. public static final String NEW_BUGS_KEY = "new_bugs";
  976. /**
  977. * SonarQube Quality Model
  978. *
  979. * @since 5.5
  980. */
  981. public static final Metric<Integer> NEW_BUGS = new Metric.Builder(NEW_BUGS_KEY, "New Bugs", Metric.ValueType.INT)
  982. .setDescription("New Bugs")
  983. .setDirection(Metric.DIRECTION_WORST)
  984. .setQualitative(true)
  985. .setDomain(DOMAIN_RELIABILITY)
  986. .setBestValue(0.0)
  987. .setOptimizedBestValue(true)
  988. .setDeleteHistoricalData(true)
  989. .create();
  990. /**
  991. * SonarQube Quality Model
  992. *
  993. * @since 5.5
  994. */
  995. public static final String VULNERABILITIES_KEY = "vulnerabilities";
  996. /**
  997. * SonarQube Quality Model
  998. *
  999. * @since 5.5
  1000. */
  1001. public static final Metric<Integer> VULNERABILITIES = new Metric.Builder(VULNERABILITIES_KEY, "Vulnerabilities", Metric.ValueType.INT)
  1002. .setDescription("Vulnerabilities")
  1003. .setDirection(Metric.DIRECTION_WORST)
  1004. .setQualitative(false)
  1005. .setDomain(DOMAIN_SECURITY)
  1006. .setBestValue(0.0)
  1007. .setOptimizedBestValue(true)
  1008. .create();
  1009. /**
  1010. * SonarQube Quality Model
  1011. *
  1012. * @since 5.5
  1013. */
  1014. public static final String NEW_VULNERABILITIES_KEY = "new_vulnerabilities";
  1015. /**
  1016. * SonarQube Quality Model
  1017. *
  1018. * @since 5.5
  1019. */
  1020. public static final Metric<Integer> NEW_VULNERABILITIES = new Metric.Builder(NEW_VULNERABILITIES_KEY, "New Vulnerabilities", Metric.ValueType.INT)
  1021. .setDescription("New Vulnerabilities")
  1022. .setDirection(Metric.DIRECTION_WORST)
  1023. .setQualitative(true)
  1024. .setDomain(DOMAIN_SECURITY)
  1025. .setBestValue(0.0)
  1026. .setOptimizedBestValue(true)
  1027. .setDeleteHistoricalData(true)
  1028. .create();
  1029. /**
  1030. * @since 7.8
  1031. */
  1032. public static final String SECURITY_HOTSPOTS_KEY = "security_hotspots";
  1033. /**
  1034. * @since 7.8
  1035. */
  1036. public static final Metric<Integer> SECURITY_HOTSPOTS = new Metric.Builder(SECURITY_HOTSPOTS_KEY, "Security Hotspots", Metric.ValueType.INT)
  1037. .setDescription("Security Hotspots")
  1038. .setDirection(Metric.DIRECTION_WORST)
  1039. .setQualitative(false)
  1040. .setDomain(DOMAIN_SECURITY_REVIEW)
  1041. .setBestValue(0.0)
  1042. .setOptimizedBestValue(true)
  1043. .create();
  1044. /**
  1045. * @since 7.8
  1046. */
  1047. public static final String NEW_SECURITY_HOTSPOTS_KEY = "new_security_hotspots";
  1048. /**
  1049. * @since 7.8
  1050. */
  1051. public static final Metric<Integer> NEW_SECURITY_HOTSPOTS = new Metric.Builder(NEW_SECURITY_HOTSPOTS_KEY, "New Security Hotspots", Metric.ValueType.INT)
  1052. .setDescription("New Security Hotspots")
  1053. .setDirection(Metric.DIRECTION_WORST)
  1054. .setQualitative(true)
  1055. .setDomain(DOMAIN_SECURITY_REVIEW)
  1056. .setBestValue(0.0)
  1057. .setOptimizedBestValue(true)
  1058. .setDeleteHistoricalData(true)
  1059. .create();
  1060. // --------------------------------------------------------------------------------------------------------------------
  1061. //
  1062. // MAINTAINABILITY CHARACTERISTIC
  1063. //
  1064. // --------------------------------------------------------------------------------------------------------------------
  1065. /**
  1066. * @since 4.0
  1067. */
  1068. // TODO should be renamed to MAINTAINABILITY_REMEDIATION_EFFORT_KEY = "maintainability_remediation_effort"
  1069. public static final String TECHNICAL_DEBT_KEY = "sqale_index";
  1070. /**
  1071. * @since 4.0
  1072. */
  1073. // TODO should be renamed to MAINTAINABILITY_REMEDIATION_EFFORT
  1074. public static final Metric<Long> TECHNICAL_DEBT = new Metric.Builder(TECHNICAL_DEBT_KEY, "Technical Debt", Metric.ValueType.WORK_DUR)
  1075. .setDescription("Total effort (in hours) to fix all the issues on the component and therefore to comply to all the requirements.")
  1076. .setDomain(DOMAIN_MAINTAINABILITY)
  1077. .setDirection(Metric.DIRECTION_WORST)
  1078. .setOptimizedBestValue(true)
  1079. .setBestValue(0.0)
  1080. .setQualitative(true)
  1081. .create();
  1082. /**
  1083. * @since 4.1
  1084. */
  1085. // TODO should be renamed to NEW_MAINTAINABILITY_REMEDIATION_EFFORT_KEY = "new_maintainability_remediation_effort"
  1086. public static final String NEW_TECHNICAL_DEBT_KEY = "new_technical_debt";
  1087. /**
  1088. * @since 4.1
  1089. */
  1090. // TODO should be renamed to NEW_MAINTAINABILITY_REMEDIATION_EFFORT
  1091. public static final Metric<Long> NEW_TECHNICAL_DEBT = new Metric.Builder(NEW_TECHNICAL_DEBT_KEY, "Added Technical Debt", Metric.ValueType.WORK_DUR)
  1092. .setDescription("Added technical debt")
  1093. .setDomain(DOMAIN_MAINTAINABILITY)
  1094. .setDirection(Metric.DIRECTION_WORST)
  1095. .setOptimizedBestValue(true)
  1096. .setBestValue(0.0)
  1097. .setQualitative(true)
  1098. .setDeleteHistoricalData(true)
  1099. .create();
  1100. /**
  1101. * @since 4.5
  1102. */
  1103. // TODO should be renamed to MAINTAINABILITY_RATING_KEY = "maintainability_rating"
  1104. public static final String SQALE_RATING_KEY = "sqale_rating";
  1105. /**
  1106. * @since 4.5
  1107. */
  1108. // TODO should be renamed to MAINTAINABILITY_RATING
  1109. public static final Metric<Integer> SQALE_RATING = new Metric.Builder(SQALE_RATING_KEY, "Maintainability Rating", Metric.ValueType.RATING)
  1110. .setDescription("A-to-E rating based on the technical debt ratio")
  1111. .setDomain(DOMAIN_MAINTAINABILITY)
  1112. .setDirection(Metric.DIRECTION_WORST)
  1113. .setQualitative(true)
  1114. .setBestValue(1.0)
  1115. .setWorstValue(5.0)
  1116. .create();
  1117. /**
  1118. * @since 6.2
  1119. */
  1120. public static final String NEW_MAINTAINABILITY_RATING_KEY = "new_maintainability_rating";
  1121. /**
  1122. * @since 6.2
  1123. */
  1124. public static final Metric<Integer> NEW_MAINTAINABILITY_RATING = new Metric.Builder(NEW_MAINTAINABILITY_RATING_KEY, "Maintainability Rating on New Code", Metric.ValueType.RATING)
  1125. .setDescription("Maintainability rating on new code")
  1126. .setDomain(DOMAIN_MAINTAINABILITY)
  1127. .setDirection(Metric.DIRECTION_WORST)
  1128. .setDeleteHistoricalData(true)
  1129. .setOptimizedBestValue(true)
  1130. .setQualitative(true)
  1131. .setBestValue(1.0)
  1132. .setWorstValue(5.0)
  1133. .create();
  1134. /**
  1135. * @since 4.5
  1136. */
  1137. public static final String DEVELOPMENT_COST_KEY = "development_cost";
  1138. /**
  1139. * @since 4.5
  1140. */
  1141. public static final Metric<String> DEVELOPMENT_COST = new Metric.Builder(DEVELOPMENT_COST_KEY, "Development Cost", Metric.ValueType.STRING)
  1142. .setDescription("Development cost")
  1143. .setDomain(DOMAIN_MAINTAINABILITY)
  1144. .setDirection(Metric.DIRECTION_WORST)
  1145. .setOptimizedBestValue(true)
  1146. .setBestValue(0.0)
  1147. .setQualitative(true)
  1148. .setHidden(true)
  1149. .create();
  1150. /**
  1151. * @since 7.0
  1152. */
  1153. public static final String NEW_DEVELOPMENT_COST_KEY = "new_development_cost";
  1154. /**
  1155. * @since 7.0
  1156. */
  1157. public static final Metric<String> NEW_DEVELOPMENT_COST = new Metric.Builder(NEW_DEVELOPMENT_COST_KEY, "Development Cost on New Code", Metric.ValueType.FLOAT)
  1158. .setDescription("Development cost on new code")
  1159. .setDomain(DOMAIN_MAINTAINABILITY)
  1160. .setDirection(Metric.DIRECTION_WORST)
  1161. .setOptimizedBestValue(true)
  1162. .setBestValue(0.0)
  1163. .setQualitative(true)
  1164. .setHidden(true)
  1165. .create();
  1166. /**
  1167. * @since 4.5
  1168. */
  1169. // TODO should be renamed to TECHNICALDEBT_RATIO_KEY = "technicaldebt_ratio"
  1170. public static final String SQALE_DEBT_RATIO_KEY = "sqale_debt_ratio";
  1171. /**
  1172. * @since 4.5
  1173. */
  1174. // TODO should be renamed to TECHNICALDEBT_RATIO
  1175. public static final Metric<Double> SQALE_DEBT_RATIO = new Metric.Builder(SQALE_DEBT_RATIO_KEY, "Technical Debt Ratio", Metric.ValueType.PERCENT)
  1176. .setDescription("Ratio of the actual technical debt compared to the estimated cost to develop the whole source code from scratch")
  1177. .setDomain(DOMAIN_MAINTAINABILITY)
  1178. .setDirection(Metric.DIRECTION_WORST)
  1179. .setOptimizedBestValue(true)
  1180. .setBestValue(0.0)
  1181. .setQualitative(true)
  1182. .create();
  1183. /**
  1184. * @since 5.2
  1185. */
  1186. // TODO should be renamed to TECHNICALDEBT_RATIO_ON_NEW_CODE_KEY = "technicaldebt_ratio_on_new_code"
  1187. public static final String NEW_SQALE_DEBT_RATIO_KEY = "new_sqale_debt_ratio";
  1188. /**
  1189. * @since 5.2
  1190. */
  1191. // TODO should be renamed to TECHNICALDEBT_RATIO_ON_NEW_CODE
  1192. public static final Metric<Double> NEW_SQALE_DEBT_RATIO = new Metric.Builder(NEW_SQALE_DEBT_RATIO_KEY, "Technical Debt Ratio on New Code", Metric.ValueType.PERCENT)
  1193. .setDescription("Technical Debt Ratio of new/changed code.")
  1194. .setDomain(DOMAIN_MAINTAINABILITY)
  1195. .setDirection(Metric.DIRECTION_WORST)
  1196. .setOptimizedBestValue(true)
  1197. .setBestValue(0.0)
  1198. .setQualitative(true)
  1199. .create();
  1200. /**
  1201. * @since 5.5
  1202. */
  1203. public static final String EFFORT_TO_REACH_MAINTAINABILITY_RATING_A_KEY = "effort_to_reach_maintainability_rating_a";
  1204. /**
  1205. * @since 5.5
  1206. */
  1207. public static final Metric<Long> EFFORT_TO_REACH_MAINTAINABILITY_RATING_A = new Metric.Builder(EFFORT_TO_REACH_MAINTAINABILITY_RATING_A_KEY,
  1208. "Effort to Reach Maintainability Rating A", Metric.ValueType.WORK_DUR)
  1209. .setDescription("Effort to reach maintainability rating A")
  1210. .setDomain(DOMAIN_MAINTAINABILITY)
  1211. .setDirection(Metric.DIRECTION_WORST)
  1212. .setQualitative(true)
  1213. .setBestValue(0.0)
  1214. .setOptimizedBestValue(true)
  1215. .create();
  1216. // --------------------------------------------------------------------------------------------------------------------
  1217. //
  1218. // RELIABILITY CHARACTERISTIC
  1219. //
  1220. // --------------------------------------------------------------------------------------------------------------------
  1221. /**
  1222. * @since 5.5
  1223. */
  1224. public static final String RELIABILITY_REMEDIATION_EFFORT_KEY = "reliability_remediation_effort";
  1225. /**
  1226. * @since 5.5
  1227. */
  1228. public static final Metric<Long> RELIABILITY_REMEDIATION_EFFORT = new Metric.Builder(RELIABILITY_REMEDIATION_EFFORT_KEY, "Reliability Remediation Effort",
  1229. Metric.ValueType.WORK_DUR)
  1230. .setDescription("Reliability Remediation Effort")
  1231. .setDomain(DOMAIN_RELIABILITY)
  1232. .setDirection(Metric.DIRECTION_WORST)
  1233. .setOptimizedBestValue(true)
  1234. .setBestValue(0.0)
  1235. .setQualitative(true)
  1236. .create();
  1237. /**
  1238. * @since 5.5
  1239. */
  1240. public static final String NEW_RELIABILITY_REMEDIATION_EFFORT_KEY = "new_reliability_remediation_effort";
  1241. /**
  1242. * @since 5.5
  1243. */
  1244. public static final Metric<Long> NEW_RELIABILITY_REMEDIATION_EFFORT = new Metric.Builder(NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, "Reliability Remediation Effort on New Code",
  1245. Metric.ValueType.WORK_DUR)
  1246. .setDescription("Reliability remediation effort on new code")
  1247. .setDomain(DOMAIN_RELIABILITY)
  1248. .setDirection(Metric.DIRECTION_WORST)
  1249. .setOptimizedBestValue(true)
  1250. .setBestValue(0.0)
  1251. .setQualitative(true)
  1252. .setDeleteHistoricalData(true)
  1253. .create();
  1254. /**
  1255. * @since 5.5
  1256. */
  1257. public static final String RELIABILITY_RATING_KEY = "reliability_rating";
  1258. /**
  1259. * @since 5.5
  1260. */
  1261. public static final Metric<Integer> RELIABILITY_RATING = new Metric.Builder(RELIABILITY_RATING_KEY, "Reliability Rating", Metric.ValueType.RATING)
  1262. .setDescription("Reliability rating")
  1263. .setDomain(DOMAIN_RELIABILITY)
  1264. .setDirection(Metric.DIRECTION_WORST)
  1265. .setQualitative(true)
  1266. .setBestValue(1.0)
  1267. .setWorstValue(5.0)
  1268. .create();
  1269. /**
  1270. * @since 6.2
  1271. */
  1272. public static final String NEW_RELIABILITY_RATING_KEY = "new_reliability_rating";
  1273. /**
  1274. * @since 6.2
  1275. */
  1276. public static final Metric<Integer> NEW_RELIABILITY_RATING = new Metric.Builder(NEW_RELIABILITY_RATING_KEY, "Reliability Rating on New Code", Metric.ValueType.RATING)
  1277. .setDescription("Reliability rating on new code")
  1278. .setDomain(DOMAIN_RELIABILITY)
  1279. .setDirection(Metric.DIRECTION_WORST)
  1280. .setDeleteHistoricalData(true)
  1281. .setOptimizedBestValue(true)
  1282. .setQualitative(true)
  1283. .setBestValue(1.0)
  1284. .setWorstValue(5.0)
  1285. .create();
  1286. // --------------------------------------------------------------------------------------------------------------------
  1287. //
  1288. // SECURITY CHARACTERISTIC
  1289. //
  1290. // --------------------------------------------------------------------------------------------------------------------
  1291. /**
  1292. * @since 5.5
  1293. */
  1294. public static final String SECURITY_REMEDIATION_EFFORT_KEY = "security_remediation_effort";
  1295. /**
  1296. * @since 5.5
  1297. */
  1298. public static final Metric<Long> SECURITY_REMEDIATION_EFFORT = new Metric.Builder(SECURITY_REMEDIATION_EFFORT_KEY, "Security Remediation Effort", Metric.ValueType.WORK_DUR)
  1299. .setDescription("Security remediation effort")
  1300. .setDomain(DOMAIN_SECURITY)
  1301. .setDirection(Metric.DIRECTION_WORST)
  1302. .setOptimizedBestValue(true)
  1303. .setBestValue(0.0)
  1304. .setQualitative(true)
  1305. .create();
  1306. /**
  1307. * @since 5.5
  1308. */
  1309. public static final String NEW_SECURITY_REMEDIATION_EFFORT_KEY = "new_security_remediation_effort";
  1310. /**
  1311. * @since 5.5
  1312. */
  1313. public static final Metric<Long> NEW_SECURITY_REMEDIATION_EFFORT = new Metric.Builder(NEW_SECURITY_REMEDIATION_EFFORT_KEY, "Security Remediation Effort on New Code",
  1314. Metric.ValueType.WORK_DUR)
  1315. .setDescription("Security remediation effort on new code")
  1316. .setDomain(DOMAIN_SECURITY)
  1317. .setDirection(Metric.DIRECTION_WORST)
  1318. .setOptimizedBestValue(true)
  1319. .setBestValue(0.0)
  1320. .setQualitative(true)
  1321. .setDeleteHistoricalData(true)
  1322. .create();
  1323. /**
  1324. * @since 5.5
  1325. */
  1326. public static final String SECURITY_RATING_KEY = "security_rating";
  1327. /**
  1328. * @since 5.5
  1329. */
  1330. public static final Metric<Integer> SECURITY_RATING = new Metric.Builder(SECURITY_RATING_KEY, "Security Rating", Metric.ValueType.RATING)
  1331. .setDescription("Security rating")
  1332. .setDomain(DOMAIN_SECURITY)
  1333. .setDirection(Metric.DIRECTION_WORST)
  1334. .setQualitative(true)
  1335. .setBestValue(1.0)
  1336. .setWorstValue(5.0)
  1337. .create();
  1338. /**
  1339. * @since 6.2
  1340. */
  1341. public static final String NEW_SECURITY_RATING_KEY = "new_security_rating";
  1342. /**
  1343. * @since 6.2
  1344. */
  1345. public static final Metric<Integer> NEW_SECURITY_RATING = new Metric.Builder(NEW_SECURITY_RATING_KEY, "Security Rating on New Code", Metric.ValueType.RATING)
  1346. .setDescription("Security rating on new code")
  1347. .setDomain(DOMAIN_SECURITY)
  1348. .setDirection(Metric.DIRECTION_WORST)
  1349. .setDeleteHistoricalData(true)
  1350. .setOptimizedBestValue(true)
  1351. .setQualitative(true)
  1352. .setBestValue(1.0)
  1353. .setWorstValue(5.0)
  1354. .create();
  1355. // --------------------------------------------------------------------------------------------------------------------
  1356. //
  1357. // SECURITY REVIEW
  1358. //
  1359. // --------------------------------------------------------------------------------------------------------------------
  1360. /**
  1361. * @since 7.8
  1362. */
  1363. public static final String SECURITY_REVIEW_RATING_KEY = "security_review_rating";
  1364. /**
  1365. * @since 7.8
  1366. */
  1367. public static final Metric<Integer> SECURITY_REVIEW_RATING = new Metric.Builder(SECURITY_REVIEW_RATING_KEY, "Security Review Rating", Metric.ValueType.RATING)
  1368. .setDescription("Security Review Rating")
  1369. .setDomain(DOMAIN_SECURITY_REVIEW)
  1370. .setDirection(Metric.DIRECTION_WORST)
  1371. .setQualitative(true)
  1372. .setBestValue(1.0)
  1373. .setWorstValue(5.0)
  1374. .create();
  1375. /**
  1376. * @since 8.2
  1377. */
  1378. public static final String NEW_SECURITY_REVIEW_RATING_KEY = "new_security_review_rating";
  1379. /**
  1380. * @since 8.2
  1381. */
  1382. public static final Metric<Integer> NEW_SECURITY_REVIEW_RATING = new Metric.Builder(NEW_SECURITY_REVIEW_RATING_KEY, "Security Review Rating on New Code",
  1383. Metric.ValueType.RATING)
  1384. .setDescription("Security Review Rating on New Code")
  1385. .setDomain(DOMAIN_SECURITY_REVIEW)
  1386. .setDirection(Metric.DIRECTION_WORST)
  1387. .setDeleteHistoricalData(true)
  1388. .setOptimizedBestValue(true)
  1389. .setQualitative(true)
  1390. .setBestValue(1.0)
  1391. .setWorstValue(5.0)
  1392. .create();
  1393. /**
  1394. * @since 8.2
  1395. */
  1396. public static final String SECURITY_HOTSPOTS_REVIEWED_KEY = "security_hotspots_reviewed";
  1397. /**
  1398. * @since 8.2
  1399. */
  1400. public static final Metric<Integer> SECURITY_HOTSPOTS_REVIEWED = new Metric.Builder(SECURITY_HOTSPOTS_REVIEWED_KEY, "Security Hotspots Reviewed", Metric.ValueType.PERCENT)
  1401. .setDescription("Percentage of Security Hotspots Reviewed")
  1402. .setDomain(DOMAIN_SECURITY_REVIEW)
  1403. .setDirection(Metric.DIRECTION_BETTER)
  1404. .setQualitative(true)
  1405. .setWorstValue(0.0)
  1406. .setBestValue(100.0)
  1407. .create();
  1408. /**
  1409. * @since 8.2
  1410. */
  1411. public static final String NEW_SECURITY_HOTSPOTS_REVIEWED_KEY = "new_security_hotspots_reviewed";
  1412. /**
  1413. * @since 8.2
  1414. */
  1415. public static final Metric<Integer> NEW_SECURITY_HOTSPOTS_REVIEWED = new Metric.Builder(NEW_SECURITY_HOTSPOTS_REVIEWED_KEY, "Security Hotspots Reviewed on New Code",
  1416. Metric.ValueType.PERCENT)
  1417. .setDescription("Percentage of Security Hotspots Reviewed on New Code")
  1418. .setDomain(DOMAIN_SECURITY_REVIEW)
  1419. .setDirection(Metric.DIRECTION_BETTER)
  1420. .setDeleteHistoricalData(true)
  1421. .setQualitative(true)
  1422. .setWorstValue(0.0)
  1423. .setBestValue(100.0)
  1424. .create();
  1425. /**
  1426. * @since 8.2
  1427. */
  1428. public static final String SECURITY_HOTSPOTS_REVIEWED_STATUS_KEY = "security_hotspots_reviewed_status";
  1429. /**
  1430. * @since 8.2
  1431. *
  1432. * This hidden metric is only needed to compute 'security_review_rating' and 'security_hotspots_reviewed' on Applications.
  1433. */
  1434. public static final Metric<Integer> SECURITY_HOTSPOTS_REVIEWED_STATUS = new Metric.Builder(SECURITY_HOTSPOTS_REVIEWED_STATUS_KEY, "Security Review Reviewed Status",
  1435. Metric.ValueType.INT)
  1436. .setDescription("Security Review Reviewed Status")
  1437. .setDirection(Metric.DIRECTION_WORST)
  1438. .setQualitative(false)
  1439. .setDomain(DOMAIN_SECURITY_REVIEW)
  1440. .setBestValue(0.0)
  1441. .setOptimizedBestValue(true)
  1442. .setDeleteHistoricalData(true)
  1443. .setHidden(true)
  1444. .create();
  1445. /**
  1446. * @since 8.2
  1447. */
  1448. public static final String SECURITY_HOTSPOTS_TO_REVIEW_STATUS_KEY = "security_hotspots_to_review_status";
  1449. /**
  1450. * @since 8.2
  1451. *
  1452. * This hidden metric is only needed to compute 'security_review_rating' and 'security_hotspots_reviewed' on Applications.
  1453. */
  1454. public static final Metric<Integer> SECURITY_HOTSPOTS_TO_REVIEW_STATUS = new Metric.Builder(SECURITY_HOTSPOTS_TO_REVIEW_STATUS_KEY, "Security Review To Review Status",
  1455. Metric.ValueType.INT)
  1456. .setDescription("Security Review To Review Status")
  1457. .setDirection(Metric.DIRECTION_WORST)
  1458. .setQualitative(false)
  1459. .setDomain(DOMAIN_SECURITY_REVIEW)
  1460. .setBestValue(0.0)
  1461. .setOptimizedBestValue(true)
  1462. .setDeleteHistoricalData(true)
  1463. .setHidden(true)
  1464. .create();
  1465. /**
  1466. * @since 8.2
  1467. */
  1468. public static final String NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS_KEY = "new_security_hotspots_reviewed_status";
  1469. /**
  1470. * @since 8.2
  1471. *
  1472. * This hidden metric is only needed to compute 'new_security_review_rating' and 'new_security_hotspots_reviewed' on Applications.
  1473. */
  1474. public static final Metric<Integer> NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS = new Metric.Builder(NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS_KEY,
  1475. "Security Review Reviewed Status on New Code", Metric.ValueType.INT)
  1476. .setDescription("Security Review Reviewed Status on New Code")
  1477. .setDirection(Metric.DIRECTION_WORST)
  1478. .setQualitative(false)
  1479. .setDomain(DOMAIN_SECURITY_REVIEW)
  1480. .setBestValue(0.0)
  1481. .setOptimizedBestValue(true)
  1482. .setDeleteHistoricalData(true)
  1483. .setHidden(true)
  1484. .create();
  1485. /**
  1486. * @since 8.2
  1487. */
  1488. public static final String NEW_SECURITY_HOTSPOTS_TO_REVIEW_STATUS_KEY = "new_security_hotspots_to_review_status";
  1489. /**
  1490. * @since 8.2
  1491. *
  1492. * This hidden metric is only needed to compute 'new_security_review_rating' and 'new_security_hotspots_reviewed' on Applications.
  1493. */
  1494. public static final Metric<Integer> NEW_SECURITY_HOTSPOTS_TO_REVIEW_STATUS = new Metric.Builder(NEW_SECURITY_HOTSPOTS_TO_REVIEW_STATUS_KEY,
  1495. "Security Review To Review Status on New Code", Metric.ValueType.INT)
  1496. .setDescription("Security Review To Review Status on New Code")
  1497. .setDirection(Metric.DIRECTION_WORST)
  1498. .setQualitative(false)
  1499. .setDomain(DOMAIN_SECURITY_REVIEW)
  1500. .setBestValue(0.0)
  1501. .setOptimizedBestValue(true)
  1502. .setDeleteHistoricalData(true)
  1503. .setHidden(true)
  1504. .create();
  1505. // --------------------------------------------------------------------------------------------------------------------
  1506. //
  1507. // FILE DATA
  1508. //
  1509. // --------------------------------------------------------------------------------------------------------------------
  1510. /**
  1511. * @since 2.14
  1512. */
  1513. public static final String NCLOC_DATA_KEY = "ncloc_data";
  1514. /**
  1515. * Information about lines of code in file.
  1516. * Key-value pairs, where key - is a number of line, and value - is an indicator of whether line contains code (1) or not (0).
  1517. * If a line number is missing in the map it is equivalent to the default value (0).
  1518. *
  1519. * @see org.sonar.api.measures.FileLinesContext
  1520. * @since 2.14
  1521. */
  1522. public static final Metric<String> NCLOC_DATA = new Metric.Builder(NCLOC_DATA_KEY, "ncloc_data", Metric.ValueType.DATA)
  1523. .setHidden(true)
  1524. .setDomain(DOMAIN_SIZE)
  1525. .create();
  1526. /**
  1527. * @since 2.14
  1528. * @deprecated in 7.3. Measures are no longer sent within analysis reports, and by consequence no
  1529. * longer persisted nor available from web API.
  1530. */
  1531. @Deprecated
  1532. public static final String COMMENT_LINES_DATA_KEY = "comment_lines_data";
  1533. /**
  1534. * Information about comments in file.
  1535. * Key-value pairs, where key - is a number of line, and value - is an indicator of whether line contains comment (1) or not (0).
  1536. * If a line number is missing in the map it is equivalent to the default value (0).
  1537. *
  1538. * @see org.sonar.api.measures.FileLinesContext
  1539. * @since 2.14
  1540. * @deprecated in 7.3. Measures are no longer sent within analysis reports, and by consequence no
  1541. * longer persisted nor available from web API.
  1542. */
  1543. @Deprecated
  1544. public static final Metric<String> COMMENT_LINES_DATA = new Metric.Builder(COMMENT_LINES_DATA_KEY, "comment_lines_data", Metric.ValueType.DATA)
  1545. .setHidden(true)
  1546. .setDomain(DOMAIN_SIZE)
  1547. .create();
  1548. /**
  1549. * @since 5.5
  1550. */
  1551. public static final String EXECUTABLE_LINES_DATA_KEY = "executable_lines_data";
  1552. /**
  1553. * Information about executable lines of code in file.
  1554. * Key-value pairs, where key - is a number of line, and value - is an indicator of whether line contains executable code (1) or not (0).
  1555. * If a line number is missing in the map it is equivalent to the default value (0).
  1556. *
  1557. * @see org.sonar.api.measures.FileLinesContext
  1558. * @since 5.5
  1559. */
  1560. public static final Metric<String> EXECUTABLE_LINES_DATA = new Metric.Builder(EXECUTABLE_LINES_DATA_KEY, "executable_lines_data", Metric.ValueType.DATA)
  1561. .setHidden(true)
  1562. .setDomain(DOMAIN_COVERAGE)
  1563. .create();
  1564. // --------------------------------------------------------------------------------------------------------------------
  1565. //
  1566. // OTHERS
  1567. //
  1568. // --------------------------------------------------------------------------------------------------------------------
  1569. public static final String ALERT_STATUS_KEY = "alert_status";
  1570. public static final Metric<Metric.Level> ALERT_STATUS = new Metric.Builder(ALERT_STATUS_KEY, "Quality Gate Status", Metric.ValueType.LEVEL)
  1571. .setDescription("The project status with regard to its quality gate.")
  1572. .setDirection(Metric.DIRECTION_BETTER)
  1573. .setQualitative(true)
  1574. .setDomain(DOMAIN_RELEASABILITY)
  1575. .create();
  1576. /**
  1577. * @since 4.4
  1578. */
  1579. public static final String QUALITY_GATE_DETAILS_KEY = "quality_gate_details";
  1580. /**
  1581. * The project detailed status with regard to its quality gate.
  1582. * Storing the global quality gate status, along with all evaluated conditions, into a JSON object.
  1583. *
  1584. * @since 4.4
  1585. */
  1586. public static final Metric<String> QUALITY_GATE_DETAILS = new Metric.Builder(QUALITY_GATE_DETAILS_KEY, "Quality Gate Details", Metric.ValueType.DATA)
  1587. .setDescription("The project detailed status with regard to its quality gate")
  1588. .setDomain(DOMAIN_GENERAL)
  1589. .create();
  1590. /**
  1591. * @since 4.4
  1592. * @deprecated since 5.5
  1593. */
  1594. @Deprecated
  1595. public static final String QUALITY_PROFILES_KEY = "quality_profiles";
  1596. /**
  1597. * @since 4.4
  1598. * @deprecated since 5.5
  1599. */
  1600. @Deprecated
  1601. public static final Metric<String> QUALITY_PROFILES = new Metric.Builder(QUALITY_PROFILES_KEY, "Profiles", Metric.ValueType.DATA)
  1602. .setDescription("Details of quality profiles used during analysis")
  1603. .setQualitative(false)
  1604. .setDomain(DOMAIN_GENERAL)
  1605. .setHidden(true)
  1606. .create();
  1607. /**
  1608. * @since 5.2
  1609. */
  1610. public static final String LAST_COMMIT_DATE_KEY = "last_commit_date";
  1611. /**
  1612. * Date of the most recent commit. Current implementation is based on commits touching lines of source code. It
  1613. * ignores other changes like file renaming or file deletion.
  1614. *
  1615. * @since 5.2
  1616. */
  1617. public static final Metric LAST_COMMIT_DATE = new Metric.Builder(LAST_COMMIT_DATE_KEY, "Date of Last Commit", Metric.ValueType.MILLISEC)
  1618. .setDomain(CoreMetrics.DOMAIN_SCM)
  1619. // waiting for type "datetime" to be correctly handled
  1620. .setHidden(true)
  1621. .create();
  1622. private static final List<Metric> METRICS;
  1623. static {
  1624. METRICS = new LinkedList<>();
  1625. for (Field field : CoreMetrics.class.getFields()) {
  1626. if (!Modifier.isTransient(field.getModifiers()) && Metric.class.isAssignableFrom(field.getType())) {
  1627. try {
  1628. Metric metric = (Metric) field.get(null);
  1629. METRICS.add(metric);
  1630. } catch (IllegalAccessException e) {
  1631. throw new SonarException("can not introspect " + CoreMetrics.class + " to get metrics", e);
  1632. }
  1633. }
  1634. }
  1635. }
  1636. private CoreMetrics() {
  1637. // only static stuff
  1638. }
  1639. public static List<Metric> getMetrics() {
  1640. return METRICS;
  1641. }
  1642. public static Metric getMetric(final String key) {
  1643. return METRICS.stream().filter(metric -> metric != null && metric.getKey().equals(key)).findFirst().orElseThrow(NoSuchElementException::new);
  1644. }
  1645. }