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;
}
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;
}
Aggregations