Skip to content
Snippets Groups Projects
Commit 1106b7c0 authored by Vincent Massol's avatar Vincent Massol
Browse files

XWIKI-19504: VFS Api: fails to start due to missing service

* Missing a func tests ATM to prove that it works, it's not very easy to write as it means adding func tests to the module but even more complex, to pre-install an extension (and its deps) before starting XWiki.
parent c34f99ea
No related branches found
No related tags found
No related merge requests found
...@@ -69,9 +69,10 @@ public List<Event> getEvents() ...@@ -69,9 +69,10 @@ public List<Event> getEvents()
// We don't listen to any event because all we're interested in is that we initialize TrueVFS when // We don't listen to any event because all we're interested in is that we initialize TrueVFS when
// this listener is initialized. This allows to fulfill the two uses cases we need: // this listener is initialized. This allows to fulfill the two uses cases we need:
// 1) When the VFS API extension is installed at runtime, the Extension Manager handles the listeners found in // 1) When the VFS API extension is installed at runtime, the Extension Manager handles the listeners found in
// in it by instantiating them and registering them against the Observation Manager. Thus the initialize() // it by instantiating them and registering them against the Observation Manager. Thus the initialize()
// method below is called and TrueVFS initialized. // method below is called and TrueVFS initialized.
// 2) When XWiki starts, all found listeners are also instantiated and registered. // 2) When XWiki starts, all found listeners are also instantiated and registered and thus the initialize()
// method below is also called.
return Collections.emptyList(); return Collections.emptyList();
} }
...@@ -84,11 +85,24 @@ public void onEvent(Event event, Object source, Object data) ...@@ -84,11 +85,24 @@ public void onEvent(Event event, Object source, Object data)
@Override @Override
public void initialize() public void initialize()
{ {
// Register our Attach VFS Driver and inject a Component Manager in it. // This class is loaded using a NamespaceURLClassLoader by the Extension API. However the call to
TConfig config = TConfig.current(); // TConfig.current() will use the context CL to load an FsManagerFactory implementation. Since at this point
// Note: Make sure we add our own Archive Detector to the existing Detector so that all archive formats // (when EventListener are instantiated) we haven't set any context CL, the main servlet container CL is used
// supported by TrueVFS are handled properly. // and thus doesn't have access to dependent JARs of the VFS API. Thus we set it here and put everything back
config.setArchiveDetector(new TArchiveDetector(config.getArchiveDetector(), "attach", // as it was before to be sure to not cause any problems with other Event Listeners and other code down the
new AttachDriver(this.componentManagerProvider.get()))); // line.
// TODO: move this to a more general location so that all EventListener implementations can benefit from it.
ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
// Register our Attach VFS Driver and inject a Component Manager in it.
TConfig config = TConfig.current();
// Note: Make sure we add our own Archive Detector to the existing Detector so that all archive formats
// supported by TrueVFS are handled properly.
config.setArchiveDetector(new TArchiveDetector(config.getArchiveDetector(), "attach",
new AttachDriver(this.componentManagerProvider.get())));
} finally {
Thread.currentThread().setContextClassLoader(currentCL);
}
} }
} }
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