Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Maven project fails during model validation
Maven project fails during model validation [message #1816272] Fri, 25 October 2019 01:30 Go to next message
Eclipse UserFriend
Hello,

I'm facing a problem when running the xtext maven plugin.

I will provide the minimal setup for reproducing the error.

DatamodelDsl.xtext
Context:
	'context' name=CTXT_FQN ('extends' parentContext=[Context|CTXT_FQN] )? ;
	
terminal CTXT_FQN:
    ID '-' VERSION ;
 


DatamodelDslScopeProvider.xtend
class DatamodelDslScopeProvider extends AbstractDatamodelDslScopeProvider {
	
	@Inject
	IResourceDescriptions resourceDescriptions; 
	
	@Inject
	Provider<XtextResourceSet> resourceSetProvider;
	
	val ePackage = DatamodelDslPackage.eINSTANCE;
	override getScope(EObject context, EReference reference){
		if(reference == ePackage.context_ParentContext && context instanceof Context){
			val currentContext = context as Context
			return scopeForParentContext(currentContext, context, reference)
		}
		return super.getScope(context,reference)
	}
	
	def protected IScope scopeForParentContext(Context currentContext, EObject context, EReference reference) {
	 	val List<Context> contexts = newArrayList;
	 	if(resourceDescriptions!==null && !resourceDescriptions.empty) {
		 	val descriptions = resourceDescriptions.getExportedObjectsByType(ePackage.context);
		 	if(!descriptions.empty){
			 	for(IEObjectDescription description: resourceDescriptions.getExportedObjectsByType(ePackage.context)){
		 			var Resource resource = resourceSetProvider.get.getResource(description.EObjectURI, true)
		 			var contextInstance = resource.allContents.filter(Context).head
		 			contexts.add(contextInstance)
			 	}
				return Scopes::scopeFor(contexts, [QualifiedName.create((it as Context).name.split("\\."))],IScope.NULLSCOPE);
			}
		} else {
			return super.getScope(context,reference)
		}
	}
}


pom.xml
<plugin>
	<groupId>org.eclipse.xtext</groupId>
	<artifactId>xtext-maven-plugin</artifactId>
	<version>${xtext.version}</version>
	<executions>
		<execution>
			<id>compile-wkfs</id>
				<goals>
					<goal>generate</goal>
				</goals>
		</execution>
	</executions>
	<configuration>
		<languages>
			<language>							 
<setup>com.wkfsfrc.rr.tools.ruledesigner.datamodel.DatamodelDslStandaloneSetup</setup>
				<outputConfigurations>
					<outputConfiguration>
						<outputDirectory>${project.basedir}/src-gen/main/resources</outputDirectory>
					</outputConfiguration>
				</outputConfigurations>
			</language>
		</languages>
	</configuration>
</plugin>


The two model examples:

myTest.datamodel
context Base_Context-1.0.0 


myTest2.datamodel
context Another_Context-1.0.0 extends Base_Context-1.0.0


The error that I'm getting:
[INFO] --- xtext-maven-plugin:2.17.1:generate (compile-wkfs) @ local-calcParentName-model ---
[INFO] Encoding: UTF-8
[INFO] Compiler source level: 1.8
[INFO] Compiler target level: 1.8
[INFO] Using common types.
[INFO] Collecting source models.
[INFO] Installing type provider.
[INFO] Generating stubs into C:\Work\Rules Designer Builds\local 24.10\workspace\ex\local-calcParentName\local-calcParentName-model\target\xtext-temp\stubs
[INFO] Compiling stubs located in C:\Work\Rules Designer Builds\local 24.10\workspace\ex\local-calcParentName\local-calcParentName-model\target\xtext-temp\stubs
[INFO] Installing type provider for stubs.
[INFO] Starting validation for input: 'myTest.datamodel'
[ERROR] resolution of uriFragment '|0' failed.
java.lang.NullPointerException
	at org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions.isEmpty(ResourceSetBasedResourceDescriptions.java:92)
	at com.wkfsfrc.rr.tools.ruledesigner.datamodel.scoping.DatamodelDslScopeProvider.scopeForParentContext(DatamodelDslScopeProvider.java:74)
	at com.wkfsfrc.rr.tools.ruledesigner.datamodel.scoping.DatamodelDslScopeProvider.getScope(DatamodelDslScopeProvider.java:54)
	at org.eclipse.xtext.linking.impl.DefaultLinkingService.getScope(DefaultLinkingService.java:58)
	at org.eclipse.xtext.linking.impl.DefaultLinkingService.getLinkedObjects(DefaultLinkingService.java:107)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:265)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:236)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.doResolveLazyCrossReference(LazyLinkingResource.java:203)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReference(LazyLinkingResource.java:162)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReferences(LazyLinkingResource.java:148)
	at org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences(EcoreUtil2.java:504)
	at org.eclipse.xtext.builder.standalone.StandaloneBuilder.launch(StandaloneBuilder.java:266)
	at org.eclipse.xtext.maven.XtextGenerator.internalExecute(XtextGenerator.java:184)
	at org.eclipse.xtext.maven.XtextGenerator.execute(XtextGenerator.java:161)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)


