diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-07-22 12:03:14 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-07-22 12:08:13 +0200 |
commit | 7c321815ed5ae9f8748ad8cbf91f79090e695b16 (patch) | |
tree | ab8a5e7c28a04058d75769e942b030d364219c08 | |
parent | 255d7243980180740c6e4e276cc6413209921596 (diff) | |
download | sonarqube-7c321815ed5ae9f8748ad8cbf91f79090e695b16.tar.gz sonarqube-7c321815ed5ae9f8748ad8cbf91f79090e695b16.zip |
SONAR-6381 throw an exception when a compatible plugin is not found.
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java | 8 | ||||
-rw-r--r-- | server/sonar-server/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java | 11 |
2 files changed, 18 insertions, 1 deletions
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> 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) { 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; @@ -174,6 +178,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"); File file = testFolder.newFile("test-1.0.jar"); |