Search in sources :

Example 6 with EmbeddableComponentManager

use of org.xwiki.component.embed.EmbeddableComponentManager in project xwiki-platform by xwiki.

the class OldCoreHelper method create.

/**
 * @param wikiId id of the wiki for which to prepare the XWiki Context (e.g. {@code xwiki})
 * @param hibernateConfig the Hibernate config fill containing the database definition (JDBC driver, username and
 *            password, etc)
 * @return an initialized instance of {@link OldCoreHelper}
 * @throws MojoExecutionException when failing to initialize {@link OldCoreHelper} instance
 */
public static OldCoreHelper create(String wikiId, File hibernateConfig) throws MojoExecutionException {
    // Create and initialize a Component Manager
    EmbeddableComponentManager embeddableComponentManager = (EmbeddableComponentManager) org.xwiki.environment.System.initialize();
    // Initialize Execution Context
    try {
        ExecutionContextManager ecim = embeddableComponentManager.getInstance(ExecutionContextManager.class);
        ecim.initialize(new ExecutionContext());
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to initialize Execution Context Manager.", e);
    }
    OldCoreHelper oldCoreHelper = create(embeddableComponentManager, wikiId, hibernateConfig);
    oldCoreHelper.disposeComponentManager = true;
    return oldCoreHelper;
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ExecutionContextManager(org.xwiki.context.ExecutionContextManager) EmbeddableComponentManager(org.xwiki.component.embed.EmbeddableComponentManager) XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) MalformedURLException(java.net.MalformedURLException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ExecutionContextException(org.xwiki.context.ExecutionContextException)

Example 7 with EmbeddableComponentManager

use of org.xwiki.component.embed.EmbeddableComponentManager 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

EmbeddableComponentManager (org.xwiki.component.embed.EmbeddableComponentManager)7 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)3 ArrayList (java.util.ArrayList)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ComponentAnnotationLoader (org.xwiki.component.annotation.ComponentAnnotationLoader)2 ComponentDeclaration (org.xwiki.component.annotation.ComponentDeclaration)2 ComponentManager (org.xwiki.component.manager.ComponentManager)2 ExecutionContext (org.xwiki.context.ExecutionContext)2 ExecutionContextException (org.xwiki.context.ExecutionContextException)2 ExecutionContextManager (org.xwiki.context.ExecutionContextManager)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 HTMLConverter (info.bliki.wiki.filter.HTMLConverter)1 WikiModel (info.bliki.wiki.model.WikiModel)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 StringReader (java.io.StringReader)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1