From b0deb0d52985ce94e4afe28f4378f14e4dae4713 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Wed, 25 Oct 2017 11:50:24 +0200 Subject: [PATCH] SONAR-9946 Fix local copy of edition plugins for tests --- .../plugins/edition/EditionPluginDownloader.java | 2 +- .../edition/EditionPluginDownloaderTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionPluginDownloader.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionPluginDownloader.java index 0da1f5d7cae..f5e73f573c9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionPluginDownloader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionPluginDownloader.java @@ -95,7 +95,7 @@ public class EditionPluginDownloader { if (url.startsWith("file:")) { // used for tests File file = toFile(uri.toURL()); - Files.copy(file.toPath(), tmpDir); + Files.copy(file.toPath(), tmpDir.resolve(file.getName())); } else { String filename = substringAfterLast(uri.getPath(), "/"); if (!filename.endsWith("." + PLUGIN_EXTENSION)) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionPluginDownloaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionPluginDownloaderTest.java index 4f7d6498abd..06e0c4675a8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionPluginDownloaderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/edition/EditionPluginDownloaderTest.java @@ -83,6 +83,22 @@ public class EditionPluginDownloaderTest { assertThat(downloadDir).isDirectory(); assertThat(tmpDir).doesNotExist(); } + + @Test + public void download_plugin_to_tmp_with_file_uri() throws IOException, URISyntaxException { + File plugin1 = temp.newFile("plugin1.jar"); + File plugin2 = temp.newFile("plugin2.jar"); + + List releases = ImmutableList.of(createRelease("plugin1", "1.0", plugin1.toURI().toString()), + createRelease("plugin2", "1.0", plugin2.toURI().toString())); + + when(updateCenter.findInstallablePlugins("plugins", Version.create(""))).thenReturn(releases); + downloader.downloadEditionPlugins(Collections.singleton("plugins"), updateCenter); + + assertThat(logTester.logs()).containsOnly("Downloading plugin: plugin1", "Downloading plugin: plugin2"); + assertThat(downloadDir).isDirectory(); + assertThat(tmpDir).doesNotExist(); + } @Test public void dont_write_download_dir_if_download_fails() throws URISyntaxException { -- 2.39.5