private static void renderPomXml(MavenizationService.MavenizationContext mavCtx, Pom pom, Path pomXmlPath) { Map vars = new HashMap(); vars.put("pom", pom); vars.put("config", mavCtx.getGraphContext().getUnique(WindupConfigurationModel.class)); Path template = chooseTemplate(pom); try { LOG.info("Rendering template: " + template + " into " + pomXmlPath + System.lineSeparator()+" - " + pom); Files.createDirectories(pomXmlPath.getParent()); renderFreemarkerTemplate(template, vars, pomXmlPath); } catch (ParseException ex) { throw new WindupException("Could not parse pom.xml template: " + template + System.lineSeparator()+" Reason: " + ex.getMessage(), ex); } catch (IOException | TemplateException ex) { throw new WindupException("Error rendering pom.xml template: " + template + System.lineSeparator()+" Reason: " + ex.getMessage(), ex); } }
private static void renderPomXml(MavenizationService.MavenizationContext mavCtx, Pom pom, Path pomXmlPath) { Map vars = new HashMap(); vars.put("pom", pom); vars.put("config", mavCtx.getGraphContext().getUnique(WindupConfigurationModel.class)); Path template = chooseTemplate(pom); try { LOG.info("Rendering template: " + template + " into " + pomXmlPath + System.lineSeparator()+" - " + pom); Files.createDirectories(pomXmlPath.getParent()); renderFreemarkerTemplate(template, vars, pomXmlPath); } catch (ParseException ex) { throw new WindupException("Could not parse pom.xml template: " + template + System.lineSeparator()+" Reason: " + ex.getMessage(), ex); } catch (IOException | TemplateException ex) { throw new WindupException("Error rendering pom.xml template: " + template + System.lineSeparator()+" Reason: " + ex.getMessage(), ex); } }
/** * Validates if the given freemarker context is syntactically correct. * * @param freemarkerContent * @throws AMWException * if the template can not be successfully validate. The error message distincts between * parsing exceptions and other (unexpected) potential issues. */ public void validateFreemarkerSyntax(String freemarkerContent) throws AMWException { Objects.requireNonNull(freemarkerContent, "freemarker content must not be null"); Configuration c = new Configuration(); c.setStrictSyntaxMode(true); c.setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX); String templateName = "validation"; StringTemplateLoader stringLoader = new StringTemplateLoader(); stringLoader.putTemplate(templateName, freemarkerContent); c.setTemplateLoader(stringLoader); try { c.getTemplate(templateName); } catch (ParseException e) { // Validation failed! - was not able to parse the template! throw new AMWException("The template is syntactically incorrect: " + e.getMessage(), e); } catch (IOException e) { // Something else went wrong throw new AMWException("The template can not be validated: " + e.getMessage(), e); } }
throw new WPBTemplateException("Freemarker Template Exception " + e.getMessage(), e);
logBeforeException(pe); errorTemplate.addAllErrorMessages(Collections.singletonList(new TemplatePropertyException( "invalid template. " + pe.getMessage(), CAUSE.PROCESSING_EXCEPTION, pe))); generatedTemplates.add(errorTemplate);
+ templateNameString + "\n" + pe.getMessage(); throw new TemplateException(msg, pe, env);