]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10153 Add ScmProvider methods to get last revision and relative paths from...
authorJanos Gyerik <janos.gyerik@sonarsource.com>
Thu, 30 Nov 2017 15:23:24 +0000 (16:23 +0100)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 5 Dec 2017 09:47:46 +0000 (10:47 +0100)
sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/ScmProviderTest.java

index e73d05a06cd4ef38bc09d58cab8c750c5eb3fd88..052a9a766e3c3845fc50e6e9672a23e74d3fe49c 100644 (file)
@@ -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";
+  }
 }
index 8e2b2dd04c1ec9f50e00b7e10af8286eb71923b9..31e65ebe3563fa031c823944aa04f757e99f9352 100644 (file)
@@ -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"));
+  }
 }