private final File downloadDir;
public PluginDownloader(UpdateCenterMatrixFactory updateCenterMatrixFactory, HttpDownloader downloader,
- DefaultServerFileSystem fileSystem) {
+ DefaultServerFileSystem fileSystem) {
this.updateCenterMatrixFactory = updateCenterMatrixFactory;
this.downloader = downloader;
this.downloadDir = fileSystem.getDownloadedPluginsDir();
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);
}
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());
}
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);
}
}
}
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 {
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;