The error is definitely caused by the code from scopeForParentContext, since when I'm not setting any parentContext everything works fine.
The reason for which it is like this implemented is because I want to be able to set as parentContext any context that is defined in the Eclipse workspace, no matter on which project belongs to.
I also tried calling code from Java which was collecting all the contexts from the workspace, but I ended up with a 'Workspace is closed' error.
So, the main goal is to be able to setup a parentContext which belong to any project from the workspace. Maybe there is another way to achieve that.

Any suggestion is more that welcomed. :)

Thank you!

Kind Regards,

Alexandra

Re: Maven project fails during model validation [message #1816273 is a reply to message #1816272] Fri, 25 October 2019 02:48 Go to previous messageGo to next message
Eclipse UserFriend
The NullPointerException is caused in this line:
return resourceSet.getResources().isEmpty();

The only chance to get this is that 'resourceSet' is null. This should under normal circumstances be never the case. Please set up a minimal project with the given settings and try to reproduce this with the information you gave. I bet there will be some customizing that causes this. I don't think that the scope provider is really the problem here. Anyway, implement tests for it.

Btw:
QualifiedName.create((it as Context).name.split("\\."))

That's really inefficient to work with regexps here. Inject the IQualifiedNameConverter and use it.
Re: Maven project fails during model validation [message #1816283 is a reply to message #1816273] Fri, 25 October 2019 07:01 Go to previous messageGo to next message
Eclipse UserFriend
Well, the scope provider is the one to blame because if I'm not setting any parent context, everything works. :)

And I'm facing the errors only when running xtext-maven-plugin.

If I don't do anything for scope provider, there is the following error.

[INFO] Installing type provider for stubs.
[INFO] Validate and generate.
[INFO] Starting validation for input: 'myTest2-1.0.0.datamodel'
[ERROR] ERROR:Couldn't resolve reference to Context 'Base_Context-1.0.0'. (myTest2-1.0.0.datamodel line : 1 column : 39)
[INFO] Starting generator for input: 'myTest2-1.0.0.datamodel'

Maybe I don't need specifically the scope provider and I'm missing something else.

[Updated on: Fri, 25 October 2019 07:01] by Moderator

Re: Maven project fails during model validation [message #1816284 is a reply to message #1816283] Fri, 25 October 2019 08:08 Go to previous message
Eclipse UserFriend
I'm afraid I can't help you more than that without having more context, which would require more time to invest, and which I have not yet.
Run Maven in debug mode, and start investigating with remote debugging why there is no ResourceSet.
Previous Topic:Working directory for xtext plugin
Next Topic:Avoid reloading resource in XtextResourceSet while referencing a non-Xtext model
Goto Forum:
  


Current Time: Sat Mar 15 01:48:59 EDT 2025

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

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

Back to the top