From 64f629aabef1cfb72de6047964d31e769da42010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arvid=20Fahlstr=C3=B6m=20Myrman?= Date: Mon, 15 May 2017 18:04:03 +0200 Subject: [PATCH] Don't assume file path delimiter when copying template files Instead of manually removing the prefix to the template root, use Path.relativize to get the relative name of template files. --- core/src/iristk/system/IrisUtils.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/iristk/system/IrisUtils.java b/core/src/iristk/system/IrisUtils.java index 275197a..98356de 100644 --- a/core/src/iristk/system/IrisUtils.java +++ b/core/src/iristk/system/IrisUtils.java @@ -14,6 +14,8 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; @@ -184,12 +186,12 @@ public static void createFromTemplate(String templateName, String name, String p throw new IOException(packagePath + " already exists"); String templateIdLC = "$" + StringUtils.lcFirst(templateName) + "$"; String templateIdUC = "$" + StringUtils.ucFirst(templateName) + "$"; - String templRoot = props.getProperty("templatePath"); - for (String filen : FileFinder.findAll(templRoot)) { + Path templRoot = Paths.get(props.getProperty("templatePath")); + for (String filen : FileFinder.findAll(templRoot.toString())) { File inputFile = new File(filen); if (inputFile.getName().equals("template.properties")) continue; - String entryName = filen.replace(templRoot + "\\", ""); + String entryName = templRoot.relativize(Paths.get(filen)).toString(); entryName = entryName.replace(templateIdLC, StringUtils.lcFirst(name)); entryName = entryName.replace(templateIdUC, StringUtils.ucFirst(name)); File targetFile = new File(packagePath, entryName);