Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Maven project fails during model validation(The Xtext maven plugin does not find generated class during the validation phase)
Maven project fails during model validation [message #1772305] Thu, 07 September 2017 19:25 Go to next message
Miguel Jimenez is currently offline Miguel JimenezFriend
Messages: 38
Registered: July 2015
Member
Hi,
When I use my language from an Eclipse plugin, everything works well. Now I'm configuring a maven project but it fails during model validation.

Here is a minimal language reproducing the error:

MyDsl.xtext
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

DomainModel:
	extensions=ExtensionSection?
	importSection=XImportSection?
	elements+=AbstractElement*;
ExtensionSection:
	declarations+=IncludeDeclaration+;
IncludeDeclaration:
	'includes' entity=[Entity|QualifiedName];
AbstractElement:
	PackageDeclaration | Entity;
PackageDeclaration:
	'package' name=QualifiedName '{'
	elements+=AbstractElement*
	'}';
Entity:
	'entity' name=ValidID body=XBlockExpression;


MyDslRuntimeModule.xtend
package org.xtext.example.mydsl
import com.google.inject.Binder
import com.google.inject.name.Names
import org.eclipse.xtext.scoping.IScopeProvider
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider
import org.xtext.example.mydsl.scoping.MyDslImportSectionNamespaceScopeProvider

class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
	override void configureIScopeProviderDelegate(Binder binder) {
		binder.bind(IScopeProvider)
			.annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE))
			.to(MyDslImportSectionNamespaceScopeProvider);
	}
}


MyDslModelInferrer.xtend
package org.xtext.example.mydsl.jvmmodel
import com.google.common.collect.Lists
import com.google.inject.Inject
import org.eclipse.xtext.naming.IQualifiedNameProvider
import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer
import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor
import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder
import org.xtext.example.mydsl.myDsl.DomainModel
import org.xtext.example.mydsl.myDsl.Entity
import org.xtext.example.mydsl.myDsl.PackageDeclaration

class MyDslJvmModelInferrer extends AbstractModelInferrer {
	@Inject extension JvmTypesBuilder
	@Inject extension IQualifiedNameProvider
	def dispatch infer(DomainModel model,
		extension IJvmDeclaredTypeAcceptor acceptor, boolean prelinkingPhase) {
		if (prelinkingPhase)
			return
		val entities = model.elements.filter(Entity) + model.elements.filter(PackageDeclaration).entities
		entities.forEach[entity|
			accept(entity.toClass(entity.fullyQualifiedName)) [
				documentation = entity.documentation
				members += entity.toMethod("body", typeRef(void)) [
					body = entity.body
				]
			]
		]
	}
	def Iterable<Entity> entities(Iterable<PackageDeclaration> packages) {
		val entities = Lists.newArrayList
		packages.forEach[^package|
			entities.addAll(^package.elements.filter(Entity))
			entities.addAll(^package.elements.filter(PackageDeclaration).entities)
		]
		entities
	}
}


MyDslImportSectionNamespaceScopeProvider.xtend
package org.xtext.example.mydsl.scoping
import com.google.common.collect.Lists
import com.google.inject.Inject
import java.util.List
import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.naming.IQualifiedNameProvider
import org.eclipse.xtext.scoping.impl.ImportNormalizer
import org.eclipse.xtext.xbase.XConstructorCall
import org.eclipse.xtext.xbase.scoping.XImportSectionNamespaceScopeProvider
import org.xtext.example.mydsl.myDsl.DomainModel
import org.xtext.example.mydsl.myDsl.ExtensionSection

