mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
fix out of scope exception on access hgcontext
This commit is contained in:
@@ -30,12 +30,17 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -43,6 +48,14 @@ import com.google.inject.Provider;
|
||||
public class HgContextProvider implements Provider<HgContext>
|
||||
{
|
||||
|
||||
/**
|
||||
* the logger for HgContextProvider
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(HgContextProvider.class);
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -52,6 +65,20 @@ public class HgContextProvider implements Provider<HgContext>
|
||||
@Override
|
||||
public HgContext get()
|
||||
{
|
||||
return new HgContext();
|
||||
HgContext ctx = context;
|
||||
|
||||
if (ctx == null)
|
||||
{
|
||||
ctx = new HgContext();
|
||||
logger.trace("context is null, we are probably out of request scope");
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@Inject(optional = true)
|
||||
private HgContext context;
|
||||
}
|
||||
@@ -40,6 +40,7 @@ import com.google.inject.servlet.ServletModule;
|
||||
import sonia.scm.installer.HgPackageReader;
|
||||
import sonia.scm.plugin.ext.Extension;
|
||||
import sonia.scm.repository.HgContext;
|
||||
import sonia.scm.repository.HgContextProvider;
|
||||
import sonia.scm.repository.HgHookManager;
|
||||
import sonia.scm.web.filter.BasicAuthenticationFilter;
|
||||
|
||||
@@ -66,7 +67,7 @@ public class HgServletModule extends ServletModule
|
||||
@Override
|
||||
protected void configureServlets()
|
||||
{
|
||||
bind(HgContext.class);
|
||||
bind(HgContext.class).toProvider(HgContextProvider.class);
|
||||
bind(HgHookManager.class);
|
||||
bind(HgPackageReader.class);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user