in support/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateRestXML.java [52:90]
public void execute() throws MojoExecutionException {
if (inputFile == null) {
throw new MojoExecutionException("Missing input file: " + inputFile);
}
Path input = Paths.get(this.inputFile);
if (!Files.exists(input)) {
throw new MojoExecutionException("Unable to read the input file: " + inputFile);
}
try {
OpenAPI document = new OpenAPIV3Parser().read(inputFile);
final Writer writer;
if (outputFile != null) {
Path output = Paths.get(this.outputFile);
if (output.getParent() != null && Files.notExists(output.getParent())) {
Files.createDirectories(output.getParent());
}
if (Files.exists(output)) {
Files.delete(output);
}
writer = Files.newBufferedWriter(output);
} else {
writer = new PrintWriter(System.out);
}
final CamelContext context = new DefaultCamelContext();
final String dsl = RestDslXmlGenerator.toXml(document).generate(context);
try (writer) {
writer.write(dsl);
}
} catch (Exception e) {
throw new MojoExecutionException("Exception while generating rest xml", e);
}
}