Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to exclude certain Xtext files from the indexing process
How to exclude certain Xtext files from the indexing process [message #1727615] Thu, 24 March 2016 13:06 Go to next message
Jochen Schmich is currently offline Jochen SchmichFriend
Messages: 29
Registered: July 2009
Junior Member
Hi all,

we're working on a Xtext-based DSL. The DSL source files usually reside in a Source folder.
When a Gradle build is executed, the DSL source files get copied to the "build" folder - thus our DSL files exist twice within the same project.
This means that the contents of both files are indexed. On top of that inferred JvmElements are also indexed.
The most obvious consequence of this is that the duplicates are marked as an Error by the NamesAreUniqueValidator.

Generally speaking, the behavior of Xtext is fully correct in this matter. But still, I want to exclude the "build" folder from the indexing process. I want to achieve that files are not indexed and JVMElements are not inferred (or at least not pushed to the index) if the containing folder is not used as a source folder.

We've partly managed to achieve this by customzing IToBeBuiltComputerContribution. This has no effect on the JVM Inferrer though.

Is there a more elegant and effective solution to this problem?

Thanks in advance,
Jochen

[Updated on: Thu, 24 March 2016 13:07]

Report message to a moderator

Re: How to exclude certain Xtext files from the indexing process [message #1727643 is a reply to message #1727615] Thu, 24 March 2016 16:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
do you use eclipse or intellij?

in eclipse if the project is recognized correctly by the gradle plugin the build folder will be excluded (JavaProjectsStateHelper)
if you use intellij and the behaviour is different i think that is a bug

can you share a sample gradle file / project to reproduce that?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to exclude certain Xtext files from the indexing process [message #1727933 is a reply to message #1727643] Tue, 29 March 2016 14:32 Go to previous messageGo to next message
Adrian Rochau is currently offline Adrian RochauFriend
Messages: 2
Registered: March 2016
Junior Member
Hi Christian!
I am working on this with Jochen.
The problem is currently not the Gradle build itself but that our DSL files are copied to the build folder and thus e.g. this identifier of the elements are not unique anymore.
As far as I understand you this should not happen because the "build" folder should be excluded and thus not be validated or indexed by Xtext, right?
Re: How to exclude certain Xtext files from the indexing process [message #1727948 is a reply to message #1727933] Tue, 29 March 2016 16:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Yes this is why i ask How and When you get the duplicate indexing. In eclipse. In Intellij. Standalone in Build ....
Can you Share something that helps us to umderstand and reproduce the problem


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to exclude certain Xtext files from the indexing process [message #1728023 is a reply to message #1727948] Wed, 30 March 2016 10:32 Go to previous messageGo to next message
Adrian Rochau is currently offline Adrian RochauFriend
Messages: 2
Registered: March 2016
Junior Member
We're using Eclipse 4.5.2 with Xtext 2.9.2.
It seems that when I perform a clean build on the project or edit the file which is correctly located in a Source Folder everything works as expected and the file in the build folder is ignored. But when I open the file in the build folder and trigger a build by editing and saving it or when I copy the file to the build folder a build of the file is triggered. So I would expect the file to be excluded from the build in all of the three cases (clean build with file in build folder, edit file in build folder, copy file to build folder) and not only in the first case. I'll try to find our more.
How is determined which resources to ignore? Can I change this?
Re: How to exclude certain Xtext files from the indexing process [message #1728025 is a reply to message #1728023] Wed, 30 March 2016 10:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
can you please share sample code. on my setup i cannot even open something in the build folder since it is hidden

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to exclude certain Xtext files from the indexing process [message #1728026 is a reply to message #1728025] Wed, 30 March 2016 11:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
there are seveal places. e.g. javaprojectstatehelper which makes only stuff in source folders visible.
and there is IResourceServiceProvider.canHandle.
and several other places


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to exclude certain Xtext files from the indexing process [message #1728027 is a reply to message #1728026] Wed, 30 March 2016 11:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
here a screenshot how it looks like

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to exclude certain Xtext files from the indexing process [message #1728802 is a reply to message #1728027] Thu, 07 April 2016 13:41 Go to previous messageGo to next message
Jochen Schmich is currently offline Jochen SchmichFriend
Messages: 29
Registered: July 2009
Junior Member
Hi Christian,

sorry for the late response - I've been away for some days. Now, back to work Smile!
Thanks for your help so far.

Your screenshot shows that you're using Buildship as the Gradle IDE integration. Our users often use the STS Gradle plug-in or the CLI.
I didn't check that yet, but that might cause the different behavior.

Quote:

there are seveal places. e.g. javaprojectstatehelper which makes only stuff in source folders visible.
and there is IResourceServiceProvider.canHandle.
and several other places


Can you please name an exhaustive list of these places? We've customized the IToBeBuiltComputerContribution. Guess that's not the correct place. We've also bound StrictJavaProjectStateHelper in our Guice Module - but that's not directly connected with our issue.

Thanks in advance!
Re: How to exclude certain Xtext files from the indexing process [message #1728803 is a reply to message #1728802] Thu, 07 April 2016 13:47 Go to previous messageGo to next message
Jochen Schmich is currently offline Jochen SchmichFriend
Messages: 29
Registered: July 2009
Junior Member
Ah - one more thing:
We customized org.eclipse.xtext.builder.impl.javasupport.JdtToBeBuiltComputer.isRejected(IFolder) before. We rejected any folder that's not on the classpath. That way we were able to exclude our EObjects from the index - but NOT their counterparts that are created by the JvmModelInferrer. These Objects (JvmTypes, JvmAttributes and so on) are created regardless of any restrictions we introduce in the IToBeBuiltComputerContribution.

Is there a central place where can also prevent the JvmModelInferrer from creating Objects when the source model file is not on the classpath?
Re: How to exclude certain Xtext files from the indexing process [message #1728830 is a reply to message #1728803] Thu, 07 April 2016 17:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
so is your project a java project or is it not ?!?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to exclude certain Xtext files from the indexing process [message #1728835 is a reply to message #1728830] Thu, 07 April 2016 17:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
p.s.

possible places may be (good start for debugging)

- Storage2UriMapperImpl.getAllEntries(IContainer)
- (called by) WorkspaceProjectsStateHelper.initContainedURIs(String)
- JavaProjectStateHelper.initVisibleHandles
- JavaProjectStateHelper.initContainedURIs

- org.eclipse.xtext.resource.IResourceServiceProvider.canHandle(URI)
- org.eclipse.xtext.ui.resource.IResourceUIServiceProvider.canHandle(URI, IStorage)

- ToBeBuiltComputer (different methods - called by the ClusteringBuilderState)

to do further support maybe a reproducable example language and project would help


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to exclude certain Xtext files from the indexing process [message #1728895 is a reply to message #1728830] Fri, 08 April 2016 10:19 Go to previous messageGo to next message
Jochen Schmich is currently offline Jochen SchmichFriend
Messages: 29
Registered: July 2009
Junior Member
Hi Christian,

thanks for your support!
I'll try to solve our problem with your suggestions.

I don't quite understand this question:
Quote:

so is your project a java project or is it not ?!?


Did you mean: Is the project with the Xtext files inside a Java Project? -> yes!
Did you mean: Do you use Xbase or the JvmType?s -> yes!

I'll let you know, whether this worked out or not and probably upload an example if not.

Cheers,
Jochen
Re: How to exclude certain Xtext files from the indexing process [message #1728921 is a reply to message #1728895] Fri, 08 April 2016 13:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
can you please post a screenshot how the project looks like when the error occurs. how does the .project file look like

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to exclude certain Xtext files from the indexing process [message #1729559 is a reply to message #1728921] Fri, 15 April 2016 13:30 Go to previous messageGo to next message
Jochen Schmich is currently offline Jochen SchmichFriend
Messages: 29
Registered: July 2009
Junior Member
Hiya,

the problem can be solved by simply overriding:
org.eclipse.xtext.resource.IResourceServiceProvider.canHandle(URI) or
org.eclipse.xtext.ui.resource.IResourceUIServiceProvider.canHandle(URI, IStorage).

public class ClasspathAwareResourceUIServiceProvider extends DefaultResourceUIServiceProvider {

	@Inject
	public ClasspathAwareResourceUIServiceProvider(IResourceServiceProvider delegate) {
		super(delegate);
	}

	@Override
	public boolean canHandle(URI uri, IStorage storage) {
		if (isJavaCoreAvailable() && storage instanceof IFile) {
			IFile file = (IFile) storage;
			IJavaProject javaProject = JavaCore.create(file.getProject());
			if (javaProject != null && javaProject.exists()) {
				return javaProject.isOnClasspath(file);
			}
		}
		return super.canHandle(uri, storage);
	}

}


The example for org.eclipse.xtext.resource.IResourceServiceProvider.canHandle(URI) would include resolving the corresponding file to the given URI and so on...

Both ways work well - the file will not be included in the Workspace Build, nor are any JvmElements stored in the index.
Validation is still executed - but results are not propagated to the Problems View.

Concerning the .project file or the screenshot...
Quote:

can you please post a screenshot how the project looks like when the error occurs. how does the .project file look like


I'll have to ask the colleague that approached us with this problem to give us the requested files - I think he used the STS Gradle plug-in, not Buildship. I'll get back to you, as soon as I have them.
We've reproduced it in a pretty generic Java Project - nothing special - only the Java Builder and the Xtext Builder are applied. Our goal was to exclude the Xtext files from the Build if they are not on the Classpath.

Thanks a lot!
Jochen
Re: How to exclude certain Xtext files from the indexing process [message #1729562 is a reply to message #1729559] Fri, 15 April 2016 13:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Yes but with a normal Java Project you should not have to do this for the target fokder This is why I am asking.

See defaultresourceuiserviceprocider canhandle(uri,storage)

For other non source folders you approach is legit



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to exclude certain Xtext files from the indexing process [message #1729564 is a reply to message #1729562] Fri, 15 April 2016 14:05 Go to previous messageGo to next message
Jochen Schmich is currently offline Jochen SchmichFriend
Messages: 29
Registered: July 2009
Junior Member
Ah OK, thanks - well everything is fine then - that's also why we still call "super.canHandle(uri, storage)".
I think STS Gradle doesn't declare the build-Folder as an output folder...
I'll have a look.
In that case, I guess you don't need the config files & screenshots anymore.

Have a nice weekend Smile

[Updated on: Fri, 15 April 2016 14:06]

Report message to a moderator

Re: How to exclude certain Xtext files from the indexing process [message #1729565 is a reply to message #1729564] Fri, 15 April 2016 14:07 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Yes

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:how to link new xpand project to existing xtext model
Next Topic:Web editor unable to generate with inferrer
Goto Forum:
  


Current Time: Fri Mar 29 06:30:34 GMT 2024

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

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

Back to the top