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.

DebtRemediationFunction.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.server.debt;
  21. import javax.annotation.CheckForNull;
  22. /**
  23. * Function used to calculate the remediation cost of an issue. See {@link Type} for details.
  24. * <p>The gap multiplier and base effort involved in the functions are durations. They are defined in hours, minutes and/or
  25. * seconds. Examples: "5min", "1h 10min". Supported units are "d" (days), "h" (hour), and "min" (minutes).
  26. *
  27. * @since 4.3
  28. */
  29. public interface DebtRemediationFunction {
  30. enum Type {
  31. /**
  32. * The cost to fix an issue of this type depends on the magnitude of the issue.
  33. * For instance, an issue related to file size might be linear, with the total cost-to-fix incrementing
  34. * (by the gap multiplier amount) for each line of code above the allowed threshold.
  35. * The rule must provide the "gap" value when raising an issue.
  36. */
  37. LINEAR(true, false),
  38. /**
  39. * It takes a certain amount of time to deal with an issue of this type (this is the gap multiplier).
  40. * Then, the magnitude of the issue comes in to play. For instance, an issue related to complexity might be linear with offset.
  41. * So the total cost to fix is the time to make the basic analysis (the base effort) plus the time required to deal
  42. * with each complexity point above the allowed value.
  43. * <p>
  44. * <code>Total remediation cost = base effort + (number of noncompliance x gap multiplier)</code>
  45. *
  46. * <p>The rule must provide the "gap" value when raising an issue. Let's take as a example the "Paragraphs should not be too complex" rule.
  47. * If you set the rule threshold to 20, and you have a paragraph with a complexity of 27, you have 7 points of complexity
  48. * to remove. Internally, this is called the Gap. In that case, if you use the LINEAR_OFFSET configuration
  49. * with an base effort of 4h and a remediation cost of 1mn, the effort for this issue related to a
  50. * too-complex block of code will be: (7 complexity points x 1min) + 4h = 4h and 7mn
  51. *
  52. */
  53. LINEAR_OFFSET(true, true),
  54. /**
  55. * The cost to fix all the issues of the rule is the same whatever the number of issues
  56. * of this rule in the file. Total remediation cost by file = constant
  57. */
  58. CONSTANT_ISSUE(false, true);
  59. private final boolean usesGapMultiplier;
  60. private final boolean usesBaseEffort;
  61. Type(boolean usesGapMultiplier, boolean usesBaseEffort) {
  62. this.usesGapMultiplier = usesGapMultiplier;
  63. this.usesBaseEffort = usesBaseEffort;
  64. }
  65. /**
  66. * @since 5.5
  67. */
  68. public boolean usesGapMultiplier() {
  69. return usesGapMultiplier;
  70. }
  71. /**
  72. * @since 5.5
  73. */
  74. public boolean usesBaseEffort() {
  75. return usesBaseEffort;
  76. }
  77. }
  78. /**
  79. * @since 5.5
  80. */
  81. Type type();
  82. /**
  83. * Non-null value on {@link Type#LINEAR} and {@link Type#LINEAR_OFFSET} functions, else {@code null}.
  84. *
  85. * @since 5.5
  86. */
  87. @CheckForNull
  88. String gapMultiplier();
  89. /**
  90. * Non-null value on {@link Type#LINEAR_OFFSET} and {@link Type#CONSTANT_ISSUE} functions, else {@code null}.
  91. *
  92. * @since 5.5
  93. */
  94. @CheckForNull
  95. String baseEffort();
  96. }