// With a little help from https://stackoverflow.com/a/28027025/738968
class MyDslImportSectionNamespaceScopeProvider extends XImportSectionNamespaceScopeProvider {
	@Inject extension IQualifiedNameProvider
	override List<ImportNormalizer> internalGetImportedNamespaceResolvers(EObject context, boolean ignoreCase) {
		switch(context) {
			XConstructorCall: {
				val container = context.model as DomainModel
				if (container.extensions !== null)
					container.extensions.provideImportNormalizerList(ignoreCase)
			}
		}
		super.internalGetImportedNamespaceResolvers(context, ignoreCase)
	}
	/*
	 * Iterates upwards through the AST until a DomainModel is found.
	 */
	def EObject model(EObject o) {
        switch (o) {
            DomainModel: o
            default: o.eContainer.model
        }
    }
	/*
	 * Creates the list of all imports of an ExtensionSection. This implementation is similar to 
	 * getImportedNamespaceResolvers(XImportSection, boolean)
	 */
	def List<ImportNormalizer> provideImportNormalizerList(ExtensionSection extensionSection, boolean ignoreCase) {
        val List<ImportNormalizer> result = Lists.newArrayList
        extensionSection.declarations.forEach[includeDecl|
        	result.add(
        		includeDecl.entity
        			.fullyQualifiedName
        			.toString
        			.createImportedNamespaceResolver(ignoreCase)
        	)
        ]
        result
    }
}


This is the POM of my example project:

pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>org.test</groupId>
	<artifactId>example</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<properties>
		<java.source.directory>src/main/java</java.source.directory>
		<mydsl.source.directory>src/main/java</mydsl.source.directory>
		<mydsl.output.directory>target/generated-sources/mydsl</mydsl.output.directory>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.eclipse.xtext</groupId>
			<artifactId>org.eclipse.xtext.xbase.lib</artifactId>
			<version>2.10.0</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.eclipse.xtext</groupId>
				<artifactId>xtext-maven-plugin</artifactId>
				<version>2.10.0</version>
				<executions>
					<execution>
						<goals>
							<goal>generate</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<javaSourceRoots>
						<javaSourceRoot>${java.source.directory}</javaSourceRoot>
					</javaSourceRoots>
					<sourceRoots>
						<sourceRoot>${mydsl.source.directory}</sourceRoot>
					</sourceRoots>
					<languages>
						<language>
							<setup>org.xtext.example.mydsl.MyDslStandaloneSetupGenerated</setup>
							<javaSupport>true</javaSupport>
							<outputConfigurations>
								<outputConfiguration>
									<outputDirectory>${mydsl.output.directory}</outputDirectory>
								</outputConfiguration>
							</outputConfigurations>
						</language>
					</languages>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>org.xtext.example.mydsl</groupId>
						<artifactId>org.xtext.example.mydsl</artifactId>
						<version>1.0.0-SNAPSHOT</version>
					</dependency>
				</dependencies>
			</plugin>
		</plugins>
	</build>
</project>


And two model examples:

foo.mydsl
package foo {
	entity B {
		println("foo")
	}
}


hello.mydsl
includes foo.B

package hello {
	entity A {
		new B()
	}
}


When I run "mvn clean package" this is what I get:

[INFO] --- xtext-maven-plugin:2.10.0:generate (default) @ example ---
[INFO] Encoding: not set. Encoding provider will be used.
[INFO] Compiler source level: 1.6
[INFO] Compiler target level: 1.6
[INFO] Using common types.
[INFO] Collecting source models.
[INFO] Installing type provider.
[INFO] Generating stubs into /Users/miguel/Development/workspace-xtext/example/target/xtext-temp/stubs
[INFO] Compiling stubs located in /Users/miguel/Development/workspace-xtext/example/target/xtext-temp/stubs
[INFO] Nothing to compile. Stubs compilation was skipped.
[INFO] Installing type provider for stubs.
[INFO] Validate and generate.
[INFO] Starting validation for input: 'foo.mydsl'
[INFO] Starting validation for input: 'hello.mydsl'
[ERROR] ERROR:B cannot be resolved. (file:/Users/miguel/Development/workspace-xtext/example/src/main/java/hello.mydsl line : 5 column : 7)


If I comment the constructor call in entity A (i.e., "new B()"), everything works.

