diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-03-21 15:41:16 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-03-21 15:41:16 +0100 |
commit | be698baf4b4519eb43b5494be23a04703a550c9a (patch) | |
tree | d3df996c3043f85676988acd2cd3711b4e399c24 /sonar-server | |
parent | 6e49ae971b49993d387af57645c068e5f677e946 (diff) | |
download | sonarqube-be698baf4b4519eb43b5494be23a04703a550c9a.tar.gz sonarqube-be698baf4b4519eb43b5494be23a04703a550c9a.zip |
SONAR-5011 Allow to install two plugins sharing the same dependency
Diffstat (limited to 'sonar-server')
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java | 9 | ||||
-rw-r--r-- | sonar-server/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java | 34 |
2 files changed, 38 insertions, 5 deletions
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<File> tempFiles = FileUtils.listFiles(downloadDir, new String[]{TMP_SUFFIX}, false); + Collection<File> 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<String> getDownloads() { List<String> names = new ArrayList<String>(); - List<File> files = (List<File>) FileUtils.listFiles(downloadDir, new String[]{PLUGIN_EXTENSION}, false); + List<File> files = (List<File>) 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<File> { private final String name; |