diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2017-12-07 11:38:28 +0100 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2017-12-07 15:40:03 +0100 |
commit | 0001182a007e70261d447023f1fa5ad5e1a0b69f (patch) | |
tree | eaae3a5bb2cf5f54a68ca42ac744494d0ead5908 /sonar-scanner-engine | |
parent | 204f88df32a21b401b4bff3190ee0e3cfb7628a3 (diff) | |
download | sonarqube-0001182a007e70261d447023f1fa5ad5e1a0b69f.tar.gz sonarqube-0001182a007e70261d447023f1fa5ad5e1a0b69f.zip |
SONAR-10142 Download compressed plugins
Diffstat (limited to 'sonar-scanner-engine')
2 files changed, 28 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java index 046acc54cd0..690cd70af97 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java @@ -29,6 +29,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.annotation.Nullable; import org.apache.commons.io.FileUtils; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -92,7 +93,11 @@ public class ScannerPluginInstaller implements PluginInstaller { @VisibleForTesting File download(final InstalledPlugin remote) { try { - return fileCache.get(remote.filename, remote.hash, new FileDownloader(remote.key)); + if (remote.compressedFilename != null) { + return fileCache.getCompressed(remote.compressedFilename, remote.compressedHash, new FileDownloader(remote.key)); + } else { + return fileCache.get(remote.filename, remote.hash, new FileDownloader(remote.key)); + } } catch (Exception e) { throw new IllegalStateException("Fail to download plugin: " + remote.key, e); } @@ -125,6 +130,10 @@ public class ScannerPluginInstaller implements PluginInstaller { String hash; String filename; long updatedAt; + @Nullable + String compressedHash; + @Nullable + String compressedFilename; } private class FileDownloader implements FileCache.Downloader { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest.java index 580ccd31c21..276fae19122 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest.java @@ -81,6 +81,24 @@ public class ScannerPluginInstallerTest { } @Test + public void should_download_compressed_plugin() throws Exception { + File pluginJar = temp.newFile(); + when(fileCache.getCompressed(eq("checkstyle-plugin.pack.gz"), eq("hash"), any(FileCache.Downloader.class))).thenReturn(pluginJar); + + ScannerPluginInstaller underTest = new ScannerPluginInstaller(wsClient, fileCache, pluginPredicate); + + InstalledPlugin remote = new InstalledPlugin(); + remote.key = "checkstyle"; + remote.filename = "checkstyle-plugin.jar"; + remote.hash = "fakemd5_1"; + remote.compressedFilename = "checkstyle-plugin.pack.gz"; + remote.compressedHash = "hash"; + File file = underTest.download(remote); + + assertThat(file).isEqualTo(pluginJar); + } + + @Test public void should_fail_to_get_plugin_index() { WsTestUtil.mockException(wsClient, "/api/plugins/installed", new IllegalStateException()); thrown.expect(IllegalStateException.class); |