Do you know why is this happening?
Thank you.
Re: Maven project fails during model validation [message #1772306 is a reply to message #1772305] Thu, 07 September 2017 19:31 Go to previous messageGo to next message
Miguel Jimenez is currently offline Miguel JimenezFriend
Messages: 38
Registered: July 2015
Member
If I set failOnValidationError to false, I get a NullPointerException:

mvn package -e
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building example 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- xtext-maven-plugin:2.10.0:generate (default) @ example ---
[INFO] Encoding: not set. Encoding provider will be used.
[INFO] Compiler source level: 1.6
[INFO] Compiler target level: 1.6
[INFO] Using common types.
[INFO] Collecting source models.
[INFO] Installing type provider.
[INFO] Generating stubs into /Users/miguel/Development/workspace-xtext/example/target/xtext-temp/stubs
[INFO] Compiling stubs located in /Users/miguel/Development/workspace-xtext/example/target/xtext-temp/stubs
[INFO] Nothing to compile. Stubs compilation was skipped.
[INFO] Installing type provider for stubs.
[INFO] Validate and generate.
[INFO] Starting validation for input: 'foo.mydsl'
[INFO] Starting validation for input: 'hello.mydsl'
[ERROR] ERROR:B cannot be resolved. (file:/Users/miguel/Development/workspace-xtext/example/src/main/java/hello.mydsl line : 5 column : 7)
[INFO] Starting generator for input: 'foo.mydsl'
[INFO] Starting generator for input: 'hello.mydsl'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.530 s
[INFO] Finished at: 2017-09-07T12:29:03-07:00
[INFO] Final Memory: 34M/227M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eclipse.xtext:xtext-maven-plugin:2.10.0:generate (default) on project example: Execution default of goal org.eclipse.xtext:xtext-maven-plugin:2.10.0:generate failed. NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eclipse.xtext:xtext-maven-plugin:2.10.0:generate (default) on project example: Execution default of goal org.eclipse.xtext:xtext-maven-plugin:2.10.0:generate failed.
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	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:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal org.eclipse.xtext:xtext-maven-plugin:2.10.0:generate failed.
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	... 20 more
Caused by: java.lang.NullPointerException
	at org.eclipse.xtext.xbase.compiler.output.SharedAppendableState.appendType(SharedAppendableState.java:98)
	at org.eclipse.xtext.xbase.compiler.output.TreeAppendable.append(TreeAppendable.java:353)
	at org.eclipse.xtext.xbase.compiler.output.TreeAppendable.append(TreeAppendable.java:1)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.appendConstructedTypeName(XbaseCompiler.java:947)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.constructorCallToJavaExpression(XbaseCompiler.java:916)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler._toJavaStatement(XbaseCompiler.java:860)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:330)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:473)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler._toJavaStatement(XbaseCompiler.java:369)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:324)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:473)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.compile(AbstractXbaseCompiler.java:294)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.compile(AbstractXbaseCompiler.java:274)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.compile(JvmModelGenerator.java:1264)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateExecutableBody(JvmModelGenerator.java:1230)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator._generateMember(JvmModelGenerator.java:933)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateMember(JvmModelGenerator.java:2015)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator$2.apply(JvmModelGenerator.java:320)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator$2.apply(JvmModelGenerator.java:1)
	at org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(ObjectExtensions.java:139)
	at org.eclipse.xtext.xbase.compiler.LoopExtensions.forEach(LoopExtensions.java:34)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateMembersInBody(JvmModelGenerator.java:324)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator._generateBody(JvmModelGenerator.java:287)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateBody(JvmModelGenerator.java:1987)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateType(JvmModelGenerator.java:231)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator._internalDoGenerate(JvmModelGenerator.java:217)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.internalDoGenerate(JvmModelGenerator.java:1970)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.doGenerate(JvmModelGenerator.java:198)
	at org.eclipse.xtext.generator.GeneratorDelegate.doGenerate(GeneratorDelegate.java:45)
	at org.eclipse.xtext.generator.GeneratorDelegate.generate(GeneratorDelegate.java:34)
	at org.eclipse.xtext.builder.standalone.StandaloneBuilder.generate(StandaloneBuilder.java:461)
	at org.eclipse.xtext.builder.standalone.StandaloneBuilder.launch(StandaloneBuilder.java:306)
	at org.eclipse.xtext.maven.XtextGenerator.internalExecute(XtextGenerator.java:165)
	at org.eclipse.xtext.maven.XtextGenerator.execute(XtextGenerator.java:142)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	... 21 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException


