From e86d299c13d8617dbcda8d98503077a35dc713b8 Mon Sep 17 00:00:00 2001 From: Godin Date: Wed, 27 Oct 2010 17:15:33 +0000 Subject: [PATCH] SONAR-1886: Uninstall a plugin --- .../platform/DefaultServerFileSystem.java | 4 +++ .../sonar/server/plugins/PluginDeployer.java | 35 +++++++++++++++++++ .../java/org/sonar/server/ui/JRubyFacade.java | 11 ++---- .../controllers/updatecenter_controller.rb | 6 ---- .../views/updatecenter/_uninstalls.html.erb | 1 - 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java b/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java index 9822d909303..2962289e48a 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java @@ -112,6 +112,10 @@ public class DefaultServerFileSystem implements ServerFileSystem { return new File(getHomeDir(), "extensions/downloads"); } + public File getRemovedPluginsDir() { + return new File(getHomeDir(), "extensions/trash"); + } + public File getJdbcDriver() { String dialect = databaseConnector.getDialect().getId(); File dir = new File(getHomeDir(), "/extensions/jdbc-driver/" + dialect + "/"); diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java b/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java index 9da1dd0aa11..a7df673ab6b 100644 --- a/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java @@ -27,6 +27,7 @@ import org.sonar.api.Plugin; import org.sonar.api.ServerComponent; import org.sonar.api.platform.Server; import org.sonar.api.utils.Logs; +import org.sonar.api.utils.SonarException; import org.sonar.api.utils.TimeProfiler; import org.sonar.api.utils.ZipUtils; import org.sonar.core.plugin.JpaPlugin; @@ -34,6 +35,7 @@ import org.sonar.core.plugin.JpaPluginDao; import org.sonar.server.platform.DefaultServerFileSystem; import org.sonar.server.platform.ServerStartException; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import java.io.File; @@ -66,6 +68,8 @@ public final class PluginDeployer implements ServerComponent { public void start() throws IOException { TimeProfiler profiler = new TimeProfiler().start("Install plugins"); + deleteRemovedPlugins(); + loadUserPlugins(); moveAndLoadDownloadedPlugins(); loadCorePlugins(); @@ -77,6 +81,37 @@ public final class PluginDeployer implements ServerComponent { profiler.stop(); } + private void deleteRemovedPlugins() { + File trashDir = fileSystem.getRemovedPluginsDir(); + try { + if (trashDir.exists()) { + FileUtils.deleteDirectory(trashDir); + } + } catch (IOException e) { + throw new SonarException("Fail to clean the plugin trash directory: " + trashDir, e); + } + } + + public void uninstall(String pluginKey) { + PluginMetadata metadata = pluginByKeys.get(pluginKey); + try { + FileUtils.moveFileToDirectory(metadata.getSourceFile(), fileSystem.getRemovedPluginsDir(), true); + } catch (IOException e) { + throw new SonarException("Fail to uninstall plugin: " + pluginKey, e); + } + } + + public List getUninstalls() { + List names = Lists.newArrayList(); + if (fileSystem.getRemovedPluginsDir().exists()) { + List files = (List) FileUtils.listFiles(fileSystem.getRemovedPluginsDir(), new String[] { "jar" }, false); + for (File file : files) { + names.add(file.getName()); + } + } + return names; + } + private void persistPlugins() { List previousPlugins = dao.getPlugins(); List installedPlugins = new ArrayList(); diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 7c83558c18a..8a68e00ccb3 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -31,7 +31,6 @@ import org.sonar.api.profiles.ProfileImporter; import org.sonar.api.resources.Language; import org.sonar.api.rules.DefaultRulesManager; import org.sonar.api.rules.RuleRepository; -import org.sonar.api.utils.SonarException; import org.sonar.api.utils.ValidationMessages; import org.sonar.api.web.Footer; import org.sonar.api.web.NavigationSection; @@ -49,6 +48,7 @@ import org.sonar.server.filters.FilterExecutor; import org.sonar.server.filters.FilterResult; import org.sonar.server.platform.Platform; import org.sonar.server.plugins.PluginClassLoaders; +import org.sonar.server.plugins.PluginDeployer; import org.sonar.server.plugins.PluginDownloader; import org.sonar.server.plugins.UpdateFinder; import org.sonar.server.plugins.UpdateFinderFactory; @@ -57,7 +57,6 @@ import org.sonar.server.rules.RulesConsole; import org.sonar.updatecenter.common.Version; import java.util.Collection; -import java.util.Collections; import java.util.List; public final class JRubyFacade implements ServerComponent { @@ -80,15 +79,11 @@ public final class JRubyFacade implements ServerComponent { } public void uninstallPlugin(String pluginKey) { - throw new SonarException("Implement me!"); - } - - public void cancelPluginUninstalls() { - throw new SonarException("Implement me!"); + getContainer().getComponent(PluginDeployer.class).uninstall(pluginKey); } public List getPluginUninstalls() { - return Collections.emptyList(); + return getContainer().getComponent(PluginDeployer.class).getUninstalls(); } public UpdateFinder getUpdateFinder(boolean forceReload) { diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/updatecenter_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/updatecenter_controller.rb index 9cbc245abe5..a1be366c155 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/updatecenter_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/updatecenter_controller.rb @@ -92,12 +92,6 @@ class UpdatecenterController < ApplicationController redirect_to :action => 'index' end - def cancel_uninstalls - java_facade.cancelPluginUninstalls() - flash[:notice]="Plugin uninstalls are canceled." - redirect_to :action => 'index' - end - private def load_update_finder @finder=java_facade.getUpdateFinder(params[:reload]=='true') diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/_uninstalls.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/_uninstalls.html.erb index 4158e78b201..d10e0ff29c0 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/_uninstalls.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/updatecenter/_uninstalls.html.erb @@ -5,7 +5,6 @@
  • <%= uninstall -%>
  • <% end %> -

    <% end %> -- 2.39.5