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.
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.
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);
}