summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-07-03 14:30:22 -0400
committerJames Moger <james.moger@gitblit.com>2014-07-03 17:00:41 -0400
commit1c301ba07b13c1cd941c44805ee09d1ac8759bd5 (patch)
treec9bd21228e4e295e8b4b10ec35a4a9f1cd1bd62a
parent34ea0170815ade4a456fe23c1b4472852ed26107 (diff)
downloadgitblit-1c301ba07b13c1cd941c44805ee09d1ac8759bd5.tar.gz
gitblit-1c301ba07b13c1cd941c44805ee09d1ac8759bd5.zip
Support injection of plugin Extensions
-rw-r--r--src/main/java/com/gitblit/manager/PluginManager.java30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/main/java/com/gitblit/manager/PluginManager.java b/src/main/java/com/gitblit/manager/PluginManager.java
index a35ff6fe..874e24b5 100644
--- a/src/main/java/com/gitblit/manager/PluginManager.java
+++ b/src/main/java/com/gitblit/manager/PluginManager.java
@@ -37,7 +37,9 @@ import java.util.TreeMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import ro.fortsoft.pf4j.DefaultExtensionFinder;
import ro.fortsoft.pf4j.DefaultPluginManager;
+import ro.fortsoft.pf4j.ExtensionFinder;
import ro.fortsoft.pf4j.PluginClassLoader;
import ro.fortsoft.pf4j.PluginState;
import ro.fortsoft.pf4j.PluginStateEvent;
@@ -103,7 +105,33 @@ public class PluginManager implements IPluginManager, PluginStateListener {
public PluginManager start() {
File dir = runtimeManager.getFileOrFolder(Keys.plugins.folder, "${baseFolder}/plugins");
dir.mkdirs();
- pf4j = new DefaultPluginManager(dir);
+ pf4j = new DefaultPluginManager(dir) {
+ @Override
+ protected ExtensionFinder createExtensionFinder() {
+ DefaultExtensionFinder extensionFinder = new DefaultExtensionFinder(this) {
+ @Override
+ protected ExtensionFactory createExtensionFactory() {
+ return new ExtensionFactory() {
+ @Override
+ public Object create(Class<?> extensionType) {
+ // instantiate && inject the extension
+ logger.debug("Create instance for extension '{}'", extensionType.getName());
+ try {
+ return runtimeManager.getInjector().getInstance(extensionType);
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ return null;
+ }
+
+ };
+ }
+ };
+ addPluginStateListener(extensionFinder);
+
+ return extensionFinder;
+ }
+ };
try {
Version systemVersion = Version.createVersion(Constants.getVersion());