Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Validator with property file involved
Validator with property file involved [message #1834606] Fri, 13 November 2020 12:21
Alexandra Tritean is currently offline Alexandra TriteanFriend
Messages: 37
Registered: March 2020
Member
Hello,

Is there a way in which I can 'inject' the IFileSystemAccess2 in a validator or which will be correct way of writing a check that needs to access a property file?

I will try to be more explicit by trying to explain what I'm trying to achieve.
I have a maven project where the DSL file is stored and when validating the file, I want to read a property from the pom.xml stored in the same project.

I wrote the following check:
@Check
def checkDslReleasePropertyIsDefined(Context context){
	val resource = context.eResource
	val platformString = resource.URI.toPlatformString(true);
   	val resourceAsFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformString));
    	val project = resourceAsFile.getProject();
	val pomFile = project.getFile("pom.xml")
	val pomFileContent = pomFile.contents 
	val dslRelease = ValidatorHelper.getDslVersionFromPom(pomFileContent)
	if (dslRelease.empty) {
	    error('The property <dsl.release> is missing in the pom file of the project ' + project.name, DatamodelDslPackage.Literals.CONTEXT__NAME)
      }
}
	


Unfortunately, when running the xtext-maven-plugin via a maven clean install, I'm getting the following stacktrace:

[INFO] Starting validation for input: 'Base_Context-1.0.0.datamodel'
[ERROR] Error executing EValidator
java.lang.IllegalStateException: Workspace is closed.
at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:432)
at com.wkfsfrc.rr.tools.ruledesigner.datamodel.validation.DatamodelDslValidator.checkDslReleasePropertyIsDefined(DatamodelDslValidator.java:74)
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.eclipse.xtext.validation.AbstractDeclarativeValidator$MethodWrapper.invoke(AbstractDeclarativeValidator.java:127)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.internalValidate(AbstractDeclarativeValidator.java:318)
at org.eclipse.xtext.validation.AbstractInjectableValidator.validate(AbstractInjectableValidator.java:71)
at org.eclipse.xtext.validation.CompositeEValidator.validate(CompositeEValidator.java:150)
at org.eclipse.emf.ecore.util.Diagnostician.doValidate(Diagnostician.java:171)
at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:158)
at org.eclipse.xtext.validation.CancelableDiagnostician.validate(CancelableDiagnostician.java:40)
at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:137)
at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:120)
at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:146)
at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:124)
at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:90)
at org.eclipse.xtext.builder.standalone.StandaloneBuilder.validate(StandaloneBuilder.java:378)
at org.eclipse.xtext.builder.standalone.StandaloneBuilder.launch(StandaloneBuilder.java:267)
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:957)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
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)


I know that I can use IFileSystemAccess2 in order to read files more easily (I'm using it in other places as well), but I'm not sure if it can be use also in this case or if I can get the pom.xml file without using 'workspace operations'.

Thank you!

Kind Regards,

Alexandra
Previous Topic:IllegalStateException during maven build of Xtext project
Next Topic:The path is unmapped
Goto Forum:
  


Current Time: Fri Apr 19 09:34:27 GMT 2024

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

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

Back to the top