implemented a child first plugin classloader strategy

This commit is contained in:
Sebastian Sdorra
2013-03-13 20:51:44 +01:00
parent 15906a7e62
commit 19c48f0a6c
3 changed files with 252 additions and 7 deletions

View File

@@ -35,11 +35,20 @@ package sonia.scm.boot;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.net.ChildFirstURLClassLoader;
//~--- JDK imports ------------------------------------------------------------
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;
import javax.servlet.ServletContext;
/**
@@ -52,6 +61,16 @@ public final class BootstrapUtil
/** Field description */
public static final String CLASSLOADER = "sonia.scm.BoostrapClassLoader";
/** Field description */
private static final String STRATEGY =
"sonia.scm.plugin.classloader.strategy";
/** Field description */
private static final String STRATEGY_CHILDFIRST = "child-first";
/** Field description */
private static final String STRATEGY_PARENTFIRST = "parent-first";
/** the logger for BootstrapUtil */
private static final Logger logger =
LoggerFactory.getLogger(BootstrapUtil.class);
@@ -66,6 +85,46 @@ public final class BootstrapUtil
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param classpathURLs
* @param parent
*
* @return
*/
public static ClassLoader createClassLoader(List<URL> classpathURLs,
ClassLoader parent)
{
ClassLoader classLoader = null;
URL[] urls = classpathURLs.toArray(new URL[classpathURLs.size()]);
String strategy = System.getProperty(STRATEGY);
if (!Strings.isNullOrEmpty(strategy))
{
if (STRATEGY_CHILDFIRST.equals(strategy))
{
logger.info("using {} as plugin classloading strategy",
STRATEGY_CHILDFIRST);
classLoader = new ChildFirstURLClassLoader(urls, parent);
}
else if (!STRATEGY_PARENTFIRST.equals(strategy))
{
logger.warn("unknown plugin classloading strategy {}", strategy);
}
}
if (classLoader == null)
{
logger.info("using {} as plugin classloading strategy",
STRATEGY_PARENTFIRST);
classLoader = new URLClassLoader(urls, parent);
}
return classLoader;
}
/**
* Method description
*