import ro.fortsoft.pf4j.Plugin;
import ro.fortsoft.pf4j.PluginWrapper;
+import ro.fortsoft.pf4j.Version;
+/**
+ * Parent class of Gitblit plugins.
+ *
+ * @author James Moger
+ * @since 1.5.0
+ */
public abstract class GitblitPlugin extends Plugin {
public GitblitPlugin(PluginWrapper wrapper) {
super(wrapper);
}
+ /**
+ * Called after a plugin as been loaded but before it is started for the
+ * first time. This allows the plugin to install settings or perform any
+ * other required first-time initialization.
+ *
+ * @since 1.5.0
+ */
+ public abstract void onInstall();
+
+ /**
+ * Called after an updated plugin has been installed but before the updated
+ * plugin is started. The oldVersion is passed as a parameter in the event
+ * that special processing needs to be executed.
+ *
+ * @param oldVersion
+ * @since 1.5.0
+ */
+ public abstract void onUpgrade(Version oldVersion);
+
+ /**
+ * Called before a plugin has been unloaded and deleted from the system.
+ * This allows a plugin to remove any settings it may have created or
+ * perform and other necessary cleanup.
+ *
+ * @since 1.5.0
+ */
+ public abstract void onUninstall();
}
}
@Override
- public boolean deletePlugin(String pluginId) {
- return pluginManager.deletePlugin(pluginId);
+ public boolean uninstallPlugin(String pluginId) {
+ return pluginManager.uninstallPlugin(pluginId);
}
@Override
* @param pluginId
* @return true if successful
*/
- boolean deletePlugin(String pluginId);
+ boolean uninstallPlugin(String pluginId);
/**
* Refresh the plugin registry.
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;
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);
}
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 {
}
@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
throw new UnloggedFailure(String.format("Plugin %s is not installed!", id));
}
- if (gitblit.deletePlugin(pluginWrapper.getPluginId())) {
+ if (gitblit.uninstallPlugin(pluginWrapper.getPluginId())) {
stdout.println(String.format("Uninstalled %s", pluginWrapper.getPluginId()));
} else {
throw new UnloggedFailure(1, String.format("Failed to uninstall %s", pluginWrapper.getPluginId()));
import com.gitblit.manager.IFederationManager;
import com.gitblit.manager.IPluginManager;
import com.gitblit.manager.IGitblit;
+import ro.fortsoft.pf4j.Version;
public class ExamplePlugin extends GitblitPlugin {
IPluginManager plugins = GitblitContext.getManager(IPluginManager.class);
IGitblit gitblit = GitblitContext.getManager(IGitblit.class);
}
+
+ @Override
+ public void stop() {
+ }
+
+ @Override
+ public void onInstall() {
+ }
+
+ @Override
+ public void onUpgrade(Version oldVersion) {
+ }
+
+ @Override
+ public void onUninstall() {
+ }
}
```