diff options
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java | 41 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java | 1 |
2 files changed, 20 insertions, 22 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java index 35db83b844a..3fd9c588b69 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java @@ -20,7 +20,6 @@ package org.sonar.batch.bootstrap; import org.sonar.batch.cache.WSLoaderResult; - import org.sonar.batch.cache.WSLoader; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; @@ -99,20 +98,7 @@ public class BatchPluginInstaller implements PluginInstaller { File download(final RemotePlugin remote) { try { final RemotePluginFile file = remote.file(); - return fileCache.get(file.getFilename(), file.getHash(), new FileCache.Downloader() { - @Override - public void download(String filename, File toFile) throws IOException { - String url = "/deploy/plugins/" + remote.getKey() + "/" + file.getFilename(); - if (LOG.isDebugEnabled()) { - LOG.debug("Download {} to {}", url, toFile.getAbsolutePath()); - } else { - LOG.info("Download {}", file.getFilename()); - } - - serverClient.download(url, toFile); - } - }); - + return fileCache.get(file.getFilename(), file.getHash(), new FileDownloader(remote.getKey())); } catch (Exception e) { throw new IllegalStateException("Fail to download plugin: " + remote.getKey(), e); } @@ -140,14 +126,27 @@ public class BatchPluginInstaller implements PluginInstaller { private String loadPluginIndex() { Profiler profiler = Profiler.create(LOG).startInfo("Load plugins index"); WSLoaderResult<String> wsResult = wsLoader.loadString(PLUGINS_INDEX_URL); + profiler.stopInfo(wsResult.isFromCache()); + return wsResult.get(); + } + + private class FileDownloader implements FileCache.Downloader { + private String key; - if (wsResult.isFromCache()) { - profiler.stopInfo("Load plugins index (done from cache)"); - } else { - profiler.stopInfo(); + FileDownloader(String key) { + this.key = key; } - return wsResult.get(); - } + @Override + public void download(String filename, File toFile) throws IOException { + String url = "/deploy/plugins/" + key + "/" + filename; + if (LOG.isDebugEnabled()) { + LOG.debug("Download {} to {}", url, toFile.getAbsolutePath()); + } else { + LOG.info("Download {}", filename); + } + serverClient.download(url, toFile); + } + } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java index c4f45c14b84..c663dbb3ef4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java @@ -55,7 +55,6 @@ public class BatchPluginInstallerTest { public void listRemotePlugins() { WSLoader wsLoader = mock(WSLoader.class); - when(wsLoader.load("/deploy/plugins/index.txt")).thenReturn(new WSLoaderResult<byte[]>("checkstyle\nsqale".getBytes(), true)); when(wsLoader.loadString("/deploy/plugins/index.txt")).thenReturn(new WSLoaderResult<String>("checkstyle\nsqale", true)); BatchPluginInstaller installer = new BatchPluginInstaller(wsLoader, serverClient, fileCache, pluginPredicate); |