From: Teryk Bellahsene Date: Wed, 22 Jul 2015 10:03:14 +0000 (+0200) Subject: SONAR-6381 throw an exception when a compatible plugin is not found. X-Git-Tag: 5.2-RC1~1039 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7c321815ed5ae9f8748ad8cbf91f79090e695b16;p=sonarqube.git SONAR-6381 throw an exception when a compatible plugin is not found. --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java index a164ad7bc18..4b6d315b206 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java @@ -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 = updateCenterMatrixFactory.getUpdateCenter(true); if (updateCenter.isPresent()) { - for (Release release : updateCenter.get().findInstallablePlugins(pluginKey, version)) { + List 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) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java index 7f78fc6c538..cbca8d02c9e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java @@ -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");