Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom FragmentProvider : issue with Acceleo
Custom FragmentProvider : issue with Acceleo [message #1786233] Fri, 27 April 2018 12:43 Go to next message
Emilien Lavigne is currently offline Emilien LavigneFriend
Messages: 5
Registered: October 2017
Junior Member
Hello,

I have an xtext DSL to describe some component's templates. It is based on a custom metamodel "template.ecore". Both the metamodel and the DSL projects are exported in plugins.

In an other workspace, I have a "My.template" file , where i declare some templates.
In an XMI file ("My.component") based on an other metamodel ("component.ecore", which contains references to "template.ecore"), I can reference the templates contained in My.template, and it works fine


I want to run an Acceleo script on My.component, so in the Acceleo project:
- In the registerPackages method, after registering the "template" and "component" package, I manually load the "My.template" file :
public void registerPackages(ResourceSet resourceSet) {
        super.registerPackages(resourceSet);
        if (!isInWorkspace(AMSA.ComponentPackage.class)) {
            resourceSet.getPackageRegistry().put(AMSA.ComponentPackage.eINSTANCE.getNsURI(), AMSA.ComponentPackage.eINSTANCE);
        }
      
        if (!isInWorkspace(AMSAt.TemplatePackage.class)) {
            resourceSet.getPackageRegistry().put(AMSAt.TemplatePackage.eINSTANCE.getNsURI(), AMSAt.TemplatePackage.eINSTANCE);
        }

        try {
	        URI model2URI = URI.createFileURI("Path-to-My.template");
		ModelUtils.load(model2URI, resourceSet);
	} catch (IOException e) {
	        e.printStackTrace();
	}
}

- In the registerResourceFactories method, I call the doSetup method of the DSL:
    public void registerResourceFactories(ResourceSet resourceSet) {
        super.registerResourceFactories(resourceSet);
        
        amsaTemplate.xtext.TemplateDescriptionStandaloneSetup.doSetup();
    }


Until then, everything works fine, I can use components and templates in my Acceleo scripts.

Problem appears when I try to implement my own Fragment Provider in the DSL, in order to reference the templates with their qualified names instead of their positions (following this article : Cross-References from XMI to Xtext)

I add a AmsaTemplateFragmentProvider.xtend file in the DSL sources :
package amsaTemplate.xtext.ressource

import com.google.inject.Inject
import java.util.Map
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.naming.IQualifiedNameConverter
import org.eclipse.xtext.naming.IQualifiedNameProvider
import org.eclipse.xtext.resource.IFragmentProvider
import org.eclipse.xtext.util.IResourceScopeCache


class AmsaTemplateFragmentProvider implements IFragmentProvider {
	
	@Inject IQualifiedNameConverter qualifiedNameConverter
	@Inject IQualifiedNameProvider qualifiedNameProvider
	@Inject IResourceScopeCache cache
	
	static val CACHE_KEY = 'name2element'
	
	override getEObject(Resource resource, String fragment, Fallback fallback) {
		try {
			val qualifiedName = qualifiedNameConverter.toQualifiedName(fragment)
			return getName2ElementMap(resource, fallback).get(qualifiedNameConverter.toString(qualifiedName))
		} catch (Exception exc) {
			return fallback.getEObject(fragment)
		}
	}
	
	/** 
	 * Returns a map qualifiedName -> EObject that is calculated on demand and cached. 
	 */
	def private Map<String, EObject> getName2ElementMap(Resource resource, Fallback fallback) {
		cache.get(CACHE_KEY, resource, [
			val name2element = <String, EObject>newHashMap
			resource.allContents.forEach [
				name2element.put(getFragment(it, fallback), it)
			]
			return name2element
		])
	}
	
	override getFragment(EObject obj, Fallback fallback) {
		try {
			return qualifiedNameConverter.toString(qualifiedNameProvider.getFullyQualifiedName(obj))
		}
		catch (Exception exc) {
			return fallback.getFragment(obj)
		}
	}
}


And then I bind it in the TemplateDescriptionRuntimeModule.xtend file
/*
 * generated by Xtext 2.13.0
 */
package amsaTemplate.xtext

import amsaTemplate.xtext.ressource.AmsaTemplateFragmentProvider

/**
 * Use this class to register components to be used at runtime / without the Equinox extension registry.
 */
class TemplateDescriptionRuntimeModule extends AbstractTemplateDescriptionRuntimeModule {
	override bindIFragmentProvider() {
		AmsaTemplateFragmentProvider
	}
}


The fragmentPovider works fine so qualified named are used to reference the templates in the XMI (and the links work in the XMI editor), but when i try to launch the acceleo application, I have the following exception :

Quote:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/xtext/xbase/lib/Exceptions
at amsaTemplate.xtext.ressource.AmsaTemplateFragmentProvider.getEObject(AmsaTemplateFragmentProvider.java:42)
at org.eclipse.xtext.resource.XtextResource.basicGetEObject(XtextResource.java:363)
at org.eclipse.xtext.resource.XtextResource.getEObject(XtextResource.java:349)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:232)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:223)
at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:201)
at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:261)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1477)
at AMSA.impl.LeafComponentImpl.getLeafTemplate(LeafComponentImpl.java:130)
at AMSA.impl.LeafComponentImpl.eGet(LeafComponentImpl.java:201)
...


