mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
template engine has to use UberClassLoader
This commit is contained in:
@@ -46,6 +46,8 @@ import com.google.inject.Inject;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.plugin.PluginLoader;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -84,11 +86,13 @@ public class MustacheTemplateEngine implements TemplateEngine
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param context
|
* @param context
|
||||||
|
* @param pluginLoader
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public MustacheTemplateEngine(ServletContext context)
|
public MustacheTemplateEngine(ServletContext context,
|
||||||
|
PluginLoader pluginLoader)
|
||||||
{
|
{
|
||||||
factory = new ServletMustacheFactory(context);
|
factory = new ServletMustacheFactory(context, pluginLoader);
|
||||||
|
|
||||||
ThreadFactory threadFactory =
|
ThreadFactory threadFactory =
|
||||||
new ThreadFactoryBuilder().setNameFormat(THREAD_NAME).build();
|
new ThreadFactoryBuilder().setNameFormat(THREAD_NAME).build();
|
||||||
@@ -168,11 +172,7 @@ public class MustacheTemplateEngine implements TemplateEngine
|
|||||||
{
|
{
|
||||||
logger.warn("could not find mustache template at {}", templatePath);
|
logger.warn("could not find mustache template at {}", templatePath);
|
||||||
}
|
}
|
||||||
catch (UncheckedExecutionException ex)
|
catch (UncheckedExecutionException | MustacheException ex)
|
||||||
{
|
|
||||||
handleWrappedException(ex, templatePath);
|
|
||||||
}
|
|
||||||
catch (MustacheException ex)
|
|
||||||
{
|
{
|
||||||
handleWrappedException(ex, templatePath);
|
handleWrappedException(ex, templatePath);
|
||||||
}
|
}
|
||||||
@@ -231,5 +231,5 @@ public class MustacheTemplateEngine implements TemplateEngine
|
|||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private ServletMustacheFactory factory;
|
private final ServletMustacheFactory factory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ import com.google.common.base.Charsets;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.plugin.PluginLoader;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -71,10 +73,13 @@ public class ServletMustacheFactory extends DefaultMustacheFactory
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param servletContext
|
* @param servletContext
|
||||||
|
* @param pluginLoader
|
||||||
*/
|
*/
|
||||||
public ServletMustacheFactory(ServletContext servletContext)
|
public ServletMustacheFactory(ServletContext servletContext,
|
||||||
|
PluginLoader pluginLoader)
|
||||||
{
|
{
|
||||||
this.servletContext = servletContext;
|
this.servletContext = servletContext;
|
||||||
|
this.pluginLoader = pluginLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -111,14 +116,7 @@ public class ServletMustacheFactory extends DefaultMustacheFactory
|
|||||||
resourceName = resourceName.substring(1);
|
resourceName = resourceName.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
is = pluginLoader.getUberClassLoader().getResourceAsStream(resourceName);
|
||||||
|
|
||||||
if (classLoader == null)
|
|
||||||
{
|
|
||||||
classLoader = ServletMustacheFactory.class.getClassLoader();
|
|
||||||
}
|
|
||||||
|
|
||||||
is = classLoader.getResourceAsStream(resourceName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is != null)
|
if (is != null)
|
||||||
@@ -146,6 +144,9 @@ public class ServletMustacheFactory extends DefaultMustacheFactory
|
|||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final PluginLoader pluginLoader;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private ServletContext servletContext;
|
private ServletContext servletContext;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,12 @@
|
|||||||
|
|
||||||
package sonia.scm.template;
|
package sonia.scm.template;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import sonia.scm.plugin.PluginLoader;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -57,7 +63,12 @@ public class MustacheTemplateEngineTest extends TemplateEngineTestBase
|
|||||||
@Override
|
@Override
|
||||||
public TemplateEngine createEngine(ServletContext context)
|
public TemplateEngine createEngine(ServletContext context)
|
||||||
{
|
{
|
||||||
return new MustacheTemplateEngine(context);
|
PluginLoader loader = mock(PluginLoader.class);
|
||||||
|
|
||||||
|
when(loader.getUberClassLoader()).thenReturn(
|
||||||
|
Thread.currentThread().getContextClassLoader());
|
||||||
|
|
||||||
|
return new MustacheTemplateEngine(context, loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user