From d741ee57292302f3b258d5ce585942babb857a91 Mon Sep 17 00:00:00 2001 From: keinhaar <10001689+keinhaar@users.noreply.github.com> Date: Sun, 27 Oct 2024 16:57:10 +0100 Subject: [PATCH] Unified the File renaming - all renaming of files is done by using the same method. - allow filenames to contain the placeholder _PROJECTNAME_ --- .../wizards/WebAppTemplateProjectCreator.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/plugins/com.gwtplugins.gdt.eclipse.suite/src/com/google/gdt/eclipse/suite/wizards/WebAppTemplateProjectCreator.java b/plugins/com.gwtplugins.gdt.eclipse.suite/src/com/google/gdt/eclipse/suite/wizards/WebAppTemplateProjectCreator.java index 72fadb7a..6008b295 100644 --- a/plugins/com.gwtplugins.gdt.eclipse.suite/src/com/google/gdt/eclipse/suite/wizards/WebAppTemplateProjectCreator.java +++ b/plugins/com.gwtplugins.gdt.eclipse.suite/src/com/google/gdt/eclipse/suite/wizards/WebAppTemplateProjectCreator.java @@ -213,29 +213,15 @@ private void replacePackageNames(IProject iProject, File dir) throws IOException File file = files.pop(); if(file.getName().contains("_PACKAGENAME_")) { - String name = file.getName(); - name = name.replace("_PACKAGENAME_", packageBaseName.replace('.', File.separatorChar)); - File newFile = new File(file.getParentFile(), name); - Files.createDirectories(newFile.getParentFile().toPath()); - boolean ret = file.renameTo(newFile); - if(ret == false) - { - throw new IOException("Could not rename"); - } - file = newFile; + file = replace(file, "_PACKAGENAME_", packageBaseName.replace('.', File.separatorChar)); + } + if(file.getName().contains("_PROJECTNAME_")) + { + file = replace(file, "_PROJECTNAME_", projectBaseName.replace('.', File.separatorChar)); } if(file.getName().contains("_.._")) { - String name = file.getName(); - name = name.replace("_.._", "../"); - File newFile = new File(file.getParentFile(), name); - Files.createDirectories(newFile.getParentFile().toPath()); - boolean ret = file.renameTo(newFile); - if(ret == false) - { - throw new IOException("Could not rename"); - } - file = newFile; + file = replace(file, "_.._", "../"); } if(file.isDirectory()) { @@ -250,6 +236,20 @@ private void replacePackageNames(IProject iProject, File dir) throws IOException } } + private File replace(File file, String toReplace, String replacement) throws IOException + { + String name = file.getName(); + name = name.replace(toReplace, replacement); + File newFile = new File(file.getParentFile(), name); + Files.createDirectories(newFile.getParentFile().toPath()); + boolean ret = file.renameTo(newFile); + if(ret == false) + { + throw new IOException("Could not rename"); + } + return newFile; + } + /** * Replaces a pattern in a File. The File is not allowed to be larger then 1.000.000 bytes. * @param file the file, where the replacement is made.