Skip to content
Snippets Groups Projects
Commit ef3726f2 authored by Simon Urli's avatar Simon Urli
Browse files

XWIKI-19378: Asynchronous document static analysis

  * Fix problem with the ExecutionContext which was not properly
    initialized
  * Fix missing initialization of the XWikiContext in the task manager
parent c770a457
No related branches found
No related tags found
No related merge requests found
......@@ -26,4 +26,5 @@
<suppressions>
<suppress checks="MultipleStringLiterals" files="src/main/java/org/xwiki/index/internal/TasksStore\.java"/>
<suppress checks="ClassFanOutComplexity" files="src/main/java/org/xwiki/index/internal/DefaultTasksManager\.java"/>
</suppressions>
......@@ -36,6 +36,7 @@
import org.xwiki.component.phase.Disposable;
import org.xwiki.component.phase.Initializable;
import org.xwiki.component.phase.InitializationException;
import org.xwiki.context.ExecutionContext;
import org.xwiki.index.TaskManager;
import org.xwiki.index.internal.jmx.JMXTasks;
import org.xwiki.management.JMXBeanRegistration;
......@@ -43,6 +44,7 @@
import org.xwiki.wiki.descriptor.WikiDescriptorManager;
import org.xwiki.wiki.manager.WikiManagerException;
import com.xpn.xwiki.XWikiContextInitializer;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.doc.tasks.XWikiDocumentIndexingTask;
import com.xpn.xwiki.doc.tasks.XWikiDocumentIndexingTaskId;
......@@ -79,6 +81,9 @@ public class DefaultTasksManager implements TaskManager, Initializable, Disposab
@Inject
private TaskExecutor taskExecutor;
@Inject
private XWikiContextInitializer xWikiContextInitializer;
@Inject
private Logger logger;
......@@ -218,12 +223,15 @@ private void consume()
private void initQueue() throws InitializationException
{
try {
this.xWikiContextInitializer.initialize(new ExecutionContext());
// Load the tasks for all wikis.
for (String wikiId : this.wikiDescriptorManager.getAllIds()) {
loadWiki(wikiId);
}
} catch (WikiManagerException e) {
throw new InitializationException("Failed to list the wiki IDs.", e);
} catch (XWikiException e) {
throw new InitializationException("Error when initializing XWikiContext", e);
}
}
......
......@@ -30,7 +30,6 @@
import org.xwiki.component.annotation.Component;
import org.xwiki.context.ExecutionContext;
import org.xwiki.context.ExecutionContextManager;
import org.xwiki.model.reference.DocumentReferenceResolver;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
......@@ -55,9 +54,6 @@ public class TasksStore extends XWikiHibernateBaseStore
@Inject
private Provider<XWikiContext> xcontextProvider;
@Inject
private DocumentReferenceResolver<String> documentReferenceResolver;
/**
* Retrieve the list of all the tasks queued for a given wiki for the current instance.
*
......@@ -164,14 +160,18 @@ public XWikiDocument getDocument(String wikiId, long docId) throws XWikiExceptio
private <T> T initWikiContext(Lambda<T> r, String wikiId) throws XWikiException
{
ExecutionContext executionContext = new ExecutionContext();
try {
this.contextManager.initialize(new ExecutionContext());
this.contextManager.pushContext(executionContext, false);
this.contextManager.initialize(executionContext);
XWikiContext xWikiContext = this.xcontextProvider.get();
xWikiContext.setWikiId(wikiId);
return r.call(xWikiContext);
} catch (Exception e) {
throw new XWikiException("Failed to executed the task in the context", e);
} finally {
this.contextManager.popContext();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment