I've managed to implement a standalone generator with the tutorial on typefox named how-and-why-use-xtext-without-the-ide
What I cannot achieve is the output configuration.
In my generator, the output config values are used while creating and when I run the same with the standalone generator, it shows DEFAULT_OUTPUT_FAMEorg/eclipse/Fame.java when I print out the file name.
class FameGeneratorRunner {
def static void main(String[] args) {
val injector = new FameStandaloneSetup().createInjectorAndDoEMFRegistration();
val resourceSet = injector.getInstance(XtextResourceSet);
val resource = resourceSet.getResource(URI.createFileURI("benlock.fm"), true);
val generator = injector.getInstance(FameGenerator);
val fsa = new InMemoryFileSystemAccess();
generator.doGenerate(resource, fsa);
for (Entry<String, CharSequence> file : fsa.getTextFiles().entrySet()) {
println("Generated file path : "+file.getKey());
println("Generated file contents : "+file.getValue());
}
}
}
class FameGenerator implements IGenerator{
@Inject extension IQualifiedNameProvider
Resource res
override doGenerate(Resource resource, IFileSystemAccess fsa) {
res=resource;
val basePackage = resource.allContents.filter(MainRule).next.fullyQualifiedName
fsa.generateFile(basePackage.toString("/") + "/api/exception/InitFailedException.java", "DEFAULT_OUTPUT_FAME", basePackage.compileInitFailedException)
for (struct : resource.allContents.toIterable.filter(GlamourType)) {
val glamour = struct.fullyQualifiedName.lastSegment.toFirstUpper
fsa.generateFile(basePackage.toString("/") + "/" + glamour +
".java", "DEFAULT_OUTPUT_FAME", struct.compile)
}
public Set<OutputConfiguration> getOutputConfigurations() {
OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess2.DEFAULT_OUTPUT);
defaultOutput.setDescription("Output Folder");
defaultOutput.setOutputDirectory("./src-gen");
defaultOutput.setOverrideExistingResources(true);
defaultOutput.setCreateOutputDirectory(true);
defaultOutput.setCleanUpDerivedResources(true);
defaultOutput.setSetDerivedProperty(true);
OutputConfiguration fameOutput = new OutputConfiguration(DEFAULT_OUTPUT_FAME);
onceOutput.setDescription("Java source folder");
onceOutput.setOutputDirectory("./src/main/java");
onceOutput.setOverrideExistingResources(true);
onceOutput.setCreateOutputDirectory(true);
onceOutput.setCleanUpDerivedResources(false);
onceOutput.setSetDerivedProperty(true);
Could some one please help me understand why everything works well whilst running via an Eclipse application but no file is generated via the standalone procedure. Is it because the IOutputConfiguration is a part of eclipse application process or something? Thank you in advance.