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.

PostProjectAnalysisTask.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.ce.posttask;
  21. import java.util.Optional;
  22. import javax.annotation.CheckForNull;
  23. import org.sonar.api.ExtensionPoint;
  24. import org.sonar.api.ce.ComputeEngineSide;
  25. /**
  26. * Extension point of which any plugin can provide an implementation and will allow them to be notified whenever some
  27. * analysis report processing ends in the Compute Engine.
  28. *
  29. * <p>
  30. * If more then one implementation of {@link PostProjectAnalysisTask} is found, they will be executed in no specific order.
  31. *
  32. * <p>
  33. * Class {@link PostProjectAnalysisTaskTester} is provided to write unit tests of implementations of this interface.
  34. *
  35. * @since 5.5
  36. * @see PostProjectAnalysisTaskTester
  37. */
  38. @ExtensionPoint
  39. @ComputeEngineSide
  40. public interface PostProjectAnalysisTask {
  41. /**
  42. * A short description or name for the task.
  43. * <p>
  44. * This will be used (but not limited to) in logs reporting the execution of the task.
  45. * @since 8.0
  46. */
  47. default String getDescription() {
  48. return this.getClass().getSimpleName();
  49. }
  50. /**
  51. * This method is called whenever the processing of a Project analysis has finished, whether successfully or not.
  52. *
  53. * @deprecated in 8.0. Implement {@link #finished(Context)} instead
  54. */
  55. @Deprecated
  56. default void finished(ProjectAnalysis analysis) {
  57. throw new IllegalStateException("Provide an implementation of method finished(Context)");
  58. }
  59. /**
  60. * @since 8.0
  61. */
  62. default void finished(Context context) {
  63. finished(context.getProjectAnalysis());
  64. }
  65. interface Context {
  66. ProjectAnalysis getProjectAnalysis();
  67. LogStatistics getLogStatistics();
  68. }
  69. /**
  70. * Each key-value paar will be added to the log describing the end of the
  71. */
  72. interface LogStatistics {
  73. /**
  74. * @return this
  75. * @throws NullPointerException if key or value is null
  76. * @throws IllegalArgumentException if key has already been set
  77. * @throws IllegalArgumentException if key is "status", to avoid conflict with field with same name added by the executor
  78. * @throws IllegalArgumentException if key is "time", to avoid conflict with the profiler field with same name
  79. */
  80. LogStatistics add(String key, Object value);
  81. }
  82. /**
  83. * @since 5.5
  84. */
  85. interface ProjectAnalysis {
  86. /**
  87. * When organizations are enabled in SonarQube, the organization the project belongs to.
  88. *
  89. * @since 7.0
  90. * @return a non empty value when organizations are enabled, otherwise empty
  91. */
  92. Optional<Organization> getOrganization();
  93. /**
  94. * Details of the Compute Engine task in which the project analysis was run.
  95. */
  96. CeTask getCeTask();
  97. /**
  98. * Details of the analyzed project.
  99. */
  100. Project getProject();
  101. /**
  102. * The branch that is being analyzed.
  103. *
  104. * @since 6.6
  105. */
  106. Optional<Branch> getBranch();
  107. /**
  108. * Status and details of the Quality Gate of the project (if any was configured on the project).
  109. */
  110. @CheckForNull
  111. QualityGate getQualityGate();
  112. /**
  113. * Analysis containing the UUID of the analysis and the date
  114. *
  115. * <p>
  116. * This Analysis can be missing when the status of the task is
  117. * {@link org.sonar.api.ce.posttask.CeTask.Status#FAILED FAILED}.
  118. * </p>
  119. */
  120. Optional<Analysis> getAnalysis();
  121. /**
  122. * Context as defined by scanner through {@link org.sonar.api.batch.sensor.SensorContext#addContextProperty(String, String)}.
  123. * It does not contain the settings used by scanner.
  124. *
  125. * @since 6.1
  126. */
  127. ScannerContext getScannerContext();
  128. /**
  129. * Revision Id that has been analysed. May return null.
  130. * @since 7.6
  131. * @deprecated in 7.8, replaced by {@code Analysis#getRevision()}
  132. * @see #getAnalysis()
  133. */
  134. @Deprecated
  135. String getScmRevisionId();
  136. }
  137. }