]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6381 throw an exception when a compatible plugin is not found.
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 22 Jul 2015 10:03:14 +0000 (12:03 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 22 Jul 2015 10:08:13 +0000 (12:08 +0200)
server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java
server/sonar-server/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java

index a164ad7bc180f2769b270faae4178ded47037386..4b6d315b206e81f80bc19d11d5476fa9d98d74c2 100644 (file)
@@ -34,6 +34,7 @@ import org.sonar.api.utils.SonarException;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.core.platform.PluginInfo;
+import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.platform.DefaultServerFileSystem;
 import org.sonar.updatecenter.common.Release;
 import org.sonar.updatecenter.common.UpdateCenter;
@@ -123,7 +124,12 @@ public class PluginDownloader implements Startable {
   public void download(String pluginKey, Version version) {
     Optional<UpdateCenter> updateCenter = updateCenterMatrixFactory.getUpdateCenter(true);
     if (updateCenter.isPresent()) {
-      for (Release release : updateCenter.get().findInstallablePlugins(pluginKey, version)) {
+      List<Release> installablePlugins = updateCenter.get().findInstallablePlugins(pluginKey, version);
+      if (installablePlugins.isEmpty()) {
+        throw new BadRequestException(String.format("Error while downloading plugin '%s' with version '%s'. No compatible plugin found.", pluginKey,
+          version.getName()));
+      }
+      for (Release release : installablePlugins) {
         try {
           downloadRelease(release);
         } catch (Exception e) {
index 7f78fc6c5384a9037f3058a1ff788c7e26bccd46..cbca8d02c9ea768af2058125d4fdcf5a402f3d0c 100644 (file)
@@ -26,6 +26,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.ArgumentMatcher;
 import org.mockito.invocation.InvocationOnMock;
@@ -33,6 +34,7 @@ import org.mockito.stubbing.Answer;
 import org.sonar.api.utils.HttpDownloader;
 import org.sonar.api.utils.SonarException;
 import org.sonar.core.platform.PluginInfo;
+import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.platform.DefaultServerFileSystem;
 import org.sonar.updatecenter.common.Plugin;
 import org.sonar.updatecenter.common.Release;
@@ -60,6 +62,8 @@ public class PluginDownloaderTest {
 
   @Rule
   public TemporaryFolder testFolder = new TemporaryFolder();
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
   File downloadDir;
   UpdateCenterMatrixFactory updateCenterMatrixFactory;
   UpdateCenter updateCenter;
@@ -173,6 +177,13 @@ public class PluginDownloaderTest {
     }
   }
 
+  @Test
+  public void fail_if_no_compatible_plugin_found() {
+    expectedException.expect(BadRequestException.class);
+
+    pluginDownloader.download("foo", create("1.0"));
+  }
+
   @Test
   public void download_from_file() throws Exception {
     Plugin test = new Plugin("test");