Did I miss something to activate or register the FragmentProvder in a standalone use case ? I don't find anything about it...

Thanks for your help,
Best regards

Emilien
Re: Custom FragmentProvider : issue with Acceleo [message #1786236 is a reply to message #1786233] Fri, 27 April 2018 13:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
How do you do the standalone execution and how do you populate the classpath

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Custom FragmentProvider : issue with Acceleo [message #1786237 is a reply to message #1786236] Fri, 27 April 2018 13:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
(This Part of the trace is missing)

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Custom FragmentProvider : issue with Acceleo [message #1786239 is a reply to message #1786237] Fri, 27 April 2018 13:42 Go to previous messageGo to next message
Emilien Lavigne is currently offline Emilien LavigneFriend
Messages: 5
Registered: October 2017
Junior Member
Hi Christian Dietrich,

Thanks for the answer.
In Eclipse, i use an Acceleo run configuration which launch the main method of the java class generated by Acceleo (same class where I call the doSetup in the registerResourceFactories method)

Here is the full exception trace :
Quote:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/xtext/xbase/lib/Exceptions
at amsaTemplate.xtext.ressource.AmsaTemplateFragmentProvider.getEObject(AmsaTemplateFragmentProvider.java:42)
at org.eclipse.xtext.resource.XtextResource.basicGetEObject(XtextResource.java:363)
at org.eclipse.xtext.resource.XtextResource.getEObject(XtextResource.java:349)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:232)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:223)
at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:201)
at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:261)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1477)
at AMSA.impl.LeafComponentImpl.getLeafTemplate(LeafComponentImpl.java:130)
at AMSA.impl.LeafComponentImpl.eGet(LeafComponentImpl.java:201)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1011)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1003)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:998)
at org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.navigateProperty(EcoreEvaluationEnvironment.java:250)
at org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.navigateProperty(EcoreEvaluationEnvironment.java:1)
at org.eclipse.ocl.EvaluationVisitorImpl.visitPropertyCallExp(EvaluationVisitorImpl.java:2325)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitPropertyCallExp(AcceleoEvaluationVisitor.java:1246)
at org.eclipse.ocl.ecore.impl.PropertyCallExpImpl.accept(PropertyCallExpImpl.java:236)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor$ParameterInitExpression.accept(AcceleoEvaluationVisitor.java:2055)
at org.eclipse.ocl.AbstractEvaluationVisitor.safeVisitExpression(AbstractEvaluationVisitor.java:569)
at org.eclipse.ocl.EvaluationVisitorImpl.visitVariable(EvaluationVisitorImpl.java:2378)
at org.eclipse.ocl.EvaluationVisitorDecorator.visitVariable(EvaluationVisitorDecorator.java:334)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.prepareInvocation(AcceleoEvaluationVisitor.java:1679)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoTemplateInvocation(AcceleoEvaluationVisitor.java:955)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1945)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoFileBlock(AcceleoEvaluationVisitor.java:431)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1935)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoLetBlock(AcceleoEvaluationVisitor.java:705)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1957)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoTemplate(AcceleoEvaluationVisitor.java:922)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1906)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoTemplateInvocation(AcceleoEvaluationVisitor.java:973)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1945)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoTemplate(AcceleoEvaluationVisitor.java:922)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1906)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoTemplateInvocation(AcceleoEvaluationVisitor.java:973)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1945)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoForBlock(AcceleoEvaluationVisitor.java:537)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1922)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoTemplate(AcceleoEvaluationVisitor.java:922)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1906)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoTemplateInvocation(AcceleoEvaluationVisitor.java:973)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1945)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoTemplate(AcceleoEvaluationVisitor.java:922)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1906)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
at org.eclipse.ocl.internal.evaluation.QueryImpl.evaluate(QueryImpl.java:146)
at org.eclipse.ocl.ecore.QueryImpl.evaluate(QueryImpl.java:56)
at org.eclipse.acceleo.engine.generation.AcceleoEngine.doEvaluate(AcceleoEngine.java:365)
at org.eclipse.acceleo.engine.generation.AcceleoEngine.evaluate(AcceleoEngine.java:142)
at org.eclipse.acceleo.engine.service.AcceleoService.doGenerateTemplate(AcceleoService.java:984)
at org.eclipse.acceleo.engine.service.AcceleoService.doGenerate(AcceleoService.java:641)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.generate(AbstractAcceleoGenerator.java:209)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.generate(AbstractAcceleoGenerator.java:172)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.doGenerate(AbstractAcceleoGenerator.java:159)
at AMSA.Simulation.acceleo.main.SimulatorGeneration.doGenerate(SimulatorGeneration.java:212)
at AMSA.Simulation.acceleo.main.SimulatorGeneration.main(SimulatorGeneration.java:170)
Caused by: java.lang.ClassNotFoundException: org.eclipse.xtext.xbase.lib.Exceptions
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 67 more

