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.

ScmProvider.java 3.5KB

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