From 3dedf31dda05b8933786c2c1b4424aabdf9339dd Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 18 Dec 2010 16:25:57 +0100 Subject: [PATCH] implement plugin uninstall method --- .../sonia/scm/plugin/AetherPluginHandler.java | 68 +++++++++++++++++-- .../scm/plugin/DefaultPluginManager.java | 41 ++++++++--- .../main/webapp/resources/js/sonia.plugin.js | 60 ++++++++-------- 3 files changed, 126 insertions(+), 43 deletions(-) diff --git a/scm-webapp/src/main/java/sonia/scm/plugin/AetherPluginHandler.java b/scm-webapp/src/main/java/sonia/scm/plugin/AetherPluginHandler.java index 9db4b38ff5..c8d05f8cf4 100644 --- a/scm-webapp/src/main/java/sonia/scm/plugin/AetherPluginHandler.java +++ b/scm-webapp/src/main/java/sonia/scm/plugin/AetherPluginHandler.java @@ -73,6 +73,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import java.util.List; import javax.xml.bind.JAXBContext; @@ -193,10 +194,7 @@ public class AetherPluginHandler localRepositoryDirectory.getAbsolutePath().length())); } - Marshaller marshaller = jaxbContext.createMarshaller(); - - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - marshaller.marshal(classpath, classpathFile); + storeClasspath(); } } catch (Exception ex) @@ -205,6 +203,54 @@ public class AetherPluginHandler } } + /** + * TODO: remove dependencies and remove files + * + * + * @param pluginPath + */ + public void uninstall(String pluginPath) + { + if (logger.isInfoEnabled()) + { + logger.info("try to uninstall plugin: {}", pluginPath); + } + + if (classpath != null) + { + synchronized (Classpath.class) + { + Iterator iterator = classpath.iterator(); + + while (iterator.hasNext()) + { + String path = iterator.next(); + + if (pluginPath.contains(path)) + { + if (logger.isInfoEnabled()) + { + logger.info("remove {} from classpath", path); + } + + iterator.remove(); + + break; + } + } + + try + { + storeClasspath(); + } + catch (JAXBException ex) + { + throw new PluginLoadException(ex); + } + } + } + } + //~--- set methods ---------------------------------------------------------- /** @@ -257,6 +303,20 @@ public class AetherPluginHandler return locator.getService(RepositorySystem.class); } + /** + * Method description + * + * + * @throws JAXBException + */ + private void storeClasspath() throws JAXBException + { + Marshaller marshaller = jaxbContext.createMarshaller(); + + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + marshaller.marshal(classpath, classpathFile); + } + //~--- fields --------------------------------------------------------------- /** Field description */ diff --git a/scm-webapp/src/main/java/sonia/scm/plugin/DefaultPluginManager.java b/scm-webapp/src/main/java/sonia/scm/plugin/DefaultPluginManager.java index 315759b47c..e81c316871 100644 --- a/scm-webapp/src/main/java/sonia/scm/plugin/DefaultPluginManager.java +++ b/scm-webapp/src/main/java/sonia/scm/plugin/DefaultPluginManager.java @@ -58,6 +58,7 @@ import java.net.URL; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -107,7 +108,7 @@ public class DefaultPluginManager implements PluginManager this.configuration = configuration; this.cache = cacheManager.getSimpleCache(String.class, PluginCenter.class, CACHE_NAME); - installedPlugins = new HashMap(); + installedPlugins = new HashMap(); for (Plugin plugin : pluginLoader.getInstalledPlugins()) { @@ -115,7 +116,7 @@ public class DefaultPluginManager implements PluginManager if ((info != null) && info.isValid()) { - installedPlugins.put(info.getId(), plugin.getInformation()); + installedPlugins.put(info.getId(), plugin); } } @@ -172,7 +173,19 @@ public class DefaultPluginManager implements PluginManager { SecurityUtil.assertIsAdmin(securityContextProvicer); - throw new UnsupportedOperationException("Not supported yet."); + Plugin plugin = installedPlugins.get(id); + + if (plugin == null) + { + throw new PluginLoadException(id.concat(" is not install")); + } + + if (pluginHandler == null) + { + pluginHandler = new AetherPluginHandler(SCMContext.getContext()); + } + + pluginHandler.uninstall(plugin.getPath()); } /** @@ -235,7 +248,7 @@ public class DefaultPluginManager implements PluginManager Set infoSet = new HashSet(); - filter(infoSet, installedPlugins.values(), filter); + filter(infoSet, getInstalled(), filter); filter(infoSet, getPluginCenter().getPlugins(), filter); return infoSet; @@ -252,9 +265,8 @@ public class DefaultPluginManager implements PluginManager { SecurityUtil.assertIsAdmin(securityContextProvicer); - Set infoSet = new HashSet(); + Set infoSet = getInstalled(); - infoSet.addAll(installedPlugins.values()); infoSet.addAll(getPluginCenter().getPlugins()); return infoSet; @@ -292,7 +304,7 @@ public class DefaultPluginManager implements PluginManager * @return */ @Override - public Collection getAvailableUpdates() + public Set getAvailableUpdates() { SecurityUtil.assertIsAdmin(securityContextProvicer); @@ -306,11 +318,18 @@ public class DefaultPluginManager implements PluginManager * @return */ @Override - public Collection getInstalled() + public Set getInstalled() { SecurityUtil.assertIsAdmin(securityContextProvicer); - return installedPlugins.values(); + Set infoSet = new LinkedHashSet(); + + for (Plugin plugin : installedPlugins.values()) + { + infoSet.add(plugin.getInformation()); + } + + return infoSet; } //~--- methods -------------------------------------------------------------- @@ -345,7 +364,7 @@ public class DefaultPluginManager implements PluginManager { PluginState state = PluginState.AVAILABLE; - for (PluginInformation installed : installedPlugins.values()) + for (PluginInformation installed : getInstalled()) { if (isSamePlugin(available, installed)) { @@ -452,7 +471,7 @@ public class DefaultPluginManager implements PluginManager private ScmConfiguration configuration; /** Field description */ - private Map installedPlugins; + private Map installedPlugins; /** Field description */ private AetherPluginHandler pluginHandler; diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.plugin.js b/scm-webapp/src/main/webapp/resources/js/sonia.plugin.js index b9329291d1..24fbac5de3 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.plugin.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.plugin.js @@ -98,8 +98,39 @@ Sonia.plugin.installPlugin = function(pluginId){ Sonia.plugin.uninstallPlugin = function(pluginId){ if ( debug ){ - console.debug('not implemented'); + console.debug( 'uninstall plugin ' + pluginId ); } + + var loadingBox = Ext.MessageBox.show({ + title: 'Please wait', + msg: 'Uninstalling Plugin.', + width: 300, + wait: true, + animate: true, + progress: true, + closable: false + }); + + Ext.Ajax.request({ + url: restUrl + 'plugins/uninstall/' + pluginId + '.json', + method: 'POST', + scope: this, + success: function(){ + if ( debug ){ + console.debug('plugin successfully uninstalled'); + } + loadingBox.hide(); + Ext.MessageBox.alert('Plugin successfully uninstalled', + 'Restart the applicationserver to activate the changes.'); + }, + failure: function(){ + if ( debug ){ + console.debug('plugin uninstallation failed'); + } + alert( 'failure' ); + loadingBox.hide(); + } + }); } Sonia.plugin.updatePlugin = function(pluginId){ @@ -108,33 +139,6 @@ Sonia.plugin.updatePlugin = function(pluginId){ } } - -// loading window - -Sonia.plugin.LoadingWindow = Ext.extend(Ext.Window,{ - - initComponent: function(){ - - var config = { - layout:'fit', - width:300, - height:150, - closable: false, - resizable: false, - plain: true, - border: false, - modal: true, - items: [{ - xtype: 'progress' - }] - }; - - Ext.apply(this, Ext.apply(this.initialConfig, config)); - Sonia.login.Window.superclass.initComponent.apply(this, arguments); - } - -}); - // plugin grid Sonia.plugin.Grid = Ext.extend(Sonia.rest.Grid, {