]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
SONARUNNER-144 Expose sonarqube version in API
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 13 Aug 2015 11:34:48 +0000 (13:34 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 13 Aug 2015 11:34:48 +0000 (13:34 +0200)
sonar-runner-api/src/main/java/org/sonar/runner/api/EmbeddedRunner.java
sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java
sonar-runner-batch/src/main/java/org/sonar/runner/batch/BatchIsolatedLauncher.java

index bebbf387d23372011a48f23c99183ea443ffd602..5c50fa92fdb7120782d1f0102eb144144a729a1d 100644 (file)
@@ -110,6 +110,7 @@ public class EmbeddedRunner {
   }
 
   public void runAnalysis(Properties analysisProperties, @Nullable IssueListener issueListener) {
+    checkLauncherExists();
     Properties copy = new Properties();
     copy.putAll(analysisProperties);
     initAnalysisProperties(copy);
@@ -125,6 +126,7 @@ public class EmbeddedRunner {
   }
 
   public void syncProject(String projectKey) {
+    checkLauncherExists();
     if (!VersionUtils.isAtLeast52(launcher.getVersion())) {
       throw new IllegalStateException("not supported in current SonarQube version: " + launcher.getVersion());
     }
@@ -141,8 +143,15 @@ public class EmbeddedRunner {
   }
 
   public void stop() {
+    checkLauncherExists();
     doStop();
   }
+  
+  public String serverVersion() {
+    checkLauncherExists();
+    return launcher.getVersion();
+  }
+  
 
   /**
    * @deprecated since 2.5 use {@link #start()}, {@link #runAnalysis(Properties)} and then {@link #stop()}
@@ -223,6 +232,12 @@ public class EmbeddedRunner {
       launcher.executeOldVersion(prop);
     }
   }
+  
+  private void checkLauncherExists() {
+    if(launcher == null) {
+      throw new IllegalStateException("not started");
+    }
+  }
 
   static class IssueListenerAdapter implements org.sonar.runner.batch.IssueListener {
     private IssueListener apiIssueListener;
index a1ffdcedd84f30c7c148a3882f32481849d91c86..9a6d6766953fb628c6f1ee832bdb96d9cd4aced2 100644 (file)
@@ -73,15 +73,29 @@ public class EmbeddedRunnerTest {
   }
 
   @Test
-  public void test_syncProject() {
+  public void test_sync_project() {
     String projectKey = "proj";
     runner.start();
     runner.syncProject(projectKey);
     verify(launcher).syncProject(projectKey);
   }
+  
+  @Test
+  public void test_server_version() {
+    runner.start();
+    assertThat(runner.serverVersion()).isEqualTo("5.2");
+  }
+  
+  @Test
+  public void test_run_before_start() {
+    expectedException.expect(IllegalStateException.class);
+    expectedException.expectMessage("started");
+    
+    runner.runAnalysis(new Properties());
+  }
 
   @Test
-  public void test_fail_projectSync_old_sq() {
+  public void test_fail_project_sync_old_sq() {
     when(launcher.getVersion()).thenReturn("5.0");
 
     expectedException.expect(IllegalStateException.class);
index 0d7be185ce74f914808440da2acdf0bd69f675bf..f941f3293c31fce9db12a356b50b04ee504ae1f8 100644 (file)
@@ -86,7 +86,7 @@ public class BatchIsolatedLauncher implements IsolatedLauncher {
   public void executeOldVersion(Properties properties) {
     createBatch(properties, null).execute();
   }
-
+  
   @Override
   public String getVersion() {
     InputStream is = this.getClass().getClassLoader().getResourceAsStream("sq-version.txt");