Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Save XtextResourceSet
Save XtextResourceSet [message #1810776] Mon, 19 August 2019 14:36 Go to next message
Alfredo Aldundi is currently offline Alfredo AldundiFriend
Messages: 38
Registered: July 2009
Member
Hi all,

I am writing a converter (model-to-text) for an existing model to a DSL. The converter loops over all resources in the input resource set and creates corresponding (Xtext) resources in the output (using XtextResourceSet.createResource). The converter is working perfectly fine, but as soon as I try to save the resource set (by iterating over all the resources and calling save) it fails with errors due to dependencies in the resources.

After a few iterations the conversion passes (i.e. after all "cross-referenced" resources are converted). So, the general conversion logic works.

The converter is running inside eclipse (triggered from a command).

I am a bit lost: how can I save resources in a way that "just works" from inside Eclipse. Actually, I do not really care about all the validation stuff when converting. If there are errors, they will popup anyway in the generated files.

This conversion is actually just done once, then I'll ditch out the old XMI ecore files and the DSL will be the master.

Any hints?!
Alfredo
Re: Save XtextResourceSet [message #1810785 is a reply to message #1810776] Mon, 19 August 2019 16:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14711
Registered: July 2009
Senior Member
The usual procedure is
1 transform all resources
2 calll save for all resources

Are you talking about the validation in CrossReferenceSerializer ?
This one is there for a reason but if you know what you do you can use a custom impl
That does not uses scopes for validation \ cross ref text calculation


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Save XtextResourceSet [message #1810788 is a reply to message #1810785] Mon, 19 August 2019 16:43 Go to previous messageGo to next message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 266
Registered: July 2009
Senior Member
How are you creating the Xtext resources? Specifically, where there are cross-references between them, is your code ensuring that the object contained in resource A and the object referenced from a some object in resource B are actually the same one, regardless of the order in which the Xtext resources happen to be generated?
Re: Save XtextResourceSet [message #1810812 is a reply to message #1810785] Tue, 20 August 2019 06:45 Go to previous messageGo to next message
Alfredo Aldundi is currently offline Alfredo AldundiFriend
Messages: 38
Registered: July 2009
Member
that is exactly what I do (transform all then save all).

I get the XtextResourceSet from the Injector.

ResourceSet in = ...;
XtextResourceSet out = injector.getInstance(XtextResourceSet.class);

in.getResource().forEach(resource -> {
   XtextResource outResource = output.getResource(getOutputUrl(resource));
  convert(resource, outResource);
});

out.getResource().forEach(resource -> {
  resource.save(null);
});


Now I have switched to the standalone setup and everything works fine. It must have something to do with index rebuild in the background. All references are 100% ok (no errors after 3 iterations of conversion, i.e. when the referenced files are generated first). Ordering the resources (just a hack, I know) also does not help. It really requires three (in my case) iterations to get a working build with the IDE setup.

Re: Save XtextResourceSet [message #1810822 is a reply to message #1810812] Tue, 20 August 2019 08:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14711
Registered: July 2009
Senior Member
in eclipse you should always use a project aware resourceset.
IResourceSetProvider will give you one.
if you want to have a "index" using all the resource in the resourceset you have to use LiveScopeResourceSetInitializer too


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Save XtextResourceSet [message #1810840 is a reply to message #1810822] Tue, 20 August 2019 12:27 Go to previous message
Alfredo Aldundi is currently offline Alfredo AldundiFriend
Messages: 38
Registered: July 2009
Member
now we are getting somewhere

@Inject
LiveScopeResourceSetInitializer initializer;
	
@Inject
IResourceSetProvider resourceSetProvider;


and then

ResourceSet outputResources = resourceSetProvider.get(project);
initializer.initialize(outputResources);


Seems to be a case of "too much magic" :-P.

Thanks for your help!
Previous Topic:Maven: Getting the configured Java source version
Next Topic:Fine-grained control of caching in Xtext
Goto Forum:
  


Current Time: Sat Sep 07 10:27:03 GMT 2024

Powered by FUDForum. Page generated in 0.05223 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top