added new plugin api

This commit is contained in:
Sebastian Sdorra
2010-09-28 19:19:11 +02:00
parent 9bca5a5f07
commit af7b7b8e4d
4 changed files with 94 additions and 0 deletions

View File

@@ -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;
}

View 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);
}

View File

@@ -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
*

View File

@@ -25,6 +25,16 @@ public interface RepositoryManager
ListenerSupport<RepositoryListener>
{
/**
* Method description
*
*
* @param handler
*/
public void addHandler(RepositoryHandler handler);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*