private List<Template> loadTemplates(File templatePath) { List<File> files; try (Stream<Path> paths = Files.walk(Paths.get(templatePath.getAbsolutePath()), 1)) { files = paths.map(i -> i.toAbsolutePath().toFile()).collect(Collectors.toList()); } catch (IOException e) { throw new SkipperException("Could not process files in template path " + templatePath, e); } List<Template> templates = new ArrayList<>(); for (File file : files) { if (isYamlFile(file)) { Template template = new Template(); template.setName(file.getName()); try { template.setData(new String(Files.readAllBytes(file.toPath()), "UTF-8")); } catch (IOException e) { throw new SkipperException("Could read template file " + file.getAbsoluteFile(), e); } templates.add(template); } } return templates; }
private List<Template> loadTemplates(File templatePath) { List<File> files; try (Stream<Path> paths = Files.walk(Paths.get(templatePath.getAbsolutePath()), 1)) { files = paths.map(i -> i.toAbsolutePath().toFile()).collect(Collectors.toList()); } catch (IOException e) { throw new SkipperException("Could not process files in template path " + templatePath, e); } List<Template> templates = new ArrayList<>(); for (File file : files) { if (isYamlFile(file)) { Template template = new Template(); template.setName(file.getName()); try { template.setData(new String(Files.readAllBytes(file.toPath()), "UTF-8")); } catch (IOException e) { throw new SkipperException("Could read template file " + file.getAbsoluteFile(), e); } templates.add(template); } } return templates; }
@Override public Template getSpringCloudDeployerApplicationTemplate() { org.springframework.core.io.Resource resource = new ClassPathResource( "/org/springframework/cloud/skipper/io/generic-template.yml"); String genericTempateData = null; try { genericTempateData = StreamUtils.copyToString(resource.getInputStream(), Charset.defaultCharset()); } catch (IOException e) { throw new IllegalArgumentException("Can't load generic template", e); } Template template = new Template(); template.setData(genericTempateData); try { template.setName(resource.getURL().toString()); } catch (IOException e) { log.error("Could not get URL of resource " + resource.getDescription(), e); throw new SkipperServerException("Could not get URL of resource " + resource.getDescription(), e); } return template; }
@Override public Template getSpringCloudDeployerApplicationTemplate() { org.springframework.core.io.Resource resource = new ClassPathResource( "/org/springframework/cloud/skipper/io/generic-template.yml"); String genericTempateData = null; try { genericTempateData = StreamUtils.copyToString(resource.getInputStream(), Charset.defaultCharset()); } catch (IOException e) { throw new IllegalArgumentException("Can't load generic template", e); } Template template = new Template(); template.setData(genericTempateData); try { template.setName(resource.getURL().toString()); } catch (IOException e) { log.error("Could not get URL of resource " + resource.getDescription(), e); throw new SkipperServerException("Could not get URL of resource " + resource.getDescription(), e); } return template; }