@Test public void generate() throws GeneratorException, IOException { ApplicationPropertiesSourceGenerator generator = getGenerator(); generator.generate(); Path propsPath = Files.find(resourceFolder.getRoot().toPath(), Integer.MAX_VALUE, (filePath, fileAttr) -> fileAttr.isRegularFile()) .filter(path -> path.toFile().getName().equals("application.properties")) .findFirst() .orElse(null); assertNotNull(propsPath); String propsAsString = FileUtils.readFileToString(propsPath.toFile()); assertTrue(propsAsString.contains("server.port")); assertTrue(propsAsString.contains("spring-boot.run.workingDirectory")); }
public void generate() throws GeneratorException { Configuration freeMarkerConfiguration = new Configuration(); freeMarkerConfiguration.setClassForTemplateLoading(WebXmlSourceGenerator.class, "/templates/properties"); freeMarkerConfiguration.setDefaultEncoding("UTF-8"); Template template; try { template = freeMarkerConfiguration.getTemplate("ApplicationProperties.ftl"); } catch (IOException e) { throw new GeneratorException("Unable to get >>ApplicationProperties.ftl<< -> exception: " + e.getMessage()); } if (!this.resourceDirectory.exists()) { this.resourceDirectory.mkdirs(); } Map<String, Object> templateData = new HashMap<>(); templateData.put("projectBuildDirectory", "${project.build.directory}"); try (StringWriter out = new StringWriter()) { template.process(templateData, out); Files.write(Paths.get(this.resourceDirectory.getPath() + File.separator + APPLICATION_PROPERTIES), out.toString() .getBytes()); out.flush(); } catch (IOException | TemplateException e) { throw new GeneratorException("Unable to write generated file: >>" + this.resourceDirectory.getPath() + File.separator + "application.properties" + "<< -> exception: " + e.getMessage()); } }
ApplicationPropertiesSourceGenerator { public void generate() throws GeneratorException { Configuration freeMarkerConfiguration = new Configuration(); freeMarkerConfiguration.setClassForTemplateLoading(WebXmlSourceGenerator.class, "/templates/properties"); freeMarkerConfiguration.setDefaultEncoding("UTF-8"); Template template; try { template = freeMarkerConfiguration.getTemplate("ApplicationProperties.ftl"); } catch (IOException e) { throw new GeneratorException("Unable to get >>ApplicationProperties.ftl<< -> exception: " + e.getMessage()); } if (!this.resourceDirectory.exists()) { this.resourceDirectory.mkdirs(); } Map<String, Object> templateData = new HashMap<>(); templateData.put("projectBuildDirectory", "${project.build.directory}"); try (StringWriter out = new StringWriter()) { template.process(templateData, out); Files.write(Paths.get(this.resourceDirectory.getPath() + File.separator + APPLICATION_PROPERTIES), out.toString() .getBytes()); out.flush(); } catch (IOException | TemplateException e) { throw new GeneratorException("Unable to write generated file: >>" + this.resourceDirectory.getPath() + File.separator + "application.properties" + "<< -> exception: " + e.getMessage()); } } }
ApplicationPropertiesSourceGenerator { public void generate() throws GeneratorException { Configuration freeMarkerConfiguration = new Configuration(); freeMarkerConfiguration.setClassForTemplateLoading(WebXmlSourceGenerator.class, "/templates/properties"); freeMarkerConfiguration.setDefaultEncoding("UTF-8"); Template template; try { template = freeMarkerConfiguration.getTemplate("ApplicationProperties.ftl"); } catch (IOException e) { throw new GeneratorException("Unable to get >>ApplicationProperties.ftl<< -> exception: " + e.getMessage()); } if (!this.resourceDirectory.exists()) { this.resourceDirectory.mkdirs(); } Map<String, Object> templateData = new HashMap<>(); templateData.put("projectBuildDirectory", "${project.build.directory}"); try (StringWriter out = new StringWriter()) { template.process(templateData, out); Files.write(Paths.get(this.resourceDirectory.getPath() + File.separator + APPLICATION_PROPERTIES), out.toString() .getBytes()); out.flush(); } catch (IOException | TemplateException e) { throw new GeneratorException("Unable to write generated file: >>" + this.resourceDirectory.getPath() + File.separator + "application.properties" + "<< -> exception: " + e.getMessage()); } } ApplicationPropertiesSourceGenerator(Builder builder); }
ApplicationPropertiesSourceGenerator { public void generate() throws GeneratorException { Configuration freeMarkerConfiguration = new Configuration(); freeMarkerConfiguration.setClassForTemplateLoading(WebXmlSourceGenerator.class, "/templates/properties"); freeMarkerConfiguration.setDefaultEncoding("UTF-8"); Template template; try { template = freeMarkerConfiguration.getTemplate("ApplicationProperties.ftl"); } catch (IOException e) { throw new GeneratorException("Unable to get >>ApplicationProperties.ftl<< -> exception: " + e.getMessage()); } if (!this.resourceDirectory.exists()) { this.resourceDirectory.mkdirs(); } Map<String, Object> templateData = new HashMap<>(); templateData.put("projectBuildDirectory", "${project.build.directory}"); try (StringWriter out = new StringWriter()) { template.process(templateData, out); Files.write(Paths.get(this.resourceDirectory.getPath() + File.separator + APPLICATION_PROPERTIES), out.toString() .getBytes()); out.flush(); } catch (IOException | TemplateException e) { throw new GeneratorException("Unable to write generated file: >>" + this.resourceDirectory.getPath() + File.separator + "application.properties" + "<< -> exception: " + e.getMessage()); } } ApplicationPropertiesSourceGenerator(Builder builder); void generate(); static Builder builder(); }
ApplicationPropertiesSourceGenerator { public void generate() throws GeneratorException { Configuration freeMarkerConfiguration = new Configuration(); freeMarkerConfiguration.setClassForTemplateLoading(WebXmlSourceGenerator.class, "/templates/properties"); freeMarkerConfiguration.setDefaultEncoding("UTF-8"); Template template; try { template = freeMarkerConfiguration.getTemplate("ApplicationProperties.ftl"); } catch (IOException e) { throw new GeneratorException("Unable to get >>ApplicationProperties.ftl<< -> exception: " + e.getMessage()); } if (!this.resourceDirectory.exists()) { this.resourceDirectory.mkdirs(); } Map<String, Object> templateData = new HashMap<>(); templateData.put("projectBuildDirectory", "${project.build.directory}"); try (StringWriter out = new StringWriter()) { template.process(templateData, out); Files.write(Paths.get(this.resourceDirectory.getPath() + File.separator + APPLICATION_PROPERTIES), out.toString() .getBytes()); out.flush(); } catch (IOException | TemplateException e) { throw new GeneratorException("Unable to write generated file: >>" + this.resourceDirectory.getPath() + File.separator + "application.properties" + "<< -> exception: " + e.getMessage()); } } ApplicationPropertiesSourceGenerator(Builder builder); void generate(); static Builder builder();  }