mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
improve plugin management
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web;
|
||||
package sonia.scm.web.plugin;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
145
scm-web-api/src/main/java/sonia/scm/web/plugin/SCMPlugin.java
Normal file
145
scm-web-api/src/main/java/sonia/scm/web/plugin/SCMPlugin.java
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web.plugin;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.repository.RepositoryHandler;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@XmlRootElement(name = "plugin-config")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class SCMPlugin
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public SCMPlugin()
|
||||
{
|
||||
handlers = new HashSet<Class<? extends RepositoryHandler>>();
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param handlerClass
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean addHandler(Class<? extends RepositoryHandler> handlerClass)
|
||||
{
|
||||
return handlers.add(handlerClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param handlerClass
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean removeHandler(Class<? extends RepositoryHandler> handlerClass)
|
||||
{
|
||||
return handlers.remove(handlerClass);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Collection<Class<? extends RepositoryHandler>> getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SecurityConfig getSecurityConfig()
|
||||
{
|
||||
return securityConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Class<? extends ScmWebPlugin> getWebPlugin()
|
||||
{
|
||||
return webPlugin;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param securityConfig
|
||||
*/
|
||||
public void setSecurityConfig(SecurityConfig securityConfig)
|
||||
{
|
||||
this.securityConfig = securityConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param webPlugin
|
||||
*/
|
||||
public void setWebPlugin(Class<? extends ScmWebPlugin> webPlugin)
|
||||
{
|
||||
this.webPlugin = webPlugin;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@XmlElementWrapper(name = "repository-handlers")
|
||||
@XmlElement(name = "repository-handler")
|
||||
private Set<Class<? extends RepositoryHandler>> handlers;
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "security")
|
||||
private SecurityConfig securityConfig;
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "web-plugin")
|
||||
private Class<? extends ScmWebPlugin> webPlugin;
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web.plugin;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class SCMPluginManager
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String PATH_PLUGINCONFIG = "META-INF/scm/plugin.xml";
|
||||
|
||||
/** Field description */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(SCMPluginManager.class);
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void load() throws IOException
|
||||
{
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
if (classLoader == null)
|
||||
{
|
||||
classLoader = SCMPluginManager.class.getClassLoader();
|
||||
}
|
||||
|
||||
load(classLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param classLoader
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void load(ClassLoader classLoader) throws IOException
|
||||
{
|
||||
Enumeration<URL> urlEnum = classLoader.getResources(PATH_PLUGINCONFIG);
|
||||
|
||||
if (urlEnum != null)
|
||||
{
|
||||
while (urlEnum.hasMoreElements())
|
||||
{
|
||||
URL url = urlEnum.nextElement();
|
||||
|
||||
loadPlugin(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<SCMPlugin> getPlugins()
|
||||
{
|
||||
return plugins;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
*/
|
||||
private void loadPlugin(URL url)
|
||||
{
|
||||
try
|
||||
{
|
||||
SCMPlugin plugin = JAXB.unmarshal(url, SCMPlugin.class);
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("load plugin {}", url.toExternalForm());
|
||||
}
|
||||
|
||||
plugins.add(plugin);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Set<SCMPlugin> plugins = new LinkedHashSet<SCMPlugin>();
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web;
|
||||
package sonia.scm.web.plugin;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web;
|
||||
package sonia.scm.web.plugin;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web.plugin;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import sonia.scm.security.EncryptionHandler;
|
||||
import sonia.scm.web.security.Authenticator;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class SecurityConfig
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Class<? extends Authenticator> getAuthenticator()
|
||||
{
|
||||
return authenticator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Class<? extends EncryptionHandler> getEncryptionHandler()
|
||||
{
|
||||
return encryptionHandler;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param authenticator
|
||||
*/
|
||||
public void setAuthenticator(Class<? extends Authenticator> authenticator)
|
||||
{
|
||||
this.authenticator = authenticator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param encryptionHandler
|
||||
*/
|
||||
public void setEncryptionHandler(
|
||||
Class<? extends EncryptionHandler> encryptionHandler)
|
||||
{
|
||||
this.encryptionHandler = encryptionHandler;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "authenticator")
|
||||
private Class<? extends Authenticator> authenticator;
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "encryption-handler")
|
||||
private Class<? extends EncryptionHandler> encryptionHandler;
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web;
|
||||
package sonia.scm.web.plugin;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user