mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
implemented a child first plugin classloader strategy
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user