aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanos Gyerik <janos.gyerik@sonarsource.com>2017-11-30 16:23:24 +0100
committerJanos Gyerik <janos.gyerik@sonarsource.com>2017-12-05 10:47:46 +0100
commit4621e7abe869caa475adcd4c16e81ea4eb4fb249 (patch)
treec5f2dc59fde94aa3dd1ac9ea966e463b3cf892a5
parentee34917caa43092fa45b51481035febb926f6738 (diff)
downloadsonarqube-4621e7abe869caa475adcd4c16e81ea4eb4fb249.tar.gz
sonarqube-4621e7abe869caa475adcd4c16e81ea4eb4fb249.zip
SONAR-10153 Add ScmProvider methods to get last revision and relative paths from SCM root
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java21
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/ScmProviderTest.java28
2 files changed, 40 insertions, 9 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java
index e73d05a06cd..052a9a766e3 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java
@@ -53,7 +53,7 @@ public abstract class ScmProvider {
}
public BlameCommand blameCommand() {
- throw new UnsupportedOperationException("Blame command is not supported by " + key() + " provider");
+ throw new UnsupportedOperationException(formatUnsupportedMessage("Blame command"));
}
/**
@@ -64,4 +64,23 @@ public abstract class ScmProvider {
public Set<Path> branchChangedFiles(String targetBranchName, Path rootBaseDir) {
return null;
}
+
+ /**
+ * The relative path from SCM root
+ */
+ public Path relativePathFromScmRoot(Path path) {
+ throw new UnsupportedOperationException(formatUnsupportedMessage("Getting relative path from SCM root"));
+ }
+
+ /**
+ * The current revision id of the analyzed code,
+ * for example the SHA1 of the current HEAD in a Git branch.
+ */
+ public String revisionId(Path path) {
+ throw new UnsupportedOperationException(formatUnsupportedMessage("Getting revision id"));
+ }
+
+ private String formatUnsupportedMessage(String prefix) {
+ return prefix + " is not supported by " + key() + " provider";
+ }
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/ScmProviderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/ScmProviderTest.java
index 8e2b2dd04c1..31e65ebe356 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/ScmProviderTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/ScmProviderTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.batch.scm;
+import java.nio.file.Paths;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -30,19 +31,30 @@ public class ScmProviderTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- @Test
- public void testDefaultImplementation() {
- ScmProvider provider = new ScmProvider() {
+ private final ScmProvider provider = new ScmProvider() {
- @Override
- public String key() {
- return "foo";
- }
- };
+ @Override
+ public String key() {
+ return "foo";
+ }
+ };
+ @Test
+ public void default_implementation_does_not_support_blame() {
assertThat(provider.supports(null)).isFalse();
thrown.expect(UnsupportedOperationException.class);
provider.blameCommand();
}
+ @Test
+ public void default_implementation_does_not_support_relativePathFromScmRoot() {
+ thrown.expect(UnsupportedOperationException.class);
+ provider.relativePathFromScmRoot(Paths.get("foo"));
+ }
+
+ @Test
+ public void default_implementation_does_not_support_revisionId() {
+ thrown.expect(UnsupportedOperationException.class);
+ provider.revisionId(Paths.get("foo"));
+ }
}