| Summary: | [XtextTests] Loading a model resource in second test case fails with a "SAXParseException: Content is not allowed in prolog." | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Alex Tugarev <alex.tugarev> | ||||||
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> | ||||||
| Status: | CLOSED FIXED | QA Contact: | |||||||
| Severity: | normal | ||||||||
| Priority: | P3 | CC: | sebastian.zarnekow | ||||||
| Version: | 2.0.1 | Flags: | sebastian.zarnekow:
indigo+
|
||||||
| Target Milestone: | SR2 | ||||||||
| Hardware: | All | ||||||||
| OS: | All | ||||||||
| Whiteboard: | |||||||||
| Attachments: |
|
||||||||
|
Description
Alex Tugarev
Created attachment 204365 [details]
Easiest way to reproduce: use the sources from this archived project.
Created attachment 204366 [details]
Proposal for a bug fix of org.eclipse.xtext.junit4.XtextRunner.
I'd reject the suggested change since it is important to store the old registry values in #setupRegistry. However, the standalone setup has to be used to call #register(Injector) for each methodBlock and not only for the first one. Therefore we may have to change the interface of ISetup or we need to provide an additional interface ISetupExtension that's implemented by the generated StandaloneSetups. (In reply to comment #3) > I'd reject the suggested change since it is important to store the old registry > values in #setupRegistry. Sebastian, maybe I didn't understand your comment but I did not disable the call of #setupRegistry. As I could see from debuggin the XtextRunner#methodBlock of 2.0.0 calls registryConfigurator.setupRegistry() and super.methodBlock(method) in different order and the second one calls <DSL>InjectorProvider.getInjector(). This difference leads to unregistered resource factory. > However, the standalone setup has to be used to call > #register(Injector) for each methodBlock and not only for the first one. > Therefore we may have to change the interface of ISetup or we need to provide > an additional interface ISetupExtension that's implemented by the generated > StandaloneSetups. I'm interested in a proper solution and more details on this. (In reply to comment #4) > (In reply to comment #3) > > I'd reject the suggested change since it is important to store the old registry > > values in #setupRegistry. > > Sebastian, maybe I didn't understand your comment but I did not disable the > call of #setupRegistry. Sorry, my comment was incomplete: It is important to store the old registry contents prior to invoking the method block. Otherwise it would not be possible to restore the original contents and thereby revert any side-effects that were caused by the method block itself. I created a new project and used this testcase:
@RunWith(XtextRunner.class)
@InjectWith(MyDslInjectorProvider.class)
public class SampleTest {
@Inject
XtextResourceSet resourceSet;
@Test
public void testResourceFactory() throws Exception {
URI uri = URI.createURI("sample.mydsl");
// XMIResource will be created (wrongly)
Resource resource = resourceSet.createResource(uri);
Assert.assertTrue(resource instanceof XtextResource);
}
@Test
public void testResourceFactory2() throws Exception {
URI uri = URI.createURI("sample.mydsl");
// XMIResource will be created (wrongly)
Resource resource = resourceSet.createResource(uri);
Assert.assertTrue(resource instanceof XtextResource);
}
}
Everything worked fine so far. Please reopen if I missed something.
(In reply to comment #6) Now I've an idea what's wrong with the <Dsl>InjectorProvider. The bug is reproducible if your #setupRegistry() in <Dsl>InjectorProvider looks like this: public void setupRegistry() { globalStateMemento = GlobalRegistries.makeCopyOfGlobalState(); } As it worked fine for you, I was wondering what could be the difference. I spent some time on this trying to understand the <Dsl>InjectorProvider after I read your #c5. And my idea was to change #setupRegistry() in <Dsl>InjectorProvider to: public void setupRegistry() { globalStateMemento = GlobalRegistries.makeCopyOfGlobalState(); if (injector != null) new <Dsl>StandaloneSetup().register(injector); } After your last comment I tried the last nightly build Xtext-N201110132135 to see how the generated <Dsl>InjectorProvider might have changed. It looks like this: public void setupRegistry() { globalStateMemento = GlobalRegistries.makeCopyOfGlobalState(); if (injector != null) new MyDslStandaloneSetup().register(injector); } And this realy works fine! I've just double-tested the 2.0.1 (from Xtext-Disto) and the bug is still there. The generated <Dsl>InjectorProvider#setupRegistry() looks like the first one. Does this bug need to be reopened? (In reply to comment #7) > Does this bug need to be reopened? No, since it's fixed for 2.1 and we don't plan a 2.0.2 Closing all bugs that were set to RESOLVED before Neon.0 Closing all bugs that were set to RESOLVED before Neon.0 |