Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Running validator on all DSL files in workspace?
Running validator on all DSL files in workspace? [message #1086683] Wed, 14 August 2013 14:57 Go to next message
Alan DW is currently offline Alan DWFriend
Messages: 119
Registered: March 2012
Senior Member
Hello everyone,

I'm developing an Xtext-based plug-in for Eclipse. My DSL files often reference objects outside their own file and my custom validator checks those references for correctness. What I would need now is the possibility to run my custom Xtext validator for all DSL files in the current workspace (regardless whether they are currently opened in an editor or not) from my plug-in Java code. The main reason I want to do this is to update the "warning" and "error" markers that appear on the workspace project explorer.

Since the validation is an Eclipse Command, I guess that this should be possible somehow, but I'm rather new to Eclipse Plug-In development, so I don't really have a clue how to do this...

Any help would be very apprechiated!

Thanks,


Alan
Re: Running validator on all DSL files in workspace? [message #1086972 is a reply to message #1086683] Thu, 15 August 2013 01:18 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
If your cross references are done using EMF references and specified as
links in the grammar, then you get the desired behavior more or less for
free.

If you need to do your own linking there are quite a few things to do
before you get the equivalent level of features. I did my own linking in
the cloudsmith / geppetto project at github - it is not trivial, and I
do not recommend taking this route unless you absolutely have to.

Regards
- henrik

On 2013-14-08 7:57, Alan DW wrote:
> Hello everyone,
>
> I'm developing an Xtext-based plug-in for Eclipse. My DSL files often
> reference objects outside their own file and my custom validator checks
> those references for correctness. What I would need now is the
> possibility to run my custom Xtext validator for all DSL files in the
> current workspace (regardless whether they are currently opened in an
> editor or not) from my plug-in Java code. The main reason I want to do
> this is to update the "warning" and "error" markers that appear on the
> workspace project explorer.
>
> Since the validation is an Eclipse Command, I guess that this should be
> possible somehow, but I'm rather new to Eclipse Plug-In development, so
> I don't really have a clue how to do this...
>
> Any help would be very apprechiated!
>
> Thanks,
>
>
> Alan
Re: Running validator on all DSL files in workspace? [message #1088602 is a reply to message #1086683] Sat, 17 August 2013 10:07 Go to previous messageGo to next message
Alan DW is currently offline Alan DWFriend
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 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
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 Go to previous message
Alan DW is currently offline Alan DWFriend
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

Previous Topic:Save Failed Attempted to beginRule: does not match outer scope rule
Next Topic:Standalone generating files with no content?
Goto Forum:
  


Current Time: Fri Apr 19 14:37:13 GMT 2024

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

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

Back to the top