String componentId = component.split("-")[1];
templateContext.put("componentId", componentId);
String componentClass = findComponentFQCN(component, selectedVersion);
templateContext.put("componentClass", componentClass);
UIPrompt prompt = context.getPrompt();
if (!prompt.promptBoolean("File '" + outputFilePath + "' already exists. Do you want to overwrite it?")) {
return Results.fail("File '" + outputFilePath + "' already exists.");
}
fileResource.createNewFile();
fileResource.setContents(template.process(templateContext));
break;
}
case SPRING: {
ResourcesFacet facet = getSelectedProject(context).getFacet(ResourcesFacet.class);
String outputFilePath = "META-INF" + File.separator + "spring" + File.separator + "components.xml";
FileResource<?> fileResource = facet.getResource(outputFilePath);
Resource<URL> xml = resourceFactory.create(getClass().getResource("/templates/my_spring.ftl")).reify(URLResource.class);
Template template = templateFactory.create(xml, FreemarkerTemplate.class);
Map<String, Object> templateContext = new HashMap<>();
String componentId = component.split("-")[1];
templateContext.put("componentId", componentId);
String componentClass = findComponentFQCN(component, selectedVersion);
templateContext.put("componentClass", componentClass);
UIPrompt prompt = context.getPrompt();
if (!prompt.promptBoolean("File '" + outputFilePath + "' already exists. Do you want to overwrite it?")) {
return Results.fail("File '" + outputFilePath + "' already exists.");
}
fileResource.createNewFile();
fileResource.setContents(template.process(templateContext));