mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-02 11:35:57 +01:00
added new plugin api
This commit is contained in:
@@ -25,6 +25,7 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -64,6 +65,11 @@ public class BasicContextProvider implements SCMContextProvider
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
for (SCMPlugin plugin : plugins)
|
||||
{
|
||||
plugin.contextDestroyed(this);
|
||||
}
|
||||
|
||||
for (GroupManager manager : groupManagerMap.values())
|
||||
{
|
||||
manager.close();
|
||||
@@ -82,6 +88,7 @@ public class BasicContextProvider implements SCMContextProvider
|
||||
loadGroupManagers();
|
||||
loadRepositoryManager();
|
||||
loadEncryptionHandler();
|
||||
loadPlugins();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -202,6 +209,20 @@ public class BasicContextProvider implements SCMContextProvider
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
private void loadPlugins()
|
||||
{
|
||||
plugins = ServiceUtil.getServices(SCMPlugin.class);
|
||||
|
||||
for (SCMPlugin plugin : plugins)
|
||||
{
|
||||
plugin.contextInitialized(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -229,6 +250,9 @@ public class BasicContextProvider implements SCMContextProvider
|
||||
/** Field description */
|
||||
private Map<String, GroupManager> groupManagerMap;
|
||||
|
||||
/** Field description */
|
||||
private List<SCMPlugin> plugins;
|
||||
|
||||
/** Field description */
|
||||
private RepositoryManager repositoryManager;
|
||||
}
|
||||
|
||||
32
scm-core/src/main/java/sonia/scm/SCMPlugin.java
Normal file
32
scm-core/src/main/java/sonia/scm/SCMPlugin.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface SCMPlugin
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void contextDestroyed(SCMContextProvider context);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void contextInitialized(SCMContextProvider context);
|
||||
}
|
||||
@@ -9,7 +9,10 @@ package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.ConfigurationException;
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.ServiceUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
@@ -44,6 +47,31 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
@Override
|
||||
public void addHandler(RepositoryHandler handler)
|
||||
{
|
||||
AssertUtil.assertIsNotNull(handler);
|
||||
|
||||
RepositoryType type = handler.getType();
|
||||
|
||||
AssertUtil.assertIsNotNull(type);
|
||||
|
||||
if (handlerMap.containsKey(type.getName()))
|
||||
{
|
||||
throw new ConfigurationException(
|
||||
type.getName().concat("allready registered"));
|
||||
}
|
||||
|
||||
handlerMap.put(type.getName(), handler);
|
||||
handler.init(SCMContext.getContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -25,6 +25,16 @@ public interface RepositoryManager
|
||||
ListenerSupport<RepositoryListener>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
public void addHandler(RepositoryHandler handler);
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user