rebuild plugin system

This commit is contained in:
Sebastian Sdorra
2010-12-01 14:26:29 +01:00
parent 11faa205e8
commit 3f1b6e1160
28 changed files with 1026 additions and 710 deletions

View File

@@ -40,6 +40,7 @@ import com.google.inject.Singleton;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import sonia.scm.Type;
import sonia.scm.plugin.ext.Extension;
//~--- JDK imports ------------------------------------------------------------
@@ -51,6 +52,7 @@ import java.io.IOException;
* @author Sebastian Sdorra
*/
@Singleton
@Extension
public class GitRepositoryHandler
extends AbstractSimpleRepositoryHandler<GitConfig>
{

View File

@@ -29,49 +29,39 @@
*
*/
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.web.plugin.ClasspathWebResource;
import sonia.scm.web.plugin.ScmWebPlugin;
import sonia.scm.web.plugin.ScmWebPluginContext;
import com.google.inject.servlet.ServletModule;
import sonia.scm.plugin.ext.Extension;
import sonia.scm.web.filter.BasicAuthenticationFilter;
/**
*
* @author Sebastian Sdorra
*/
public class HgWebPlugin implements ScmWebPlugin
@Extension
public class GitServletModule extends ServletModule
{
/** Field description */
public static final String SCRIPT = "/sonia/scm/hg.config.js";
public static final String PATTERN_GIT = "/git/*";
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param context
*/
@Override
public void contextDestroyed(ScmWebPluginContext context)
protected void configureServlets()
{
// do nothing
}
/**
* Method description
*
*
* @param context
*/
@Override
public void contextInitialized(ScmWebPluginContext context)
{
context.addScriptResource(new ClasspathWebResource(SCRIPT));
context.addInjectModule(new HgServletModule());
filter(PATTERN_GIT).through(BasicAuthenticationFilter.class);
filter(PATTERN_GIT).through(GitPermissionFilter.class);
serve(PATTERN_GIT).with(ScmGitServlet.class);
}
}

View File

@@ -1,94 +0,0 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.servlet.ServletModule;
import sonia.scm.web.filter.BasicAuthenticationFilter;
import sonia.scm.web.plugin.ClasspathWebResource;
import sonia.scm.web.plugin.ScmWebPlugin;
import sonia.scm.web.plugin.ScmWebPluginContext;
/**
*
* @author Sebastian Sdorra
*/
public class GitWebPlugin implements ScmWebPlugin
{
/** Field description */
public static final String PATTERN_GIT = "/git/*";
/** Field description */
public static final String SCRIPT = "/sonia/scm/git.config.js";
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param context
*/
@Override
public void contextDestroyed(ScmWebPluginContext context)
{
// do nothing
}
/**
* Method description
*
*
* @param context
*/
@Override
public void contextInitialized(ScmWebPluginContext context)
{
context.addScriptResource(new ClasspathWebResource(SCRIPT));
context.addInjectModule(new ServletModule()
{
@Override
protected void configureServlets()
{
filter(PATTERN_GIT).through(BasicAuthenticationFilter.class);
filter(PATTERN_GIT).through(GitPermissionFilter.class);
serve(PATTERN_GIT).with(ScmGitServlet.class);
}
});
}
}

View File

@@ -40,12 +40,18 @@
Purpose of the document follows.
-->
<plugin-config>
<plugin>
<web-plugin>sonia.scm.web.GitWebPlugin</web-plugin>
<information>
<name>${project.name}</name>
<description>${project.description}</description>
<author>Sebastian Sdorra</author>
<version>${project.version}</version>
<url>http://bitbucket.org/sdorra/scm-manager</url>
</information>
<repository-handlers>
<repository-handler>sonia.scm.repository.GitRepositoryHandler</repository-handler>
</repository-handlers>
<resources>
<script>/sonia/scm/git.config.js</script>
</resources>
</plugin-config>
</plugin>

View File

@@ -42,6 +42,7 @@ import sonia.scm.io.ExtendedCommand;
import sonia.scm.io.INIConfiguration;
import sonia.scm.io.INIConfigurationWriter;
import sonia.scm.io.INISection;
import sonia.scm.plugin.ext.Extension;
//~--- JDK imports ------------------------------------------------------------
@@ -53,6 +54,7 @@ import java.io.IOException;
* @author Sebastian Sdorra
*/
@Singleton
@Extension
public class HgRepositoryHandler
extends AbstractSimpleRepositoryHandler<HgConfig>
{

View File

@@ -36,6 +36,7 @@ package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.servlet.ServletModule;
import sonia.scm.plugin.ext.Extension;
import sonia.scm.web.filter.BasicAuthenticationFilter;
@@ -43,6 +44,7 @@ import sonia.scm.web.filter.BasicAuthenticationFilter;
*
* @author Sebastian Sdorra
*/
@Extension
public class HgServletModule extends ServletModule
{

View File

@@ -40,12 +40,18 @@
Purpose of the document follows.
-->
<plugin-config>
<plugin>
<web-plugin>sonia.scm.web.HgWebPlugin</web-plugin>
<information>
<name>scm-hg-plugin</name>
<description>Mercurial Plugin</description>
<author>Sebastian Sdorra</author>
<version>1.0-M3-SNAPSHOT</version>
<url>http://bitbucket.org/sdorra/scm-manager</url>
</information>
<repository-handlers>
<repository-handler>sonia.scm.repository.HgRepositoryHandler</repository-handler>
</repository-handlers>
<resources>
<script>/sonia/scm/hg.config.js</script>
</resources>
</plugin-config>
</plugin>

View File

@@ -41,6 +41,7 @@ import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import sonia.scm.Type;
import sonia.scm.plugin.ext.Extension;
//~--- JDK imports ------------------------------------------------------------
@@ -52,6 +53,7 @@ import java.io.IOException;
* @author Sebastian Sdorra
*/
@Singleton
@Extension
public class SvnRepositoryHandler
extends AbstractSimpleRepositoryHandler<SvnConfig>
{

View File

@@ -43,11 +43,13 @@ import sonia.scm.web.filter.BasicAuthenticationFilter;
import java.util.HashMap;
import java.util.Map;
import sonia.scm.plugin.ext.Extension;
/**
*
* @author Sebastian Sdorra
*/
@Extension
public class SvnServletModule extends ServletModule
{

View File

@@ -1,79 +0,0 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.web.plugin.ClasspathWebResource;
import sonia.scm.web.plugin.ScmWebPlugin;
import sonia.scm.web.plugin.ScmWebPluginContext;
/**
*
* @author Sebastian Sdorra
*/
public class SvnWebPlugin implements ScmWebPlugin
{
/** Field description */
public static final String SCRIPT = "/sonia/scm/svn.config.js";
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param context
*/
@Override
public void contextDestroyed(ScmWebPluginContext context)
{
// do nothing
}
/**
* Method description
*
*
* @param context
*/
@Override
public void contextInitialized(ScmWebPluginContext context)
{
context.addScriptResource(new ClasspathWebResource(SCRIPT));
context.addInjectModule(new SvnServletModule());
}
}

View File

@@ -40,12 +40,18 @@
Purpose of the document follows.
-->
<plugin-config>
<plugin>
<web-plugin>sonia.scm.web.SvnWebPlugin</web-plugin>
<information>
<name>${project.name}</name>
<description>${project.description}</description>
<author>Sebastian Sdorra</author>
<version>${project.version}</version>
<url>http://bitbucket.org/sdorra/scm-manager</url>
</information>
<repository-handlers>
<repository-handler>sonia.scm.repository.SvnRepositoryHandler</repository-handler>
</repository-handlers>
<resources>
<script>/sonia/scm/svn.config.js</script>
</resources>
</plugin-config>
</plugin>

View File

@@ -29,21 +29,31 @@
*
*/
package sonia.scm.web.plugin;
package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.plugin.ext.ExtensionObject;
import sonia.scm.plugin.ext.ExtensionProcessor;
import sonia.scm.plugin.ext.JARExtensionScanner;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collection;
import java.util.Enumeration;
import java.util.LinkedHashSet;
import java.util.HashSet;
import java.util.Set;
import javax.xml.bind.JAXB;
@@ -52,15 +62,38 @@ import javax.xml.bind.JAXB;
*
* @author Sebastian Sdorra
*/
public class SCMPluginManager
public class DefaultPluginManager implements PluginManager
{
/** Field description */
public static final String DEFAULT_PACKAGE = "sonia.scm";
/** Field description */
public static final String PATH_PLUGINCONFIG = "META-INF/scm/plugin.xml";
/** Field description */
/** the logger for DefaultPluginManager */
private static final Logger logger =
LoggerFactory.getLogger(SCMPluginManager.class);
LoggerFactory.getLogger(DefaultPluginManager.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
public DefaultPluginManager()
{
ClassLoader classLoader = getClassLoader();
try
{
load(classLoader);
}
catch (IOException ex)
{
throw new RuntimeException(ex);
}
}
//~--- methods --------------------------------------------------------------
@@ -68,19 +101,63 @@ public class SCMPluginManager
* Method description
*
*
* @throws IOException
* @param processor
*/
public void load() throws IOException
@Override
public void processExtensions(ExtensionProcessor processor)
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Set<ExtensionObject> extensions = new HashSet<ExtensionObject>();
ClassLoader classLoader = getClassLoader();
JARExtensionScanner scanner = new JARExtensionScanner();
if (classLoader == null)
for (Plugin plugin : plugins)
{
classLoader = SCMPluginManager.class.getClassLoader();
InputStream input = null;
try
{
Set<String> packageSet = plugin.getPackageSet();
if (packageSet == null)
{
packageSet = new HashSet<String>();
}
load(classLoader);
packageSet.add(DEFAULT_PACKAGE);
input = new FileInputStream(plugin.getPath());
scanner.processExtensions(classLoader, extensions, input, packageSet);
}
catch (IOException ex)
{
logger.error(ex.getMessage(), ex);
}
finally
{
IOUtil.close(input);
}
}
for (ExtensionObject exo : extensions)
{
processor.processExtension(exo.getExtension(), exo.getExtensionClass());
}
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public Collection<Plugin> getPlugins()
{
return plugins;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
@@ -90,7 +167,7 @@ public class SCMPluginManager
*
* @throws IOException
*/
public void load(ClassLoader classLoader) throws IOException
private void load(ClassLoader classLoader) throws IOException
{
Enumeration<URL> urlEnum = classLoader.getResources(PATH_PLUGINCONFIG);
@@ -105,21 +182,6 @@ public class SCMPluginManager
}
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public Set<SCMPlugin> getPlugins()
{
return plugins;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
@@ -130,13 +192,20 @@ public class SCMPluginManager
{
try
{
SCMPlugin plugin = JAXB.unmarshal(url, SCMPlugin.class);
// jar:file:/some/path/file.jar!/META-INF/scm/plugin.xml
String path = url.toExternalForm();
path = path.substring("jar:file:".length(), path.lastIndexOf("!"));
if (logger.isInfoEnabled())
{
logger.info("load plugin {}", url.toExternalForm());
logger.info("load plugin {}", path);
}
Plugin plugin = JAXB.unmarshal(url, Plugin.class);
plugin.setPath(path);
plugins.add(plugin);
}
catch (Exception ex)
@@ -145,8 +214,28 @@ public class SCMPluginManager
}
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
private ClassLoader getClassLoader()
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null)
{
classLoader = DefaultPluginManager.class.getClassLoader();
}
return classLoader;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Set<SCMPlugin> plugins = new LinkedHashSet<SCMPlugin>();
private Set<Plugin> plugins = new HashSet<Plugin>();
}

View File

@@ -31,15 +31,12 @@
package sonia.scm.web.plugin;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.repository.RepositoryHandler;
package sonia.scm.plugin;
//~--- JDK imports ------------------------------------------------------------
import java.util.HashSet;
import java.net.URL;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
@@ -47,36 +44,26 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author Sebastian Sdorra
*/
@XmlRootElement(name = "plugin-config")
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class SCMPlugin
public class Plugin
{
/**
* Constructs ...
*
*/
public SCMPlugin()
{
repositoryHandlers = new HashSet<Class<? extends RepositoryHandler>>();
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public Set<Class<? extends RepositoryHandler>> getRepositoryHandlers()
public PluginInformation getInformation()
{
return repositoryHandlers;
return information;
}
/**
@@ -85,9 +72,9 @@ public class SCMPlugin
*
* @return
*/
public SecurityConfig getSecurityConfig()
public Set<String> getPackageSet()
{
return securityConfig;
return packageSet;
}
/**
@@ -96,9 +83,20 @@ public class SCMPlugin
*
* @return
*/
public Class<? extends ScmWebPlugin> getWebPlugin()
public String getPath()
{
return webPlugin;
return path;
}
/**
* Method description
*
*
* @return
*/
public PluginResources getResources()
{
return resources;
}
//~--- set methods ----------------------------------------------------------
@@ -107,48 +105,60 @@ public class SCMPlugin
* Method description
*
*
* @param repositoryHandlers
* @param information
*/
public void setRepositoryHandlers(
Set<Class<? extends RepositoryHandler>> repositoryHandlers)
public void setInformation(PluginInformation information)
{
this.repositoryHandlers = repositoryHandlers;
this.information = information;
}
/**
* Method description
*
*
* @param securityConfig
* @param packageSet
*/
public void setSecurityConfig(SecurityConfig securityConfig)
public void setPackageSet(Set<String> packageSet)
{
this.securityConfig = securityConfig;
this.packageSet = packageSet;
}
/**
* Method description
*
*
* @param webPlugin
* @param path
*/
public void setWebPlugin(Class<? extends ScmWebPlugin> webPlugin)
public void setPath(String path)
{
this.webPlugin = webPlugin;
this.path = path;
}
/**
* Method description
*
*
* @param resources
*/
public void setResources(PluginResources resources)
{
this.resources = resources;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
@XmlElementWrapper(name = "repository-handlers")
@XmlElement(name = "repository-handler")
private Set<Class<? extends RepositoryHandler>> repositoryHandlers;
private PluginInformation information;
/** Field description */
@XmlElement(name = "security")
private SecurityConfig securityConfig;
@XmlElement(name = "package")
@XmlElementWrapper(name = "packages")
private Set<String> packageSet;
/** Field description */
@XmlElement(name = "web-plugin")
private Class<? extends ScmWebPlugin> webPlugin;
@XmlTransient
private String path;
/** Field description */
private PluginResources resources;
}

View File

@@ -29,95 +29,26 @@
*
*/
package sonia.scm.web.plugin;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Module;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.servlet.ServletContext;
package sonia.scm.plugin;
/**
*
* @author Sebastian Sdorra
*/
public class ScmWebPluginContext
public class PluginInformation
{
/**
* Constructs ...
*
*
* @param servletContext
*/
public ScmWebPluginContext(ServletContext servletContext)
{
this.servletContext = servletContext;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param module
*/
public void addInjectModule(Module module)
{
injectModules.add(module);
}
/**
* Method description
*
*
* @param resource
*/
public void addScriptResource(WebResource resource)
{
scriptResources.add(resource);
}
/**
* Method description
*
*
* @param module
*/
public void removeInjectModule(Module module)
{
injectModules.remove(module);
}
/**
* Method description
*
*
* @param resource
*/
public void removeScriptResource(WebResource resource)
{
scriptResources.remove(resource);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public Collection<Module> getInjectModules()
public String getAuthor()
{
return injectModules;
return author;
}
/**
@@ -126,9 +57,9 @@ public class ScmWebPluginContext
*
* @return
*/
public Collection<WebResource> getScriptResources()
public String getDescription()
{
return scriptResources;
return description;
}
/**
@@ -137,19 +68,104 @@ public class ScmWebPluginContext
*
* @return
*/
public ServletContext getServletContext()
public String getName()
{
return servletContext;
return name;
}
/**
* Method description
*
*
* @return
*/
public String getUrl()
{
return url;
}
/**
* Method description
*
*
* @return
*/
public String getVersion()
{
return version;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param author
*/
public void setAuthor(String author)
{
this.author = author;
}
/**
* Method description
*
*
* @param description
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* Method description
*
*
* @param name
*/
public void setName(String name)
{
this.name = name;
}
/**
* Method description
*
*
* @param url
*/
public void setUrl(String url)
{
this.url = url;
}
/**
* Method description
*
*
* @param version
*/
public void setVersion(String version)
{
this.version = version;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Set<WebResource> scriptResources = new HashSet<WebResource>();
private String author;
/** Field description */
private Set<Module> injectModules = new HashSet<Module>();
private String description;
/** Field description */
private ServletContext servletContext;
private String name;
/** Field description */
private String url;
/** Field description */
private String version;
}

View File

@@ -35,39 +35,36 @@ package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.web.plugin.WebResource;
import com.google.inject.Binder;
//~--- JDK imports ------------------------------------------------------------
import java.io.Serializable;
import java.util.Comparator;
import java.util.Collection;
import sonia.scm.plugin.ext.ExtensionProcessor;
/**
*
* @author Sebastian Sdorra
*/
public class WebResourceComparator
implements Comparator<WebResource>, Serializable
public interface PluginManager
{
/** Field description */
private static final long serialVersionUID = -5916499507958881372L;
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param resource
* @param resource1
* @param binder
*/
public void processExtensions(ExtensionProcessor processor);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public int compare(WebResource resource, WebResource resource1)
{
return resource.getId().compareTo(resource1.getId());
}
public Collection<Plugin> getPlugins();
}

View File

@@ -29,15 +29,14 @@
*
*/
package sonia.scm.web.plugin;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.security.EncryptionHandler;
import sonia.scm.web.security.Authenticator;
package sonia.scm.plugin;
//~--- JDK imports ------------------------------------------------------------
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
@@ -46,8 +45,8 @@ import javax.xml.bind.annotation.XmlElement;
*
* @author Sebastian Sdorra
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class SecurityConfig
@XmlAccessorType(XmlAccessType.NONE)
public class PluginResources
{
/**
@@ -56,9 +55,9 @@ public class SecurityConfig
*
* @return
*/
public Class<? extends Authenticator> getAuthenticator()
public Set<String> getScriptResources()
{
return authenticator;
return scriptResources;
}
/**
@@ -67,9 +66,9 @@ public class SecurityConfig
*
* @return
*/
public Class<? extends EncryptionHandler> getEncryptionHandler()
public Set<String> getStylesheetResources()
{
return encryptionHandler;
return stylesheetResources;
}
//~--- set methods ----------------------------------------------------------
@@ -78,32 +77,31 @@ public class SecurityConfig
* Method description
*
*
* @param authenticator
* @param scriptResources
*/
public void setAuthenticator(Class<? extends Authenticator> authenticator)
public void setScriptResources(Set<String> scriptResources)
{
this.authenticator = authenticator;
this.scriptResources = scriptResources;
}
/**
* Method description
*
*
* @param encryptionHandler
* @param stylesheetResources
*/
public void setEncryptionHandler(
Class<? extends EncryptionHandler> encryptionHandler)
public void setStylesheetResources(Set<String> stylesheetResources)
{
this.encryptionHandler = encryptionHandler;
this.stylesheetResources = stylesheetResources;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
@XmlElement(name = "authenticator")
private Class<? extends Authenticator> authenticator;
@XmlElement(name = "script")
private Set<String> scriptResources;
/** Field description */
@XmlElement(name = "encryption-handler")
private Class<? extends EncryptionHandler> encryptionHandler;
@XmlElement(name = "stylesheet")
private Set<String> stylesheetResources;
}

View File

@@ -31,35 +31,21 @@
package sonia.scm.web.plugin;
package sonia.scm.plugin.ext;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
*
* @author Sebastian Sdorra
*/
public interface WebResource
{
/**
* Method description
*
*
* @return
*
* @throws IOException
*/
public InputStream getContent() throws IOException;
/**
* Method description
*
*
* @return
*/
public String getId();
}
@Documented
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface Extension {}

View File

@@ -31,28 +31,26 @@
package sonia.scm.web.plugin;
//~--- JDK imports ------------------------------------------------------------
import java.io.InputStream;
package sonia.scm.plugin.ext;
/**
*
* @author Sebastian Sdorra
*/
public class ClasspathWebResource implements WebResource
public class ExtensionObject
{
/**
* Constructs ...
*
*
* @param contentPath
* @param extension
* @param extensionClass
*/
public ClasspathWebResource(String contentPath)
public ExtensionObject(Extension extension, Class<?> extensionClass)
{
this.contentPath = contentPath;
this.extension = extension;
this.extensionClass = extensionClass;
}
//~--- get methods ----------------------------------------------------------
@@ -63,10 +61,9 @@ public class ClasspathWebResource implements WebResource
*
* @return
*/
@Override
public InputStream getContent()
public Extension getExtension()
{
return ClasspathWebResource.class.getResourceAsStream(contentPath);
return extension;
}
/**
@@ -75,14 +72,16 @@ public class ClasspathWebResource implements WebResource
*
* @return
*/
@Override
public String getId()
public Class<?> getExtensionClass()
{
return contentPath;
return extensionClass;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String contentPath;
private Extension extension;
/** Field description */
private Class<?> extensionClass;
}

View File

@@ -29,28 +29,23 @@
*
*/
package sonia.scm.web.plugin;
package sonia.scm.plugin.ext;
/**
*
* @author Sebastian Sdorra
*/
public interface ScmWebPlugin
public interface ExtensionProcessor
{
/**
* Method description
*
*
* @param context
* @param extension
* @param extensionClass
*/
public void contextDestroyed(ScmWebPluginContext context);
/**
* Method description
*
*
* @param context
*/
public void contextInitialized(ScmWebPluginContext context);
public void processExtension(Extension extension, Class<?> extensionClass);
}

View File

@@ -0,0 +1,66 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.plugin.ext;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
/**
*
* @author Sebastian Sdorra
*/
public interface ExtensionScanner
{
/**
* Method description
*
*
*
* @param classLoader
* @param extensionObjects
* @param input
* @param packagess
*
* @throws IOException
*/
public void processExtensions(ClassLoader classLoader,
Collection<ExtensionObject> extensionObjects,
InputStream input, Collection<String> packagess)
throws IOException;
}

View File

@@ -0,0 +1,228 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.plugin.ext;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
/**
*
* @author Sebastian Sdorra
*/
public class JARExtensionScanner implements ExtensionScanner
{
/** the logger for JARExtensionScanner */
private static final Logger logger =
LoggerFactory.getLogger(JARExtensionScanner.class);
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
*
* @param classLoader
* @param extensionObjects
* @param inputStream
* @param packages
*
* @throws IOException
*/
@Override
public void processExtensions(ClassLoader classLoader,
Collection<ExtensionObject> extensionObjects,
InputStream inputStream,
Collection<String> packages)
throws IOException
{
JarInputStream input = null;
try
{
input = new JarInputStream(inputStream);
JarEntry entry = input.getNextJarEntry();
while (entry != null)
{
if (!entry.isDirectory())
{
processEntry(classLoader, extensionObjects, packages, entry);
}
entry = input.getNextJarEntry();
}
}
finally
{
IOUtil.close(input);
}
}
/**
* Method description
*
*
* @param classLoader
* @param name
*
* @return
*/
private Class<?> createClass(ClassLoader classLoader, String name)
{
Class<?> clazz = null;
try
{
clazz = classLoader.loadClass(name);
}
catch (Exception ex)
{
logger.error(ex.getMessage(), ex);
}
return clazz;
}
/**
* Method description
*
*
*
* @param classLoader
* @param extensionObjects
* @param packages
* @param entry
*/
private void processEntry(ClassLoader classLoader,
Collection<ExtensionObject> extensionObjects,
Collection<String> packages, JarEntry entry)
{
String name = entry.getName();
if (name.endsWith(".class"))
{
name = getClassName(name);
if (isManagedClass(packages, name))
{
Class<?> managedClass = createClass(classLoader, name);
if (managedClass != null)
{
processManagedClass(extensionObjects, managedClass);
}
}
}
}
/**
* Method description
*
*
* @param extensionObjects
* @param managedClass
*/
private void processManagedClass(
Collection<ExtensionObject> extensionObjects, Class<?> managedClass)
{
Extension extension = managedClass.getAnnotation(Extension.class);
if (extension != null)
{
if (logger.isDebugEnabled())
{
logger.debug("found extension class {}", managedClass.getName());
}
extensionObjects.add(new ExtensionObject(extension, managedClass));
}
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param name
*
* @return
*/
private String getClassName(String name)
{
return name.replaceAll("/", ".").substring(0, name.length() - 6);
}
/**
* Method description
*
*
* @param packages
* @param name
*
* @return
*/
private boolean isManagedClass(Collection<String> packages, String name)
{
boolean result = false;
for (String pkg : packages)
{
if (name.startsWith(pkg))
{
result = true;
break;
}
}
return result;
}
}

View File

@@ -0,0 +1,226 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.multibindings.Multibinder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.plugin.ext.Extension;
import sonia.scm.plugin.ext.ExtensionProcessor;
import sonia.scm.repository.RepositoryHandler;
import sonia.scm.security.EncryptionHandler;
import sonia.scm.web.security.Authenticator;
//~--- JDK imports ------------------------------------------------------------
import java.util.HashSet;
import java.util.Set;
/**
*
* @author Sebastian Sdorra
*/
public class BindingExtensionProcessor implements ExtensionProcessor
{
/** the logger for BindingExtensionProcessor */
private static final Logger logger =
LoggerFactory.getLogger(BindingExtensionProcessor.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
*/
public BindingExtensionProcessor()
{
this.moduleSet = new HashSet<Module>();
this.extensions = new HashSet<Class<?>>();
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param binder
*/
@SuppressWarnings("unchecked")
public void bindExtensions(Binder binder)
{
Multibinder<RepositoryHandler> repositoryHandlers =
Multibinder.newSetBinder(binder, RepositoryHandler.class);
for (Class extensionClass : extensions)
{
try
{
if (RepositoryHandler.class.isAssignableFrom(extensionClass))
{
if (logger.isInfoEnabled())
{
logger.info("bind RepositoryHandler {}", extensionClass.getName());
}
binder.bind(extensionClass);
repositoryHandlers.addBinding().to(extensionClass);
}
else if (EncryptionHandler.class.isAssignableFrom(extensionClass))
{
bind(binder, EncryptionHandler.class, extensionClass);
}
else if (Authenticator.class.isAssignableFrom(extensionClass))
{
bind(binder, Authenticator.class, extensionClass);
}
else
{
if (logger.isInfoEnabled())
{
logger.info("bind {}", extensionClass.getName());
}
binder.bind(extensionClass);
}
}
catch (Exception ex)
{
logger.error(ex.getMessage(), ex);
}
}
}
/**
* Method description
*
*
* @param extension
* @param extensionClass
*/
@Override
public void processExtension(Extension extension, Class extensionClass)
{
if (Module.class.isAssignableFrom(extensionClass))
{
if (logger.isInfoEnabled())
{
logger.info("add GuiceModule {}", extensionClass.getName());
}
addModuleClass(extensionClass);
}
else
{
extensions.add(extensionClass);
}
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public Set<Module> getModuleSet()
{
return moduleSet;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param extensionClass
*/
private void addModuleClass(Class<? extends Module> extensionClass)
{
try
{
Module module = extensionClass.newInstance();
moduleSet.add(module);
}
catch (Exception ex)
{
logger.error(ex.getMessage(), ex);
}
}
/**
* Method description
*
*
*
* @param binder
* @param type
* @param bindingType
* @param <T>
*
* @return
*/
private <T> void bind(Binder binder, Class<T> type,
Class<? extends T> bindingType)
{
if (logger.isDebugEnabled())
{
logger.debug("bind Authenticator {}", type.getName(),
bindingType.getName());
}
binder.bind(type).to(bindingType);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Set<Class<?>> extensions;
/** Field description */
private Set<Module> moduleSet;
}

View File

@@ -40,29 +40,16 @@ import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.servlet.GuiceServletContextListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.plugin.DefaultPluginManager;
import sonia.scm.plugin.PluginManager;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.user.UserManager;
import sonia.scm.util.Util;
import sonia.scm.web.plugin.SCMPlugin;
import sonia.scm.web.plugin.SCMPluginManager;
import sonia.scm.web.plugin.ScmWebPlugin;
import sonia.scm.web.plugin.ScmWebPluginContext;
import sonia.scm.web.security.Authenticator;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.servlet.ServletContextEvent;
/**
*
@@ -71,77 +58,6 @@ import javax.servlet.ServletContextEvent;
public class ContextListener extends GuiceServletContextListener
{
/** the logger for ContextListener */
private static final Logger logger =
LoggerFactory.getLogger(ContextListener.class);
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param servletContextEvent
*/
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent)
{
for (ScmWebPlugin plugin : webPluginSet)
{
plugin.contextDestroyed(webPluginContext);
}
super.contextDestroyed(servletContextEvent);
}
/**
* Method description
*
*
* @param servletContextEvent
*/
@Override
public void contextInitialized(ServletContextEvent servletContextEvent)
{
pluginManager = new SCMPluginManager();
try
{
pluginManager.load();
webPluginContext =
new ScmWebPluginContext(servletContextEvent.getServletContext());
for (SCMPlugin plugin : pluginManager.getPlugins())
{
try
{
webPluginSet.add(plugin.getWebPlugin().newInstance());
}
catch (InstantiationException ex)
{
logger.error(ex.getMessage(), ex);
}
catch (IllegalAccessException ex)
{
logger.error(ex.getMessage(), ex);
}
}
for (ScmWebPlugin plugin : webPluginSet)
{
plugin.contextInitialized(webPluginContext);
}
}
catch (IOException ex)
{
throw new RuntimeException(ex);
}
super.contextInitialized(servletContextEvent);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
@@ -151,18 +67,19 @@ public class ContextListener extends GuiceServletContextListener
@Override
protected Injector getInjector()
{
List<Module> modules = new ArrayList<Module>();
PluginManager manager = new DefaultPluginManager();
BindingExtensionProcessor bindExtProcessor =
new BindingExtensionProcessor();
modules.add(new ScmServletModule(pluginManager, webPluginContext));
manager.processExtensions(bindExtProcessor);
Collection<Module> pluginModules = webPluginContext.getInjectModules();
ScmServletModule main = new ScmServletModule(manager, bindExtProcessor);
List<Module> moduleList =
new ArrayList<Module>(bindExtProcessor.getModuleSet());
if (Util.isNotEmpty(pluginModules))
{
modules.addAll(pluginModules);
}
moduleList.add(0, main);
Injector injector = Guice.createInjector(modules);
Injector injector = Guice.createInjector(moduleList);
// init RepositoryManager
injector.getInstance(RepositoryManager.class).init(SCMContext.getContext());
@@ -175,15 +92,4 @@ public class ContextListener extends GuiceServletContextListener
return injector;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private SCMPluginManager pluginManager;
/** Field description */
private ScmWebPluginContext webPluginContext;
/** Field description */
private Set<ScmWebPlugin> webPluginSet = new LinkedHashSet<ScmWebPlugin>();
}

View File

@@ -35,7 +35,6 @@ package sonia.scm;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.multibindings.Multibinder;
import com.google.inject.servlet.ServletModule;
import org.slf4j.Logger;
@@ -46,20 +45,16 @@ import sonia.scm.cache.CacheManager;
import sonia.scm.cache.EhCacheManager;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.filter.SecurityFilter;
import sonia.scm.plugin.PluginManager;
import sonia.scm.plugin.ScriptResourceServlet;
import sonia.scm.repository.RepositoryHandler;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.repository.xml.XmlRepositoryManager;
import sonia.scm.security.EncryptionHandler;
import sonia.scm.security.MessageDigestEncryptionHandler;
import sonia.scm.security.SecurityContext;
import sonia.scm.user.UserManager;
import sonia.scm.user.xml.XmlUserManager;
import sonia.scm.util.DebugServlet;
import sonia.scm.util.Util;
import sonia.scm.web.plugin.SCMPlugin;
import sonia.scm.web.plugin.SCMPluginManager;
import sonia.scm.web.plugin.ScmWebPluginContext;
import sonia.scm.web.plugin.SecurityConfig;
import sonia.scm.web.security.Authenticator;
import sonia.scm.web.security.BasicSecurityContext;
import sonia.scm.web.security.WebSecurityContext;
@@ -74,14 +69,10 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import javax.xml.bind.JAXB;
import sonia.scm.security.SecurityContext;
/**
*
@@ -131,15 +122,14 @@ public class ScmServletModule extends ServletModule
* Constructs ...
*
*
*
* @param pluginManager
* @param webPluginContext
* @param manager
* @param bindExtProcessor
*/
ScmServletModule(SCMPluginManager pluginManager,
ScmWebPluginContext webPluginContext)
ScmServletModule(PluginManager manager,
BindingExtensionProcessor bindExtProcessor)
{
this.pluginManager = pluginManager;
this.webPluginContext = webPluginContext;
this.pluginManager = manager;
this.bindExtProcessor = bindExtProcessor;
}
//~--- methods --------------------------------------------------------------
@@ -158,19 +148,18 @@ public class ScmServletModule extends ServletModule
ScmConfiguration config = getScmConfiguration(context);
bind(ScmConfiguration.class).toInstance(config);
// bind(EncryptionHandler.class).to(MessageDigestEncryptionHandler.class);
// bind(Authenticator.class).to(XmlAuthenticator.class);
bind(PluginManager.class).toInstance(pluginManager);
bind(EncryptionHandler.class).to(MessageDigestEncryptionHandler.class);
bind(Authenticator.class).to(XmlAuthenticator.class);
bind(SecurityContext.class).to(BasicSecurityContext.class);
bind(WebSecurityContext.class).to(BasicSecurityContext.class);
loadPlugins(pluginManager);
bindExtProcessor.bindExtensions(binder());
bind(CacheManager.class).to(EhCacheManager.class);
// bind(RepositoryManager.class).annotatedWith(Undecorated.class).to(
// BasicRepositoryManager.class);
bind(RepositoryManager.class).to(XmlRepositoryManager.class);
bind(UserManager.class).to(XmlUserManager.class);
bind(ScmWebPluginContext.class).toInstance(webPluginContext);
// filter(PATTERN_RESTAPI).through(LoggingFilter.class);
@@ -206,91 +195,6 @@ public class ScmServletModule extends ServletModule
serve(PATTERN_RESTAPI).with(GuiceContainer.class, params);
}
/**
* Method description
*
*
* @param repositoryHandlerBinder
* @param handlerSet
*/
private void bindRepositoryHandlers(
Multibinder<RepositoryHandler> repositoryHandlerBinder,
Set<Class<? extends RepositoryHandler>> handlerSet)
{
for (Class<? extends RepositoryHandler> handlerClass : handlerSet)
{
if (logger.isInfoEnabled())
{
logger.info("load RepositoryHandler {}", handlerClass.getName());
}
bind(handlerClass);
repositoryHandlerBinder.addBinding().to(handlerClass);
}
}
/**
* Method description
*
*
* @param pluginManager
*/
private void loadPlugins(SCMPluginManager pluginManager)
{
Set<SCMPlugin> pluginSet = pluginManager.getPlugins();
if (Util.isNotEmpty(pluginSet))
{
// repository handlers
Multibinder<RepositoryHandler> repositoryHandlerBinder =
Multibinder.newSetBinder(binder(), RepositoryHandler.class);
Set<Class<? extends RepositoryHandler>> repositoryHandlerSet =
new LinkedHashSet<Class<? extends RepositoryHandler>>();
// security stuff
Class<? extends EncryptionHandler> encryptionHandler =
MessageDigestEncryptionHandler.class;
Class<? extends Authenticator> authenticator = XmlAuthenticator.class;
for (SCMPlugin plugin : pluginSet)
{
Collection<Class<? extends RepositoryHandler>> pluginRepositoryHandlers =
plugin.getRepositoryHandlers();
if (Util.isNotEmpty(pluginRepositoryHandlers))
{
repositoryHandlerSet.addAll(pluginRepositoryHandlers);
}
SecurityConfig securityConfig = plugin.getSecurityConfig();
if (securityConfig != null)
{
Class<? extends EncryptionHandler> enc =
securityConfig.getEncryptionHandler();
if (enc != null)
{
encryptionHandler = enc;
}
Class<? extends Authenticator> auth =
securityConfig.getAuthenticator();
if (auth != null)
{
authenticator = auth;
}
}
}
bind(EncryptionHandler.class).to(encryptionHandler);
bind(Authenticator.class).to(authenticator);
bindRepositoryHandlers(repositoryHandlerBinder, repositoryHandlerSet);
}
}
//~--- get methods ----------------------------------------------------------
/**
@@ -329,8 +233,8 @@ public class ScmServletModule extends ServletModule
//~--- fields ---------------------------------------------------------------
/** Field description */
private SCMPluginManager pluginManager;
private BindingExtensionProcessor bindExtProcessor;
/** Field description */
private ScmWebPluginContext webPluginContext;
private PluginManager pluginManager;
}

View File

@@ -212,6 +212,11 @@ public class RepositoryResource extends AbstractResource<Repository>
* @param repository
*/
private void appendUrl(Repository repository)
{
RepositoryHandler handler =
repositoryManager.getHandler(repository.getType());
if (handler != null)
{
StringBuilder url = new StringBuilder(request.getScheme());
@@ -226,13 +231,10 @@ public class RepositoryResource extends AbstractResource<Repository>
}
url.append(ctxPath);
RepositoryHandler handler =
repositoryManager.getHandler(repository.getType());
url.append(handler.createResourcePath(repository));
repository.setUrl(url.toString());
}
}
//~--- fields ---------------------------------------------------------------

View File

@@ -40,8 +40,6 @@ import com.google.inject.Singleton;
import sonia.scm.util.IOUtil;
import sonia.scm.util.Util;
import sonia.scm.web.plugin.ScmWebPluginContext;
import sonia.scm.web.plugin.WebResource;
//~--- JDK imports ------------------------------------------------------------
@@ -49,10 +47,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import javax.servlet.ServletException;
@@ -70,6 +67,20 @@ public class ScriptResourceServlet extends AbstractResourceServlet
/** Field description */
private static final long serialVersionUID = -5769146163848821050L;
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param manager
*/
@Inject
public ScriptResourceServlet(PluginManager manager)
{
this.manager = manager;
}
//~--- methods --------------------------------------------------------------
/**
@@ -89,19 +100,13 @@ public class ScriptResourceServlet extends AbstractResourceServlet
"function sayPluginHello(){ alert('Plugin Hello !'); }".concat(
System.getProperty("line.separator")).getBytes());
Collection<WebResource> scriptResources =
webPluginContext.getScriptResources();
Collection<String> scriptResources = getScriptResources();
if (Util.isNotEmpty(scriptResources))
{
List<WebResource> resourceList =
new ArrayList<WebResource>(scriptResources);
Collections.sort(resourceList, new WebResourceComparator());
for (WebResource scriptResource : resourceList)
for (String resource : scriptResources)
{
appendResource(stream, scriptResource);
appendResource(stream, resource);
}
}
}
@@ -132,10 +137,10 @@ public class ScriptResourceServlet extends AbstractResourceServlet
* @throws IOException
* @throws ServletException
*/
private void appendResource(OutputStream stream, WebResource script)
private void appendResource(OutputStream stream, String script)
throws ServletException, IOException
{
InputStream input = script.getContent();
InputStream input = ScriptResourceServlet.class.getResourceAsStream(script);
if (input != null)
{
@@ -150,9 +155,54 @@ public class ScriptResourceServlet extends AbstractResourceServlet
}
}
/**
* Method description
*
*
* @param resources
* @param plugin
*/
private void processPlugin(Set<String> resources, Plugin plugin)
{
PluginResources pluginResources = plugin.getResources();
if (pluginResources != null)
{
Set<String> scriptResources = pluginResources.getScriptResources();
if (scriptResources != null)
{
resources.addAll(scriptResources);
}
}
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
private Collection<String> getScriptResources()
{
Set<String> resources = new TreeSet<String>();
Collection<Plugin> plugins = manager.getPlugins();
if (plugins != null)
{
for (Plugin plugin : plugins)
{
processPlugin(resources, plugin);
}
}
return resources;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
@Inject
private ScmWebPluginContext webPluginContext;
private PluginManager manager;
}