Re: Custom FragmentProvider : issue with Acceleo [message #1786241 is a reply to message #1786239] Fri, 27 April 2018 13:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
For me it looks like the classpath of that main misses some required stuff (xbase.lib)

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Custom FragmentProvider : issue with Acceleo [message #1786242 is a reply to message #1786241] Fri, 27 April 2018 13:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6042
Registered: July 2009
Senior Member
Hi

Are you sure that is the full stack trace? It looks suspiciously like there is a deeper nested exception. Probably identifying the missing xbase.lib.

You can simplify the failure by attempting to construct an org/eclipse/xtext/xbase/lib/Exceptions at the start of main().

If you provide a repro you can get an informed response rather than a guess.

Regards

Ed Willink
Re: Custom FragmentProvider : issue with Acceleo [message #1786252 is a reply to message #1786242] Fri, 27 April 2018 17:36 Go to previous messageGo to next message
Emilien Lavigne is currently offline Emilien LavigneFriend
Messages: 5
Registered: October 2017
Junior Member
Hi,

Thanks for the answers

@Ed Wililnk, I tried to construct an org/eclipse/xtext/xbase/lib/Exceptions in the Main method, so I explicitly added the dependency to the org.eclipse.xtext.xbase.lib package in the manifest of the Acceleo project, and the error disappear...
I checked that this package was in the dependencies of the xtext project... I don't understand why i need to put it again in the Acceleo project...

By the way, it works with that, and I can run the acceleo generator with my cross-ref using qualified names, that was my first goal !

Regards,

Emilien
Re: Custom FragmentProvider : issue with Acceleo [message #1786261 is a reply to message #1786252] Sat, 28 April 2018 07:11 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6042
Registered: July 2009
Senior Member
Hi

When you run an Acceleo transformation you are running a standalone Java application with some help from Eclipse in that the classpath is auto-generated from the MANIFEST.MF; it uses only what is registered in the MANIFEST.MF.

When you edit an Acceleo transformation you are running within Eclipse and everything registered in your Eclipse workspace can be accessible.

Adding org/eclipse/xtext/xbase/lib/Exceptions in the Main method forced you to fix the defective MANIFEST.MF. However since you already had an XXXStandaloneSetup() call one might hope that the transitive dependency on org/eclipse/xtext/xbase/lib would be there automatically. Without a repro I cannot tell whether there is an Xtext bug or not. It looks as if the XXX MANIFEST.MF should export org/eclipse/xtext/xbase/lib. Perhaps your XXX MANIFEST.MFgen has the relevant declaration awaiting your update of XXX 's MANIFEST.MF.

Regards

Ed Willink
Previous Topic:Problem with Linking to library models
Next Topic:How can i override XTextBuilder ??
Goto Forum:
  


Current Time: Mon Sep 24 13:25:17 GMT 2018

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

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

Back to the top