[Solved] Specify path of file to generate [message #1827174] |
Sat, 09 May 2020 10:00 |
Luca Reccia Messages: 14 Registered: May 2020 |
Junior Member |
|
|
This is my main code, I would like xtext generate the output file with a specific name instead of its random name.
At the moment it uses the outPath as folder in which it places the generated file.
I would like to create the file with name specified in the outPath.
I didn't manage to find anything in the documentation.
class Main2 {
def static main(String[] args) {
if (args.empty) {
System::err.println('Usage: <path_to_input_file> <path_to_output_file>')
return
}
val injector = new MGrammarStandaloneSetup().createInjectorAndDoEMFRegistration
val main = injector.getInstance(Main2)
main.runGenerator(args.get(0), args.get(1))
}
@Inject Provider<ResourceSet> resourceSetProvider
@Inject IResourceValidator validator
@Inject GeneratorDelegate generator
@Inject JavaIoFileSystemAccess fileAccess
def protected runGenerator(String inPath, String outPath) {
// Load the resource
val set = resourceSetProvider.get
val resource = set.getResource(URI.createFileURI(inPath), true)
// Validate the resource
val issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)
if (!issues.empty) {
issues.forEach[System.err.println(it)]
return
}
// Configure and start the generator
fileAccess.outputPath = outPath
val context = new GeneratorContext => [
cancelIndicator = CancelIndicator.NullImpl
]
generator.generate(resource, fileAccess, context)
System.out.println('Code generation finished.')
}
}
thanks
[Updated on: Sat, 09 May 2020 14:32] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04153 seconds