From be698baf4b4519eb43b5494be23a04703a550c9a Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 21 Mar 2014 15:41:16 +0100 Subject: SONAR-5011 Allow to install two plugins sharing the same dependency --- .../org/sonar/server/plugins/PluginDownloader.java | 9 +++--- .../sonar/server/plugins/PluginDownloaderTest.java | 34 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 5 deletions(-) (limited to 'sonar-server') diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java b/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java index 71ea2d05e96..0263c928fcf 100644 --- a/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java @@ -49,7 +49,7 @@ public class PluginDownloader implements Startable { private final File downloadDir; public PluginDownloader(UpdateCenterMatrixFactory updateCenterMatrixFactory, HttpDownloader downloader, - DefaultServerFileSystem fileSystem) { + DefaultServerFileSystem fileSystem) { this.updateCenterMatrixFactory = updateCenterMatrixFactory; this.downloader = downloader; this.downloadDir = fileSystem.getDownloadedPluginsDir(); @@ -64,7 +64,7 @@ public class PluginDownloader implements Startable { public void start() { try { FileUtils.forceMkdir(downloadDir); - Collection tempFiles = FileUtils.listFiles(downloadDir, new String[]{TMP_SUFFIX}, false); + Collection tempFiles = FileUtils.listFiles(downloadDir, new String[] {TMP_SUFFIX}, false); for (File tempFile : tempFiles) { FileUtils.deleteQuietly(tempFile); } @@ -95,7 +95,7 @@ public class PluginDownloader implements Startable { public List getDownloads() { List names = new ArrayList(); - List files = (List) FileUtils.listFiles(downloadDir, new String[]{PLUGIN_EXTENSION}, false); + List files = (List) FileUtils.listFiles(downloadDir, new String[] {PLUGIN_EXTENSION}, false); for (File file : files) { names.add(file.getName()); } @@ -132,7 +132,8 @@ public class PluginDownloader implements Startable { File targetFile = new File(downloadDir, filename); File tempFile = new File(downloadDir, filename + "." + TMP_SUFFIX); downloader.download(uri, tempFile); - FileUtils.moveFile(tempFile, targetFile); + FileUtils.copyFile(tempFile, targetFile); + FileUtils.deleteQuietly(tempFile); } } } diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java index 16dbd269f4e..093d54c07d5 100644 --- a/sonar-server/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java +++ b/sonar-server/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java @@ -46,7 +46,12 @@ import static org.fest.assertions.Fail.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class PluginDownloaderTest { @@ -230,6 +235,33 @@ public class PluginDownloaderTest { assertThat(pluginDownloader.hasDownloads()).isFalse(); } + // SONAR-5011 + @Test + public void download_common_transitive_dependency() throws Exception { + Plugin test1 = new Plugin("test1"); + Release test1R = new Release(test1, "1.0").setDownloadUrl("http://server/test1-1.0.jar"); + test1.addRelease(test1R); + + Plugin test2 = new Plugin("test2"); + Release test2R = new Release(test2, "1.0").setDownloadUrl("http://server/test2-1.0.jar"); + test2.addRelease(test2R); + + Plugin testDep = new Plugin("testdep"); + Release testDepR = new Release(testDep, "1.0").setDownloadUrl("http://server/testdep-1.0.jar"); + testDep.addRelease(testDepR); + + when(updateCenter.findInstallablePlugins("test1", Version.create("1.0"))).thenReturn(newArrayList(test1R, testDepR)); + when(updateCenter.findInstallablePlugins("test2", Version.create("1.0"))).thenReturn(newArrayList(test2R, testDepR)); + + pluginDownloader.start(); + pluginDownloader.download("test1", Version.create("1.0")); + pluginDownloader.download("test2", Version.create("1.0")); + + assertThat(new File(downloadDir, "test1-1.0.jar")).exists(); + assertThat(new File(downloadDir, "test2-1.0.jar")).exists(); + assertThat(new File(downloadDir, "testdep-1.0.jar")).exists(); + } + class HasFileName extends ArgumentMatcher { private final String name; -- cgit v1.2.3