|
|
|
|
|
|
|
|
|
Re: Exporting Parser+Generator as standalone jar file [message #912444 is a reply to message #912400] |
Thu, 13 September 2012 15:41 |
mcse mcse Messages: 53 Registered: August 2012 |
Member |
|
|
Hi Christian,
I have just copied and pasted this from the arguments of the configuration that opens
eclipse editor when run. Do you think that I left the arguments empty for the Java Launch configuration ?
My Main.java has the following content:
public class Main {
public static void main(String[] args) {
if (args.length==0) {
System.err.println("Aborting: no path to EMF resource provided!");
return;
}
Injector injector = new org.xtext.example.mydsl.XcDStandaloneSetupGenerated().createInjectorAndDoEMFRegistration();
Main main = injector.getInstance(Main.class);
main.runGenerator(args[0]);
}
@Inject
private Provider<ResourceSet> resourceSetProvider;
@Inject
private IResourceValidator validator;
@Inject
private IGenerator generator;
@Inject
private JavaIoFileSystemAccess fileAccess;
protected void runGenerator(String string) {
// load the resource
ResourceSet set = resourceSetProvider.get();
Resource resource = set.getResource(URI.createURI(string), true);
// validate the resource
List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
if (!list.isEmpty()) {
for (Issue issue : list) {
System.err.println(issue);
}
return;
}
// configure and start the generator
fileAccess.setOutputPath("src-gen/");
generator.doGenerate(resource, fileAccess);
System.out.println("Code generation finished.");
}
}
So, is what you are suggesting to add the following snippet inside the above main.java ? THe below snippet is obtained from "StandaloneSetupGenerated.java"
public Injector createInjectorAndDoEMFRegistration() {
// register default ePackages
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"ecore", new org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl());
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"xmi", new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl());
if (!EPackage.Registry.INSTANCE.containsKey(org.eclipse.xtext.XtextPackage.eNS_URI))
EPackage.Registry.INSTANCE.put(org.eclipse.xtext.XtextPackage.eNS_URI, org.eclipse.xtext.XtextPackage.eINSTANCE);
Injector injector = createInjector();
register(injector);
return injector;
}
public Injector createInjector() {
return Guice.createInjector(new org.xtext.example.mydsl.XcDRuntimeModule());
}
public void register(Injector injector) {
if (!EPackage.Registry.INSTANCE.containsKey("...")) {
EPackage.Registry.INSTANCE.put("...", org.xtext.example.mydsl.myDsl.MyDslPackage.eINSTANCE);
}
org.eclipse.xtext.resource.IResourceFactory resourceFactory = injector.getInstance(org.eclipse.xtext.resource.IResourceFactory.class);
org.eclipse.xtext.resource.IResourceServiceProvider serviceProvider = injector.getInstance(org.eclipse.xtext.resource.IResourceServiceProvider.class);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xcd", resourceFactory);
org.eclipse.xtext.resource.IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("xcd", serviceProvider);
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06372 seconds