Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » ImportUriGlobalScopeProvider can not find resource
ImportUriGlobalScopeProvider can not find resource [message #724019] Sat, 10 September 2011 11:19 Go to next message
eecolor is currently offline eecolorFriend
Messages: 36
Registered: September 2011
Member
I have the following simplified language:

grammar ee.xtext.test.Test with org.eclipse.xtext.common.Terminals

generate test "http://www.xtext.ee/test/Test"

File:
	(classes+=Class)*
	(references+=ClassReference)*
;

Class:
	'class' name=ID
	'{'
	'}'
;

ClassReference:
	reference=[Class]
;


In the mew2 file I have the following (relevant) lines:

// scoping and exporting API
fragment = scoping.ImportURIScopingFragment {}
fragment = exporting.SimpleNamesFragment {}

// scoping and exporting API
//fragment = scoping.ImportNamespacesScopingFragment {}
//fragment = exporting.QualifiedNamesFragment {}
//fragment = builder.BuilderIntegrationFragment {}

// provides the necessary bindings for java types integration
//fragment = types.TypesGeneratorFragment {}

// generates the required bindings only if the grammar inherits from Xbase
//fragment = xbase.XbaseGeneratorFragment {}


My module looks like this:

public class TestRuntimeModule extends ee.xtext.test.AbstractTestRuntimeModule {

	@Override
	public Class<? extends IGlobalScopeProvider> bindIGlobalScopeProvider() {
		return TestImportUriGlobalScopeProvider.class;
	}
	
}


My custom ImportUriGlobalScopeProvider looks like this:

public class TestImportUriGlobalScopeProvider extends
		ImportUriGlobalScopeProvider {

	@Override
	protected LinkedHashSet<URI> getImportedUris(Resource resource) {
		
		System.out.println("resource exists: " + (getClass().getClassLoader().getResource("test2.test") != null));
		
		LinkedHashSet<URI> temp = super.getImportedUris(resource);
	    temp.add(URI.createURI("classpath:/test2.test"));
	    
	    
	    return temp;
	}
	
}


I have created a separate plugin with the 'test2.test' file in it. Both the test project and the test.ui project have a dependency on that plugin.

I am using this text file:

class Test1
{
	
}

Test1
Test2


When I test the above configuration I get the following output:

resource exists: true
ERROR org.eclipse.xtext.linking.lazy.LazyLinkingResource  - resolution of uriFragment 'xtextLink_::0.1.0::0::/1' failed.
org.eclipse.xtext.resource.ClasspathUriResolutionException: java.lang.IllegalStateException: Couldn't find resource on classpath. URI was 'classpath:/test2.test'
...


It seems this is caused by the ClassloaderClasspathUriResolver using another class loader. The resolve method is called without a context, this causes the Thread.currentThread().getContextClassLoader() to be used:

public URI resolve(Object context, URI classpathUri) {
    	Object myContext = context;
        if (myContext == null) {
            myContext = Thread.currentThread().getContextClassLoader();
        }
    	
    	...
}


I have no clue on how to solve this problem, any help would be greatly appreciated.

[Updated on: Sat, 10 September 2011 11:19]

Report message to a moderator

Re: ImportUriGlobalScopeProvider can not find resource [message #725409 is a reply to message #724019] Wed, 14 September 2011 17:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14666
Registered: July 2009
Senior Member
HI,

hi just a short thought:
what about adding test2.test to the classpath of the model project?
or using platform:/plugin uris instead?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: ImportUriGlobalScopeProvider can not find resource [message #725439 is a reply to message #725409] Wed, 14 September 2011 19:24 Go to previous messageGo to next message
eecolor is currently offline eecolorFriend
Messages: 36
Registered: September 2011
Member
I took the approach from http://blogs.itemis.de/stundzig/archives/795

I did however try your suggestion, it gave the exact same result:

resource exists: true
2147 [Worker-5] ERROR org.eclipse.xtext.linking.lazy.LazyLinkingResource  - resolution of uriFragment 'xtextLink_::0.1.0::0::/1' failed.
org.eclipse.xtext.resource.ClasspathUriResolutionException: java.lang.IllegalStateException: Couldn't find resource on classpath. URI was 'classpath:/test2.test'

[Updated on: Wed, 14 September 2011 19:25]

Report message to a moderator

Re: ImportUriGlobalScopeProvider can not find resource [message #725446 is a reply to message #725439] Wed, 14 September 2011 19:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14666
Registered: July 2009
Senior Member
Hi,

how are you actually executing this:

(1) create a new project with your dsl and importuri customization (changed to classpath:/test/test2.mydsl)
(2) create a pluginproject with the libary file (hanged the file to be in a package test and exported this in the manifest)
(3) start a runtime, create a pluginproject, add the lib project to the path, create the model file - i can ref stuff from the lib project

or

(1) create a new project with your dsl and importuri customization (code changed to platform:/plugin/lib/test2.mydsl)
(2) create a pluginproject with the libary (made file be part of the build in build.properties)
(3) start runtime, create any project and ref stuff

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: ImportUriGlobalScopeProvider can not find resource [message #725458 is a reply to message #725446] Wed, 14 September 2011 20:43 Go to previous messageGo to next message
eecolor is currently offline eecolorFriend
Messages: 36
Registered: September 2011
Member
I am using the first approach, but I think I see a difference. I am not manually adding the lib project to the path. In thought that by making my xText project dependent on the plugin, it would be available. The strange thing is: it is actually available to the classloader of the TestImportUriGlobalScopeProvider, yet the underlying ClassloaderClasspathUriResolver can not find it.

I am not creating a Java project for the test project, I guess that's needed in order for this approach to work. I will go and do some testing when I have some more time.

I still do not understand the rules that the ClassloaderClasspathUriResolver uses to determine which classloader to use, but it would be nice if in the future I could ship my intrinsic classes in a jar with the xtext editor plugin. If you have any more insight on this, please do post it.

Thanks for your help!


Re: ImportUriGlobalScopeProvider can not find resource [message #725461 is a reply to message #725458] Wed, 14 September 2011 20:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14666
Registered: July 2009
Senior Member
Hi,

classpath is the classpath of the resource the import is used within (the model file you want to cross reference from). It is not the classpath of the infrastructure code (the scope provider)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: ImportUriGlobalScopeProvider can not find resource [message #725462 is a reply to message #725461] Wed, 14 September 2011 20:53 Go to previous message
eecolor is currently offline eecolorFriend
Messages: 36
Registered: September 2011
Member
I see, thank you very much.
Previous Topic:How can I define constructors in xtend class files?
Next Topic:How to make Xtext parser stop if a particular word is found?
Goto Forum:
  


Current Time: Fri Apr 26 16:49:38 GMT 2024

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

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

Back to the top