Search in sources :

Example 11 with ExecutionContextManager

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;
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ExecutionContextManager(org.xwiki.context.ExecutionContextManager) EmbeddableComponentManager(org.xwiki.component.embed.EmbeddableComponentManager) ComponentManager(org.xwiki.component.manager.ComponentManager) XWikiContext(com.xpn.xwiki.XWikiContext) EmbeddableComponentManager(org.xwiki.component.embed.EmbeddableComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ExecutionContextException(org.xwiki.context.ExecutionContextException)

Aggregations

ExecutionContextManager (org.xwiki.context.ExecutionContextManager)11 ExecutionContext (org.xwiki.context.ExecutionContext)8 Execution (org.xwiki.context.Execution)6 XWikiContext (com.xpn.xwiki.XWikiContext)4 DocumentReference (org.xwiki.model.reference.DocumentReference)4 ExecutionContextException (org.xwiki.context.ExecutionContextException)3 XWiki (com.xpn.xwiki.XWiki)2 XWikiException (com.xpn.xwiki.XWikiException)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 Before (org.junit.Before)2 Test (org.junit.Test)2 EmbeddableComponentManager (org.xwiki.component.embed.EmbeddableComponentManager)2 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)2 CoreConfiguration (com.xpn.xwiki.CoreConfiguration)1 XWikiCfgConfigurationSource (com.xpn.xwiki.internal.XWikiCfgConfigurationSource)1 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)1