use of org.xwiki.context.ExecutionContextManager in project xwiki-platform by xwiki.
the class AbstractDocumentMojo method createXWikiContext.
protected XWikiContext createXWikiContext() throws MojoExecutionException {
EmbeddableComponentManager ecm = new EmbeddableComponentManager();
ecm.initialize(this.getClass().getClassLoader());
Utils.setComponentManager(ecm);
// Context component manager is totally useless here
ecm.unregisterComponent(ComponentManager.class, "context");
// We need to initialize the Component Manager so that the components can be looked up
XWikiContext xcontext = new XWikiContext();
xcontext.put(ComponentManager.class.getName(), ecm);
// Initialize the Container fields (request, response, session).
try {
ExecutionContextManager ecim = ecm.getInstance(ExecutionContextManager.class);
ExecutionContext econtext = new ExecutionContext();
// Bridge with old XWiki Context, required for old code.
xcontext.declareInExecutionContext(econtext);
ecim.initialize(econtext);
} catch (ExecutionContextException | ComponentLookupException e) {
throw new MojoExecutionException("Failed to initialize Execution Context.", e);
}
return xcontext;
}
Aggregations