Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ScmProvider.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.batch.scm;
  21. import java.io.File;
  22. import java.nio.file.Path;
  23. import java.time.Instant;
  24. import java.util.Map;
  25. import java.util.Set;
  26. import javax.annotation.CheckForNull;
  27. import org.sonar.api.CoreProperties;
  28. import org.sonar.api.ExtensionPoint;
  29. import org.sonar.api.scanner.ScannerSide;
  30. /**
  31. * @since 5.0
  32. */
  33. @ScannerSide
  34. @ExtensionPoint
  35. public abstract class ScmProvider {
  36. /**
  37. * Unique identifier of the provider. Can be passed to {@link CoreProperties#SCM_PROVIDER_KEY}
  38. * Can be used in SCM URL to define the provider to use.
  39. */
  40. public abstract String key();
  41. /**
  42. * Whether this provider is able to manage files located in this directory.
  43. * Used by autodetection. Not considered if user has forced the provider key.
  44. *
  45. * @return false by default
  46. */
  47. public boolean supports(File baseDir) {
  48. return false;
  49. }
  50. public BlameCommand blameCommand() {
  51. throw new UnsupportedOperationException(formatUnsupportedMessage("Blame command"));
  52. }
  53. /**
  54. * Return absolute path of the files changed in the current branch, compared to the provided target branch.
  55. *
  56. * @return null if the SCM provider was not able to compute the list of files.
  57. * @since 7.0
  58. */
  59. @CheckForNull
  60. public Set<Path> branchChangedFiles(String targetBranchName, Path rootBaseDir) {
  61. return null;
  62. }
  63. /**
  64. * Return a map between paths given as argument and the corresponding line numbers which are new compared to the provided target branch.
  65. * If nothing is returned for a file, the scanner will consider that the provider was unable to determine changes for that file and it will
  66. * assume that nothing was changed in it.
  67. * If null is returned, an imprecise fallback mechanism will be used to detect which lines are new (based on SCM dates).
  68. *
  69. * @param files Absolute path of files of interest
  70. * @return null if the SCM provider was not able to compute the new lines
  71. * @since 7.4
  72. */
  73. @CheckForNull
  74. public Map<Path, Set<Integer>> branchChangedLines(String targetBranchName, Path rootBaseDir, Set<Path> files) {
  75. return null;
  76. }
  77. /**
  78. * Find the date of the merge base between the current branch and the given reference branch.
  79. *
  80. * @return null if the SCM provider was not able to compute the date
  81. * @since 8.4
  82. * @deprecated Not used anymore since 9.3
  83. */
  84. @CheckForNull
  85. @Deprecated
  86. public Instant forkDate(String referenceBranchName, Path rootBaseDir) {
  87. return null;
  88. }
  89. /**
  90. * The relative path from SCM root
  91. * @since 7.0
  92. */
  93. public Path relativePathFromScmRoot(Path path) {
  94. throw new UnsupportedOperationException(formatUnsupportedMessage("Getting relative path from SCM root"));
  95. }
  96. /**
  97. * @since 7.7
  98. */
  99. public IgnoreCommand ignoreCommand() {
  100. throw new UnsupportedOperationException(formatUnsupportedMessage("Checking for ignored files"));
  101. }
  102. /**
  103. * The current revision id of the analyzed code,
  104. * for example the SHA1 of the current HEAD in a Git branch.
  105. * @since 7.0
  106. */
  107. @CheckForNull
  108. public String revisionId(Path path) {
  109. throw new UnsupportedOperationException(formatUnsupportedMessage("Getting revision id"));
  110. }
  111. private String formatUnsupportedMessage(String prefix) {
  112. return prefix + " is not supported by " + key() + " provider";
  113. }
  114. }