diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-01-29 09:56:48 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-01-29 09:58:11 +0100 |
commit | 9f3de2ad8b0aaff9ec309a50a1b5d0f3c578d7a8 (patch) | |
tree | d895d242da60ed1208cddf81d5fd4dfea3949aa5 /sonar-batch | |
parent | 62806519276a867d5f243f18fc5e8b12e34f5b69 (diff) | |
download | sonarqube-9f3de2ad8b0aaff9ec309a50a1b5d0f3c578d7a8.tar.gz sonarqube-9f3de2ad8b0aaff9ec309a50a1b5d0f3c578d7a8.zip |
SONAR-2291 Don't extract plugins in the cache folder
but instead extract them in a temporary location.
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java | 12 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java | 29 |
2 files changed, 33 insertions, 8 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java index 1ea9307364d..be4e3837230 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java @@ -52,9 +52,11 @@ public class BatchPluginRepository implements PluginRepository { private Map<String, PluginMetadata> metadataByKey; private Settings settings; private PluginClassloaders classLoaders; + private TempDirectories workingDirectories; - public BatchPluginRepository(PluginDownloader pluginDownloader, Settings settings) { + public BatchPluginRepository(PluginDownloader pluginDownloader, TempDirectories workingDirectories, Settings settings) { this.pluginDownloader = pluginDownloader; + this.workingDirectories = workingDirectories; this.settings = settings; } @@ -71,7 +73,9 @@ public class BatchPluginRepository implements PluginRepository { if (filter.accepts(remote.getKey())) { List<File> pluginFiles = pluginDownloader.downloadPlugin(remote); List<File> extensionFiles = pluginFiles.subList(1, pluginFiles.size()); - PluginMetadata metadata = extractor.installInSameLocation(pluginFiles.get(0), remote.isCore(), extensionFiles); + File targetDir = workingDirectories.getDir("plugins/" + remote.getKey()); + LOG.debug("Installing plugin " + remote.getKey() + " into " + targetDir); + PluginMetadata metadata = extractor.install(pluginFiles.get(0), remote.isCore(), extensionFiles, targetDir); if (StringUtils.isBlank(metadata.getBasePlugin()) || filter.accepts(metadata.getBasePlugin())) { LOG.debug("Excluded plugin: " + metadata.getKey()); metadataByKey.put(metadata.getKey(), metadata); @@ -125,9 +129,9 @@ public class BatchPluginRepository implements PluginRepository { // These default values are not supported by Settings because the class CorePlugin // is not loaded yet. whites.addAll(propertyValues(settings, - CoreProperties.DRY_RUN_INCLUDE_PLUGINS, CoreProperties.DRY_RUN_INCLUDE_PLUGINS_DEFAULT_VALUE)); + CoreProperties.DRY_RUN_INCLUDE_PLUGINS, CoreProperties.DRY_RUN_INCLUDE_PLUGINS_DEFAULT_VALUE)); blacks.addAll(propertyValues(settings, - CoreProperties.DRY_RUN_EXCLUDE_PLUGINS, CoreProperties.DRY_RUN_EXCLUDE_PLUGINS_DEFAULT_VALUE)); + CoreProperties.DRY_RUN_EXCLUDE_PLUGINS, CoreProperties.DRY_RUN_EXCLUDE_PLUGINS_DEFAULT_VALUE)); } if (!whites.isEmpty()) { LOG.info("Include plugins: " + Joiner.on(", ").join(whites)); diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java index f0cf8a22478..f7af9003d62 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java @@ -22,7 +22,9 @@ package org.sonar.batch.bootstrap; import com.google.common.collect.Lists; import org.codehaus.plexus.util.FileUtils; import org.junit.After; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.sonar.api.CoreProperties; import org.sonar.api.config.Settings; import org.sonar.core.plugins.RemotePlugin; @@ -40,6 +42,9 @@ import static org.mockito.Mockito.when; public class BatchPluginRepositoryTest { + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + private BatchPluginRepository repository; @After @@ -51,12 +56,15 @@ public class BatchPluginRepositoryTest { @Test public void shouldLoadPlugin() throws IOException { + TempDirectories tempDirs = mock(TempDirectories.class); + File toDir = temp.newFolder(); + when(tempDirs.getDir("plugins/checkstyle")).thenReturn(toDir); RemotePlugin checkstyle = new RemotePlugin("checkstyle", true); PluginDownloader downloader = mock(PluginDownloader.class); when(downloader.downloadPlugin(checkstyle)).thenReturn(copyFiles("sonar-checkstyle-plugin-2.8.jar")); - repository = new BatchPluginRepository(downloader, new Settings()); + repository = new BatchPluginRepository(downloader, tempDirs, new Settings()); repository.doStart(Arrays.asList(checkstyle)); @@ -68,6 +76,11 @@ public class BatchPluginRepositoryTest { @Test public void shouldLoadPluginExtension() throws IOException { + TempDirectories tempDirs = mock(TempDirectories.class); + File toDir1 = temp.newFolder(); + File toDir2 = temp.newFolder(); + when(tempDirs.getDir("plugins/checkstyle")).thenReturn(toDir1); + when(tempDirs.getDir("plugins/checkstyleextensions")).thenReturn(toDir2); RemotePlugin checkstyle = new RemotePlugin("checkstyle", true); RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false); @@ -75,7 +88,7 @@ public class BatchPluginRepositoryTest { when(downloader.downloadPlugin(checkstyle)).thenReturn(copyFiles("sonar-checkstyle-plugin-2.8.jar")); when(downloader.downloadPlugin(checkstyleExt)).thenReturn(copyFiles("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar")); - repository = new BatchPluginRepository(downloader, new Settings()); + repository = new BatchPluginRepository(downloader, tempDirs, new Settings()); repository.doStart(Arrays.asList(checkstyle, checkstyleExt)); @@ -88,13 +101,16 @@ public class BatchPluginRepositoryTest { @Test public void shouldLoadPluginDeprecatedExtensions() throws IOException { + TempDirectories tempDirs = mock(TempDirectories.class); + File toDir = temp.newFolder(); + when(tempDirs.getDir("plugins/checkstyle")).thenReturn(toDir); RemotePlugin checkstyle = new RemotePlugin("checkstyle", true); checkstyle.getFiles().add(new RemotePluginFile("checkstyle-ext.xml", "fakemd5")); PluginDownloader downloader = mock(PluginDownloader.class); when(downloader.downloadPlugin(checkstyle)).thenReturn(copyFiles("sonar-checkstyle-plugin-2.8.jar", "checkstyle-ext.xml")); - repository = new BatchPluginRepository(downloader, new Settings()); + repository = new BatchPluginRepository(downloader, tempDirs, new Settings()); repository.doStart(Arrays.asList(checkstyle)); @@ -107,6 +123,11 @@ public class BatchPluginRepositoryTest { @Test public void shouldExcludePluginAndItsExtensions() throws IOException { + TempDirectories tempDirs = mock(TempDirectories.class); + File toDir1 = temp.newFolder(); + File toDir2 = temp.newFolder(); + when(tempDirs.getDir("plugins/checkstyle")).thenReturn(toDir1); + when(tempDirs.getDir("plugins/checkstyleextensions")).thenReturn(toDir2); RemotePlugin checkstyle = new RemotePlugin("checkstyle", true); RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false); @@ -116,7 +137,7 @@ public class BatchPluginRepositoryTest { Settings settings = new Settings(); settings.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle"); - repository = new BatchPluginRepository(downloader, settings); + repository = new BatchPluginRepository(downloader, tempDirs, settings); repository.doStart(Arrays.asList(checkstyle, checkstyleExt)); |