summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/manager
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-04-17 18:00:58 -0400
committerJames Moger <james.moger@gitblit.com>2014-04-17 18:08:12 -0400
commitcf4004e8d64399f6fc722fcb313eaaae6a65fa20 (patch)
tree795bd96caf734212b4120d6e7c3597af0f9a60d0 /src/main/java/com/gitblit/manager
parent067bb4db93544dca984363dbe728f94607ba8a5d (diff)
downloadgitblit-cf4004e8d64399f6fc722fcb313eaaae6a65fa20.tar.gz
gitblit-cf4004e8d64399f6fc722fcb313eaaae6a65fa20.zip
Add plugin (un)install lifecycle methods
Diffstat (limited to 'src/main/java/com/gitblit/manager')
-rw-r--r--src/main/java/com/gitblit/manager/GitblitManager.java4
-rw-r--r--src/main/java/com/gitblit/manager/IPluginManager.java2
-rw-r--r--src/main/java/com/gitblit/manager/PluginManager.java30
3 files changed, 31 insertions, 5 deletions
diff --git a/src/main/java/com/gitblit/manager/GitblitManager.java b/src/main/java/com/gitblit/manager/GitblitManager.java
index 4ecb9c6d..61a09491 100644
--- a/src/main/java/com/gitblit/manager/GitblitManager.java
+++ b/src/main/java/com/gitblit/manager/GitblitManager.java
@@ -1251,8 +1251,8 @@ public class GitblitManager implements IGitblit {
}
@Override
- public boolean deletePlugin(String pluginId) {
- return pluginManager.deletePlugin(pluginId);
+ public boolean uninstallPlugin(String pluginId) {
+ return pluginManager.uninstallPlugin(pluginId);
}
@Override
diff --git a/src/main/java/com/gitblit/manager/IPluginManager.java b/src/main/java/com/gitblit/manager/IPluginManager.java
index bf04619c..528bbed4 100644
--- a/src/main/java/com/gitblit/manager/IPluginManager.java
+++ b/src/main/java/com/gitblit/manager/IPluginManager.java
@@ -122,7 +122,7 @@ public interface IPluginManager extends IManager {
* @param pluginId
* @return true if successful
*/
- boolean deletePlugin(String pluginId);
+ boolean uninstallPlugin(String pluginId);
/**
* Refresh the plugin registry.
diff --git a/src/main/java/com/gitblit/manager/PluginManager.java b/src/main/java/com/gitblit/manager/PluginManager.java
index 405dc510..40d302dd 100644
--- a/src/main/java/com/gitblit/manager/PluginManager.java
+++ b/src/main/java/com/gitblit/manager/PluginManager.java
@@ -47,6 +47,7 @@ import ro.fortsoft.pf4j.Version;
import com.gitblit.Constants;
import com.gitblit.Keys;
+import com.gitblit.extensions.GitblitPlugin;
import com.gitblit.models.PluginRegistry;
import com.gitblit.models.PluginRegistry.InstallState;
import com.gitblit.models.PluginRegistry.PluginRegistration;
@@ -141,6 +142,12 @@ public class PluginManager implements IPluginManager, PluginStateListener {
return false;
}
+ // allow the plugin to prepare for operation after installation
+ PluginWrapper pluginWrapper = pf4j.getPlugin(pluginId);
+ if (pluginWrapper.getPlugin() instanceof GitblitPlugin) {
+ ((GitblitPlugin) pluginWrapper.getPlugin()).onInstall();
+ }
+
PluginState state = pf4j.startPlugin(pluginId);
return PluginState.STARTED.equals(state);
}
@@ -154,13 +161,20 @@ public class PluginManager implements IPluginManager, PluginStateListener {
return false;
}
- if (deletePlugin(pluginId)) {
+ Version oldVersion = pf4j.getPlugin(pluginId).getDescriptor().getVersion();
+ if (removePlugin(pluginId, false)) {
String newPluginId = pf4j.loadPlugin(file);
if (StringUtils.isEmpty(newPluginId)) {
logger.error("Failed to load plugin {}", file);
return false;
}
+ // the plugin to handle an upgrade
+ PluginWrapper pluginWrapper = pf4j.getPlugin(newPluginId);
+ if (pluginWrapper.getPlugin() instanceof GitblitPlugin) {
+ ((GitblitPlugin) pluginWrapper.getPlugin()).onUpgrade(oldVersion);
+ }
+
PluginState state = pf4j.startPlugin(newPluginId);
return PluginState.STARTED.equals(state);
} else {
@@ -183,9 +197,21 @@ public class PluginManager implements IPluginManager, PluginStateListener {
}
@Override
- public synchronized boolean deletePlugin(String pluginId) {
+ public synchronized boolean uninstallPlugin(String pluginId) {
+ return removePlugin(pluginId, true);
+ }
+
+ protected boolean removePlugin(String pluginId, boolean isUninstall) {
PluginWrapper pluginWrapper = getPlugin(pluginId);
final String name = pluginWrapper.getPluginPath().substring(1);
+
+ if (isUninstall) {
+ // allow the plugin to prepare for uninstallation
+ if (pluginWrapper.getPlugin() instanceof GitblitPlugin) {
+ ((GitblitPlugin) pluginWrapper.getPlugin()).onUninstall();
+ }
+ }
+
if (pf4j.deletePlugin(pluginId)) {
// delete the checksums