Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Set XText content-type to UTF-8
Set XText content-type to UTF-8 [message #1060244] Thu, 23 May 2013 12:38 Go to next message
Ronan B is currently offline Ronan B
Messages: 195
Registered: July 2009
Senior Member
Hi,
I have an ATL transformation whose output is a file based on an XText grammar. On windows I always get the wrong encoding in the output file as I cannot rely on my users starting the JVM with UTF-8 encoding.

So I tried to follow the example code in http://www.eclipse.org/forums/index.php/m/818388/?srch=xtext+utf-8#msg_818388 without success.

I modified my XRuntimeModule with the following:

public Class<? extends IEncodingProvider> bindIEncodingProvider() {
return UTF8EncodingProvider.class;
}

I then added the new class UTF8EncodingProvider in the same package as follows:

public class UTF8EncodingProvider implements IEncodingProvider {

@Override
public String getEncoding(URI uri) {
return "utf-8";
}
}

Now after rebuilding and running I get the following errors:

!MESSAGE org.eclipse.core.runtime.CoreException: Failed to create injector for com.a.b.Yang ExtensionFactory: com.a.b.ui.YangExecutableExtensionFactory
!STACK 0
org.eclipse.emf.common.util.WrappedException: org.eclipse.core.runtime.CoreException: Failed to create injector for com.a.b.Yang ExtensionFactory: com.a.b.ui.YangExecutableExtensionFactory
at org.eclipse.emf.ecore.plugin.RegistryReader$PluginClassDescriptor.createInstance(Unknown Source)
at org.eclipse.emf.ecore.plugin.RegistryReader$ResourceFactoryDescriptor.createFactory(Unknown Source)
at org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl.convert(Unknown Source)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$2.delegatedGetFactory(Unknown Source)
at org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl.getFactory(Unknown Source)
at org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl.getFactory(Unknown Source)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(Unknown Source)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(Unknown Source)
at org.eclipse.m2m.atl.core.emf.EMFExtractor.createResource(Unknown Source)
at org.eclipse.m2m.atl.core.emf.EMFExtractor.recreateResourceIfNeeded(Unknown Source)
at org.eclipse.m2m.atl.core.emf.EMFExtractor.extract(Unknown Source)
at com.a.c.launcher.transformations.LauncherService.launch(Unknown Source)
at com.a.c.launcher.transformations.M2MLauncher.convert(Unknown Source)
at com.a.c.yang.launcher.extension.YangTransform.runYangModuleTransform(Unknown Source)
at com.a.c.yang.launcher.extension.YangTransform.runYangTransforms(Unknown Source)
at com.a.c.yang.launcher.extension.YangTransform.run(Unknown Source)
at com.a.c.launcher.transformations.internal.TransformationJob.runCustomTransforms(Unknown Source)
at com.a.c.launcher.transformations.internal.TransformationJob.run(Unknown Source)
at org.eclipse.core.internal.jobs.Worker.run(Unknown Source)
Caused by: org.eclipse.core.runtime.CoreException: Failed to create injector for com.a.b.Yang ExtensionFactory: com.a.b.ui.YangExecutableExtensionFactory
at org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory.create(Unknown Source)
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(Unknown Source)
at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(Unknown Source)
... 19 more
Caused by: java.lang.RuntimeException: Failed to create injector for com.a.b.Yang
at com.a.b.ui.internal.YangActivator.createInjector(Unknown Source)
at com.a.b.ui.internal.YangActivator.getInjector(Unknown Source)
at com.a.b.ui.YangExecutableExtensionFactory.getInjector(Unknown Source)
... 22 more
Caused by: com.google.inject.CreationException: Guice creation errors:

1) A binding to org.eclipse.xtext.parser.IEncodingProvider was already configured at org.eclipse.xtext.service.MethodBasedModule.configure(Unknown Source).
at org.eclipse.xtext.service.MethodBasedModule.configure(Unknown Source)

1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Unknown Source)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(Unknown Source)
at com.google.inject.internal.InternalInjectorCreator.build(Unknown Source)
at com.google.inject.Guice.createInjector(Unknown Source)
at com.google.inject.Guice.createInjector(Unknown Source)
at com.google.inject.Guice.createInjector(Unknown Source)
... 25 more

What am I doing wrong? It seems very complicated to change the output encoding type. Maybe I missed something obvious.

Thanks!
Ronan
Re: Set XText content-type to UTF-8 [message #1060265 is a reply to message #1060244] Thu, 23 May 2013 13:37 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander Nittka
Messages: 1085
Registered: July 2009
Senior Member
Hi,

I'd say you did not *@Override* an existing binding (use a quick ouline search for encoding), but define a new one.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Set XText content-type to UTF-8 [message #1060380 is a reply to message #1060265] Fri, 24 May 2013 07:16 Go to previous message
Ronan B is currently offline Ronan B
Messages: 195
Registered: July 2009
Senior Member
Hi Alex,
Thanks but I searched the code and could not find an existing binding definition. I could not use @Override on my public Class<? extends IEncodingProvider> bindIEncodingProvider() definition as Java complains saying "The method bindIEncodingProvider() of type YangRuntimeModule must override or implement a supertype method".

Anyways I tried an alternate solution in my RuntimeModule, as follows:

@Override
public void configureRuntimeEncodingProvider(Binder binder) {
binder.bind(IEncodingProvider.class)
.annotatedWith(DispatchingProvider.Runtime.class)
.to(UTF8EncodingProvider.class);
}

This does the trick. Inspiration from https://github.com/eclipse/xtext/blob/master/docs/org.eclipse.xtext.doc.xdoc/xdoc/115-encoding.xdoc

Regards,
Ronan
Previous Topic:Getting bean properties from JvmGenericType
Next Topic:XExpression to String
Goto Forum:
  


Current Time: Tue May 28 17:10:09 EDT 2013

Powered by FUDForum. Page generated in 0.01474 seconds