Home » Modeling » TMF (Xtext) » Running validator on all DSL files in workspace?
| |
Re: Running validator on all DSL files in workspace? [message #1088602 is a reply to message #1086683] |
Sat, 17 August 2013 10:07 |
Alan DW Messages: 119 Registered: March 2012 |
Senior Member |
|
|
Hi,
thanks for your reply, but my concern is not related to object linking.
Let me give you an example which is similar (but a little simpler) to my use case.
Let's say we have a DSL which allows the user to enter filepaths at specific locations. For Xtext, these filepaths are just plain Strings. My validator verifies if the file path inside the string is valid and also checks if the target file exists. If the path does not point to an existing file, it will issue an error in the DSL editor.
So, the problem now is that I need to re-evaluate that correctness criterion for all my DSL files in my workspace every time the user adds, moves, renames or removes a file in the workspace, since it might have been just the one file that was referenced by a file path inside a DSL file.
And the question is: how do I (programatically) run my validator on all DSL files in my workspace, without having to open them in a visual editor?
Thanks,
Alan
|
|
|
Re: Running validator on all DSL files in workspace? [message #1088779 is a reply to message #1088602] |
Sat, 17 August 2013 16:50 |
Henrik Lindberg Messages: 2509 Registered: July 2009 |
Senior Member |
|
|
On 2013-17-08 3:07, Alan DW wrote:
> Hi,
>
> thanks for your reply, but my concern is not related to object linking.
> Let me give you an example which is similar (but a little simpler) to my
> use case.
>
> Let's say we have a DSL which allows the user to enter filepaths at
> specific locations. For Xtext, these filepaths are just plain Strings.
> My validator verifies if the file path inside the string is valid and
> also checks if the target file exists. If the path does not point to an
> existing file, it will issue an error in the DSL editor.
>
This is actually linking, even if not to something in a file, but to the
file itself.
> So, the problem now is that I need to re-evaluate that correctness
> criterion for all my DSL files in my workspace every time the user adds,
> moves, renames or removes a file in the workspace, since it might have
> been just the one file that was referenced by a file path inside a DSL
> file.
>
> And the question is: how do I (programatically) run my validator on all
> DSL files in my workspace, without having to open them in a visual editor?
>
Again, you do not have to do this, Xtext will do it for you if you
record the information that is needed by the Xtext builder. You
basically have to keep track of dependencies between files (both
resolved and unresolved; i.e. a link to a non existing file). This
enables the Builder to figure out what needs to be rebuilt (i.e.
validated and linked).
If you go down this path, one possible implementation is to build an EMF
model of the files that are the possible targets in your DSL language.
When files are modified this triggers a change of the model. You then
add references to the entries in the file model to your DSL.
However, if you prefer to rebuild everything (it is required in other
scenarios such as changing preferences that affects the result), you can
take a look at the implementation in cloudsmith / geppetto @ github.
Checkout the class org.cloudsmith.geppetto.pp.dsl.ui.builder.PPBuildJob
and the places where it is used.
You may be interested in the class
org.cloudsmith.geppetto.pp.dsl.ui.preferences.PPPreferencesHelper.RebuildChecker
which is used to queue events that require a full rebuild. This is
required as you do not want to a full rebuild for every change (e.g. in
your case, if someone removes or adds a bunch of files)
Hope that helps.
- henrik
|
|
|
Re: Running validator on all DSL files in workspace? [message #1090034 is a reply to message #1086683] |
Mon, 19 August 2013 16:06 |
Alan DW Messages: 119 Registered: March 2012 |
Senior Member |
|
|
Hi,
okay, so I misunderstood your first post, sorry for that.
For now, thanks to a friend of mine who gave me the hint, I've found the following solution:
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project : projects) {
if (project.getNature("org.eclipse.xtext.ui.shared.xtextNature") != null) {
project.build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
}
}
... so we just iterate over all projects in the workspace which have the xtext nature applied, and tell the incremental project builder to re-build the project.
I must admit that this might not be the most efficient way to do this, but for my use-case this is okay, since the projects I'm dealing with are relatively small and few in numbers. Plus, I don't have any Xtext-based generator applied in any way, so "re-building" actually just boils down to "re-verifying" for my case.
Oh, and by the way, if someone wants to accomplish this task in the way stated above, then for *some* reason (that I do not fully understand yet), the project builder indeed builds the Xtext DSL projects and updates the error markers in the project outline (as desired), but it does *not* update the error markers in active editors for the DSL files (Xtext bug maybe?). You have to update them manually by calling the PlatformUI, iterating over all editor windows that are currently editing DSL files and using their document provider to reset the document (which, in turn, will reset the view).
I agree that the whole approach is neither very "pretty" nor "fancy" and more like a sledgehammer-approach, but it does the job pretty well in a few lines of code without interfering with any EMF model or doing complex linking.
Greets,
Alan
[Updated on: Mon, 19 August 2013 16:07] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Fri Apr 19 14:37:13 GMT 2024
Powered by FUDForum. Page generated in 0.02681 seconds
|