My POM:
...
<configuration>
	<failOnValidationError>false</failOnValidationError>
</configuration>
...
Re: Maven project fails during model validation [message #1772308 is a reply to message #1772305] Thu, 07 September 2017 19:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12322
Registered: July 2009
Senior Member
<setup>org.xtext.example.mydsl4.MyDslStandaloneSetup</setup>

if (prelinkingPhase)
return

is bad

acceptor.accept(toClass("name"))[
// this is executed in prelinking=false
]

i have the feeling you miss a return like

if (container.extensions !== null)
return container.extensions.provideImportNormalizerList(ignoreCase)


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Maven project fails during model validation [message #1772310 is a reply to message #1772308] Thu, 07 September 2017 19:50 Go to previous messageGo to next message
Miguel Jimenez is currently offline Miguel JimenezFriend
Messages: 38
Registered: July 2015
Member
Thanks for the quick reply Christian.

You were right about the return statement, I applied both suggestions to my code and it worked.

Thank you!
Re: Maven project fails during model validation [message #1772312 is a reply to message #1772310] Fri, 08 September 2017 01:10 Go to previous messageGo to next message
Miguel Jimenez is currently offline Miguel JimenezFriend
Messages: 38
Registered: July 2015
Member
Christian,
Something weird is happening when I try to include this into my language. It seems there is a problem
integrating a custom qualified name provider and my previous code. I only added the following code and it
stopped working:

MyDslQualifiedNameProvider.xtend
package org.xtext.example.mydsl.runtime

import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider

class MyDslQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {
	
}


MyDslRuntimeModule.xtend
package org.xtext.example.mydsl

import com.google.inject.Binder
import com.google.inject.name.Names
import org.eclipse.xtext.scoping.IScopeProvider
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider
import org.xtext.example.mydsl.scoping.MyDslImportSectionNamespaceScopeProvider
import org.xtext.example.mydsl.runtime.MyDslQualifiedNameProvider
import org.eclipse.xtext.naming.IQualifiedNameProvider

class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
	override void configureIScopeProviderDelegate(Binder binder) {
		binder.bind(IScopeProvider)
			.annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE))
			.to(MyDslImportSectionNamespaceScopeProvider);
	}
	override Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return MyDslQualifiedNameProvider
	} 
}


The error is the same I was getting before:

...
[INFO] --- xtext-maven-plugin:2.10.0:generate (default) @ example ---
[INFO] Encoding: not set. Encoding provider will be used.
[INFO] Compiler source level: 1.6
[INFO] Compiler target level: 1.6
[INFO] Using common types.
[INFO] Collecting source models.
[INFO] Installing type provider.
[INFO] Generating stubs into /Users/miguel/Development/workspace-xtext/example/target/xtext-temp/stubs
[INFO] Compiling stubs located in /Users/miguel/Development/workspace-xtext/example/target/xtext-temp/stubs
[INFO] Nothing to compile. Stubs compilation was skipped.
[INFO] Installing type provider for stubs.
[INFO] Validate and generate.
[INFO] Starting validation for input: 'foo.mydsl'
[INFO] Starting validation for input: 'hello.mydsl'
[ERROR] ERROR:B cannot be resolved. (file:/Users/miguel/Development/workspace-xtext/example/src/main/mydsl/hello/hello.mydsl line : 5 column : 7)
...


Do you know why is this happening?
Re: Maven project fails during model validation [message #1772316 is a reply to message #1772312] Fri, 08 September 2017 04:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12322
Registered: July 2009
Senior Member
xbase uses XbaseQualifiedNameProvider not DefaultDeclarativeQualifiedNameProvider

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Maven project fails during model validation [message #1772317 is a reply to message #1772316] Fri, 08 September 2017 05:15 Go to previous message
Miguel Jimenez is currently offline Miguel JimenezFriend
Messages: 38
Registered: July 2015
Member
Thanks for the quick reply. It's working now.
Previous Topic:Use of proposalprovider for content-assist
Next Topic:[ERROR] org.eclipse.xtext.service.CompoundModule - maybe Validations?
Goto Forum:
  


Current Time: Thu Oct 18 01:08:29 GMT 2018

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

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

Back to the top