mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
improve ScmWebPlugin api
This commit is contained in:
@@ -14,14 +14,19 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
|
||||
import sonia.scm.util.ServiceUtil;
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.web.ScmWebPlugin;
|
||||
import sonia.scm.web.ScmWebPluginContext;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -29,18 +34,47 @@ import java.util.List;
|
||||
public class ContextListener extends GuiceServletContextListener
|
||||
{
|
||||
|
||||
/*
|
||||
* @Override
|
||||
* public void contextInitialized(ServletContextEvent servletContextEvent)
|
||||
* {
|
||||
* Logger logger = Logger.getLogger("");
|
||||
* logger.setLevel(Level.ALL);
|
||||
* ConsoleHandler handler = new ConsoleHandler();
|
||||
* handler.setLevel(Level.ALL);
|
||||
* logger.addHandler( handler );
|
||||
* super.contextInitialized(servletContextEvent);
|
||||
* }
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param servletContextEvent
|
||||
*/
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent servletContextEvent)
|
||||
{
|
||||
List<ScmWebPlugin> plugins = ServiceUtil.getServices(ScmWebPlugin.class);
|
||||
|
||||
for (ScmWebPlugin plugin : plugins)
|
||||
{
|
||||
plugin.contextDestroyed(webPluginContext);
|
||||
}
|
||||
|
||||
super.contextDestroyed(servletContextEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param servletContextEvent
|
||||
*/
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent servletContextEvent)
|
||||
{
|
||||
webPluginContext = new ScmWebPluginContext();
|
||||
|
||||
List<ScmWebPlugin> plugins = ServiceUtil.getServices(ScmWebPlugin.class);
|
||||
|
||||
for (ScmWebPlugin plugin : plugins)
|
||||
{
|
||||
plugin.contextInitialized(webPluginContext);
|
||||
}
|
||||
|
||||
super.contextInitialized(servletContextEvent);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -51,25 +85,22 @@ public class ContextListener extends GuiceServletContextListener
|
||||
@Override
|
||||
protected Injector getInjector()
|
||||
{
|
||||
ScmWebPluginContext webPluginContext = new ScmWebPluginContext();
|
||||
List<ScmWebPlugin> plugins = webPluginContext.getPlugins();
|
||||
List<Module> modules = new ArrayList<Module>();
|
||||
|
||||
modules.add(new ScmServletModule(webPluginContext));
|
||||
|
||||
if (Util.isNotEmpty(plugins))
|
||||
{
|
||||
for (ScmWebPlugin plugin : plugins)
|
||||
{
|
||||
Module[] moduleArray = plugin.getModules();
|
||||
Collection<Module> pluginModules = webPluginContext.getInjectModules();
|
||||
|
||||
if (Util.isNotEmpty(moduleArray))
|
||||
{
|
||||
modules.addAll(Arrays.asList(moduleArray));
|
||||
}
|
||||
}
|
||||
if (Util.isNotEmpty(pluginModules))
|
||||
{
|
||||
modules.addAll(pluginModules);
|
||||
}
|
||||
|
||||
return Guice.createInjector(modules);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private ScmWebPluginContext webPluginContext;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import sonia.scm.plugin.ScriptResourceServlet;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.security.Authenticator;
|
||||
import sonia.scm.security.DemoAuthenticator;
|
||||
import sonia.scm.web.ScmWebPluginContext;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -12,9 +12,10 @@ package sonia.scm.plugin;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.ScmWebPlugin;
|
||||
import sonia.scm.ScmWebPluginContext;
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.web.ScmWebPlugin;
|
||||
import sonia.scm.web.ScmWebPluginContext;
|
||||
import sonia.scm.web.WebResource;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -23,6 +24,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
@@ -60,13 +62,14 @@ public class ScriptResourceServlet extends AbstractResourceServlet
|
||||
"function sayPluginHello(){ alert('Plugin Hello !'); }".concat(
|
||||
System.getProperty("line.separator")).getBytes());
|
||||
|
||||
List<ScmWebPlugin> plugins = webPluginContext.getPlugins();
|
||||
Collection<WebResource> scriptResources =
|
||||
webPluginContext.getScriptResources();
|
||||
|
||||
if (Util.isNotEmpty(plugins))
|
||||
if (Util.isNotEmpty(scriptResources))
|
||||
{
|
||||
for (ScmWebPlugin plugin : plugins)
|
||||
for (WebResource scriptResource : scriptResources)
|
||||
{
|
||||
appendResource(stream, plugin);
|
||||
appendResource(stream, scriptResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,15 +95,15 @@ public class ScriptResourceServlet extends AbstractResourceServlet
|
||||
*
|
||||
*
|
||||
* @param stream
|
||||
* @param plugin
|
||||
* @param script
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ServletException
|
||||
*/
|
||||
private void appendResource(OutputStream stream, ScmWebPlugin plugin)
|
||||
private void appendResource(OutputStream stream, WebResource script)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
InputStream input = plugin.getScript();
|
||||
InputStream input = script.getContent();
|
||||
|
||||
if (input != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user