From 37900a7394880d793ab85216cee3f546ecdac0dd Mon Sep 17 00:00:00 2001 From: zhoulc Date: Wed, 30 Mar 2022 10:08:55 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E6=94=B9=E5=8C=85=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/iocoder/yudao/ProjectReactor.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java index f961b066f..b661e077e 100644 --- a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java +++ b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java @@ -8,10 +8,11 @@ import org.apache.commons.io.FileUtils; import java.io.File; import java.nio.charset.StandardCharsets; import java.util.Collection; +import java.util.regex.Matcher; /** * 项目修改器,一键替换 Maven 的 groupId、artifactId,项目的 package 等 - * + *

* 通过修改 groupIdNew、artifactIdNew、projectBaseDirNew 三个变量 * * @author 芋道源码 @@ -22,18 +23,19 @@ public class ProjectReactor { private static final String GROUP_ID = "cn.iocoder.boot"; private static final String ARTIFACT_ID = "yudao"; private static final String PACKAGE_NAME = "cn.iocoder.yudao"; - private static final String TITLE = "芋道管理系统"; + private static final String TITLE = "欣辰装点猫管理系统"; public static void main(String[] args) { + long start = System.currentTimeMillis(); String projectBaseDir = getProjectBaseDir(); // ========== 配置,需要你手动修改 ========== - String groupIdNew = "cn.star.gg"; - String artifactIdNew = "star"; - String packageNameNew = "cn.start.pp"; - String titleNew = "土豆管理系统"; + String groupIdNew = "cn.huwing.boot"; + String artifactIdNew = "zdm"; + String packageNameNew = "cn.huwing.zdm"; + String titleNew = "欣辰装点猫管理系统"; String projectBaseDirNew = projectBaseDir + "-new"; // 一键改名后,“新”项目所在的目录 - // ========== ========== + log.info("[main][新项目路径地址]projectBaseDirNew: " + projectBaseDirNew); // 获得需要复制的文件 log.info("[main][开始获得需要重写的文件]"); @@ -44,13 +46,12 @@ public class ProjectReactor { String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew); writeFile(file, content, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew); }); - log.info("[main][重写完成]"); + long end = System.currentTimeMillis(); + log.info("[main][重写完成]共耗时:" + (end - start) / 1000 + "秒"); } private static String getProjectBaseDir() { - // noinspection ConstantConditions - return StrUtil.subBefore(ProjectReactor.class.getClassLoader().getResource("").getFile(), - "/yudao-server", false); + return StrUtil.subBefore(new File(ProjectReactor.class.getClassLoader().getResource(File.separator).getFile()).getPath(), "\\yudao-server", false); } private static Collection listFiles(String projectBaseDir) { @@ -59,6 +60,7 @@ public class ProjectReactor { files.removeIf(file -> file.getPath().contains("/node_modules/")); files.removeIf(file -> file.getPath().contains("/.idea/")); // 移除 IDEA 自身的文件 files.removeIf(file -> file.getPath().contains("/.git/")); // 移除 Git 自身的文件 + files.removeIf(file -> file.getPath().contains("/.github/")); // 移除 GitHub 自身的文件 files.removeIf(file -> file.getPath().contains("/dist/")); // 移除 Node 编译出来的 return files; } @@ -77,11 +79,10 @@ public class ProjectReactor { private static void writeFile(File file, String fileContent, String projectBaseDir, String projectBaseDirNew, String packageNameNew, String artifactIdNew) { String newPath = file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录 - .replace(PACKAGE_NAME.replaceAll("\\.", File.separator), - packageNameNew.replaceAll("\\.", File.separator)) + .replace(PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(File.separator)), + packageNameNew.replaceAll("\\.", Matcher.quoteReplacement(File.separator))) .replace(ARTIFACT_ID, artifactIdNew) // .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); FileUtil.writeUtf8String(fileContent, newPath); } - -} +} \ No newline at end of file From 1f6bf1621ae52cdc892c67c64119ed55d1943c00 Mon Sep 17 00:00:00 2001 From: zhoulc Date: Wed, 30 Mar 2022 14:35:05 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E8=80=97=E6=97=B6?= =?UTF-8?q?=E9=A2=84=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java index b661e077e..5739170aa 100644 --- a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java +++ b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java @@ -40,7 +40,7 @@ public class ProjectReactor { // 获得需要复制的文件 log.info("[main][开始获得需要重写的文件]"); Collection files = listFiles(projectBaseDir); - log.info("[main][需要重写的文件数量:{},预计需要 5-10 秒]", files.size()); + log.info("[main][需要重写的文件数量:{},预计需要 30 秒]", files.size()); // 写入文件 files.forEach(file -> { String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew); From f651b86d53b11820b18cb74f34dc278ba8c8b82b Mon Sep 17 00:00:00 2001 From: zhoulc Date: Wed, 30 Mar 2022 16:15:08 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E6=9B=B4=E6=94=B9=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E6=96=B9=E6=B3=95=EF=BC=8C=E9=80=82=E5=BA=94?= =?UTF-8?q?windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/iocoder/yudao/ProjectReactor.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java index 5739170aa..3d9d83df9 100644 --- a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java +++ b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java @@ -9,6 +9,7 @@ import java.io.File; import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.regex.Matcher; +import java.util.stream.Collectors; /** * 项目修改器,一键替换 Maven 的 groupId、artifactId,项目的 package 等 @@ -40,7 +41,7 @@ public class ProjectReactor { // 获得需要复制的文件 log.info("[main][开始获得需要重写的文件]"); Collection files = listFiles(projectBaseDir); - log.info("[main][需要重写的文件数量:{},预计需要 30 秒]", files.size()); + log.info("[main][需要重写的文件数量:{},预计需要 5-10 秒]", files.size()); // 写入文件 files.forEach(file -> { String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew); @@ -56,12 +57,15 @@ public class ProjectReactor { private static Collection listFiles(String projectBaseDir) { Collection files = FileUtils.listFiles(new File(projectBaseDir), null, true); - files.removeIf(file -> file.getPath().contains("/target/")); - files.removeIf(file -> file.getPath().contains("/node_modules/")); - files.removeIf(file -> file.getPath().contains("/.idea/")); // 移除 IDEA 自身的文件 - files.removeIf(file -> file.getPath().contains("/.git/")); // 移除 Git 自身的文件 - files.removeIf(file -> file.getPath().contains("/.github/")); // 移除 GitHub 自身的文件 - files.removeIf(file -> file.getPath().contains("/dist/")); // 移除 Node 编译出来的 + // 移除 IDEA Git GitHub 自身的文件; Node 编译出来的文件 + files = files.stream() + .filter(file -> !file.getPath().contains("\\target\\") + && !file.getPath().contains("\\node_modules\\") + && !file.getPath().contains("\\.idea\\") + && !file.getPath().contains("\\.git\\") + && !file.getPath().contains("\\.github\\") + && !file.getPath().contains("\\dist\\")) + .collect(Collectors.toList()); return files; } From 50b6a4cb5e536ab7db42446fb6ed149b3cf24374 Mon Sep 17 00:00:00 2001 From: zhoulc Date: Wed, 30 Mar 2022 16:22:57 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E6=9B=B4=E6=94=B9=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E6=96=B9=E6=B3=95=EF=BC=8C=E9=80=82=E5=BA=94?= =?UTF-8?q?windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/cn/iocoder/yudao/ProjectReactor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java index 3d9d83df9..935e2db0a 100644 --- a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java +++ b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java @@ -64,7 +64,8 @@ public class ProjectReactor { && !file.getPath().contains("\\.idea\\") && !file.getPath().contains("\\.git\\") && !file.getPath().contains("\\.github\\") - && !file.getPath().contains("\\dist\\")) + && !file.getPath().contains("\\dist\\") + && !file.getPath().contains(".iml")) .collect(Collectors.toList()); return files; } From c729570328e6a7966b0a3dc0c8e3bd18b755f977 Mon Sep 17 00:00:00 2001 From: zhoulc Date: Wed, 30 Mar 2022 16:41:40 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9title?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java index 935e2db0a..cced87fd7 100644 --- a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java +++ b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java @@ -24,7 +24,7 @@ public class ProjectReactor { private static final String GROUP_ID = "cn.iocoder.boot"; private static final String ARTIFACT_ID = "yudao"; private static final String PACKAGE_NAME = "cn.iocoder.yudao"; - private static final String TITLE = "欣辰装点猫管理系统"; + private static final String TITLE = "芋道管理系统"; public static void main(String[] args) { long start = System.currentTimeMillis(); From d9afb0e6c60595751a0a828cac04e42c96196080 Mon Sep 17 00:00:00 2001 From: zhoulc Date: Wed, 30 Mar 2022 18:09:51 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0html.gz=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/cn/iocoder/yudao/ProjectReactor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java index cced87fd7..c92c4cb1b 100644 --- a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java +++ b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java @@ -34,7 +34,7 @@ public class ProjectReactor { String groupIdNew = "cn.huwing.boot"; String artifactIdNew = "zdm"; String packageNameNew = "cn.huwing.zdm"; - String titleNew = "欣辰装点猫管理系统"; + String titleNew = "测试名管理系统"; String projectBaseDirNew = projectBaseDir + "-new"; // 一键改名后,“新”项目所在的目录 log.info("[main][新项目路径地址]projectBaseDirNew: " + projectBaseDirNew); @@ -65,7 +65,8 @@ public class ProjectReactor { && !file.getPath().contains("\\.git\\") && !file.getPath().contains("\\.github\\") && !file.getPath().contains("\\dist\\") - && !file.getPath().contains(".iml")) + && !file.getPath().contains(".iml") + && !file.getPath().contains(".html.gz")) .collect(Collectors.toList()); return files; } From 5ac7c3bd5d42b5409953137657276618f2d634b1 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 30 Mar 2022 21:54:45 +0800 Subject: [PATCH 07/10] =?UTF-8?q?code=20review=20ProjectReactor=20?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/cn/iocoder/yudao/ProjectReactor.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java index c92c4cb1b..e31eb4b67 100644 --- a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java +++ b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java @@ -31,7 +31,7 @@ public class ProjectReactor { String projectBaseDir = getProjectBaseDir(); // ========== 配置,需要你手动修改 ========== - String groupIdNew = "cn.huwing.boot"; + String groupIdNew = "cn.huwing.boot"; // TODO @seeker:这几个参数改回去原来的哈。 String artifactIdNew = "zdm"; String packageNameNew = "cn.huwing.zdm"; String titleNew = "测试名管理系统"; @@ -47,8 +47,8 @@ public class ProjectReactor { String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew); writeFile(file, content, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew); }); - long end = System.currentTimeMillis(); - log.info("[main][重写完成]共耗时:" + (end - start) / 1000 + "秒"); + long end = System.currentTimeMillis(); // TODO @seeker:直接减,不用增加变量 + log.info("[main][重写完成]共耗时:" + (end - start) / 1000 + "秒"); // TODO @seeker:logger 不要拼接字符串,用占位符 } private static String getProjectBaseDir() { @@ -59,7 +59,7 @@ public class ProjectReactor { Collection files = FileUtils.listFiles(new File(projectBaseDir), null, true); // 移除 IDEA Git GitHub 自身的文件; Node 编译出来的文件 files = files.stream() - .filter(file -> !file.getPath().contains("\\target\\") + .filter(file -> !file.getPath().contains("\\target\\") // TODO @seeker:使用 File.separator,也要考虑 mac && !file.getPath().contains("\\node_modules\\") && !file.getPath().contains("\\.idea\\") && !file.getPath().contains("\\.git\\") @@ -91,4 +91,4 @@ public class ProjectReactor { .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); FileUtil.writeUtf8String(fileContent, newPath); } -} \ No newline at end of file +} From 1b496d91e1749770b07c32021f20520dfdc7ef9b Mon Sep 17 00:00:00 2001 From: zhoulc Date: Thu, 31 Mar 2022 08:13:32 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E5=85=BC=E5=AE=B9mac?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/iocoder/yudao/ProjectReactor.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java index e31eb4b67..0961c9252 100644 --- a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java +++ b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java @@ -31,10 +31,10 @@ public class ProjectReactor { String projectBaseDir = getProjectBaseDir(); // ========== 配置,需要你手动修改 ========== - String groupIdNew = "cn.huwing.boot"; // TODO @seeker:这几个参数改回去原来的哈。 - String artifactIdNew = "zdm"; - String packageNameNew = "cn.huwing.zdm"; - String titleNew = "测试名管理系统"; + String groupIdNew = "cn.star.gg"; + String artifactIdNew = "star"; + String packageNameNew = "cn.start.pp"; + String titleNew = "土豆管理系统"; String projectBaseDirNew = projectBaseDir + "-new"; // 一键改名后,“新”项目所在的目录 log.info("[main][新项目路径地址]projectBaseDirNew: " + projectBaseDirNew); @@ -47,24 +47,23 @@ public class ProjectReactor { String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew); writeFile(file, content, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew); }); - long end = System.currentTimeMillis(); // TODO @seeker:直接减,不用增加变量 - log.info("[main][重写完成]共耗时:" + (end - start) / 1000 + "秒"); // TODO @seeker:logger 不要拼接字符串,用占位符 + log.info("[main][重写完成]共耗时:{} 秒", (System.currentTimeMillis() - start) / 1000); } private static String getProjectBaseDir() { - return StrUtil.subBefore(new File(ProjectReactor.class.getClassLoader().getResource(File.separator).getFile()).getPath(), "\\yudao-server", false); + return StrUtil.subBefore(new File(ProjectReactor.class.getClassLoader().getResource(File.separator).getFile()).getPath(), File.separator + "yudao-server", false); } private static Collection listFiles(String projectBaseDir) { Collection files = FileUtils.listFiles(new File(projectBaseDir), null, true); // 移除 IDEA Git GitHub 自身的文件; Node 编译出来的文件 files = files.stream() - .filter(file -> !file.getPath().contains("\\target\\") // TODO @seeker:使用 File.separator,也要考虑 mac - && !file.getPath().contains("\\node_modules\\") - && !file.getPath().contains("\\.idea\\") - && !file.getPath().contains("\\.git\\") - && !file.getPath().contains("\\.github\\") - && !file.getPath().contains("\\dist\\") + .filter(file -> !file.getPath().contains(File.separator + "target" + File.separator) + && !file.getPath().contains(File.separator + "node_modules" + File.separator) + && !file.getPath().contains(File.separator + ".idea" + File.separator) + && !file.getPath().contains(File.separator + ".git" + File.separator) + && !file.getPath().contains(File.separator + ".github" + File.separator) + && !file.getPath().contains(File.separator + "dist" + File.separator) && !file.getPath().contains(".iml") && !file.getPath().contains(".html.gz")) .collect(Collectors.toList()); From ceb76e719059841198a652b7bd10fa0df1c8fccf Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 20 Apr 2022 12:52:13 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=20mac=20=E7=9A=84=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/iocoder/yudao/ProjectReactor.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java index 0961c9252..75b22cea0 100644 --- a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java +++ b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java @@ -11,6 +11,8 @@ import java.util.Collection; import java.util.regex.Matcher; import java.util.stream.Collectors; +import static java.io.File.separator; + /** * 项目修改器,一键替换 Maven 的 groupId、artifactId,项目的 package 等 *

@@ -39,9 +41,9 @@ public class ProjectReactor { log.info("[main][新项目路径地址]projectBaseDirNew: " + projectBaseDirNew); // 获得需要复制的文件 - log.info("[main][开始获得需要重写的文件]"); + log.info("[main][开始获得需要重写的文件,预计需要 10-20 秒]"); Collection files = listFiles(projectBaseDir); - log.info("[main][需要重写的文件数量:{},预计需要 5-10 秒]", files.size()); + log.info("[main][需要重写的文件数量:{},预计需要 15-30 秒]", files.size()); // 写入文件 files.forEach(file -> { String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew); @@ -51,19 +53,19 @@ public class ProjectReactor { } private static String getProjectBaseDir() { - return StrUtil.subBefore(new File(ProjectReactor.class.getClassLoader().getResource(File.separator).getFile()).getPath(), File.separator + "yudao-server", false); + return StrUtil.subBefore(ProjectReactor.class.getClassLoader().getResource("").getFile(), + separator + "yudao-server", false); } private static Collection listFiles(String projectBaseDir) { Collection files = FileUtils.listFiles(new File(projectBaseDir), null, true); - // 移除 IDEA Git GitHub 自身的文件; Node 编译出来的文件 + // 移除 IDEA、Git 自身的文件、Node 编译出来的文件 files = files.stream() - .filter(file -> !file.getPath().contains(File.separator + "target" + File.separator) - && !file.getPath().contains(File.separator + "node_modules" + File.separator) - && !file.getPath().contains(File.separator + ".idea" + File.separator) - && !file.getPath().contains(File.separator + ".git" + File.separator) - && !file.getPath().contains(File.separator + ".github" + File.separator) - && !file.getPath().contains(File.separator + "dist" + File.separator) + .filter(file -> !file.getPath().contains(separator + "target" + separator) + && !file.getPath().contains(separator + "node_modules" + separator) + && !file.getPath().contains(separator + ".idea" + separator) + && !file.getPath().contains(separator + ".git" + separator) + && !file.getPath().contains(separator + "dist" + separator) && !file.getPath().contains(".iml") && !file.getPath().contains(".html.gz")) .collect(Collectors.toList()); @@ -84,8 +86,8 @@ public class ProjectReactor { private static void writeFile(File file, String fileContent, String projectBaseDir, String projectBaseDirNew, String packageNameNew, String artifactIdNew) { String newPath = file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录 - .replace(PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(File.separator)), - packageNameNew.replaceAll("\\.", Matcher.quoteReplacement(File.separator))) + .replace(PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(separator)), + packageNameNew.replaceAll("\\.", Matcher.quoteReplacement(separator))) .replace(ARTIFACT_ID, artifactIdNew) // .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); FileUtil.writeUtf8String(fileContent, newPath); From 946735ac246a27f5fb9fe8a878bc43e31cbfd2b7 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 20 Apr 2022 20:56:33 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E6=94=B9=E7=A0=81=E7=9A=84=E5=AE=9E=E7=8E=B0=EF=BC=8C=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=20win=20=E5=92=8C=20mac=20=E7=9A=84=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E5=A4=8D=20png?= =?UTF-8?q?=E3=80=81jpg=20=E7=AD=89=E6=96=87=E4=BB=B6=E7=9A=84=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/iocoder/yudao/ProjectReactor.java | 52 ++++++++++++++++--- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java index 75b22cea0..2cb2f9640 100644 --- a/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java +++ b/yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java @@ -1,13 +1,16 @@ package cn.iocoder.yudao; +import cn.hutool.core.io.FileTypeUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.common.util.collection.SetUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; import java.io.File; import java.nio.charset.StandardCharsets; import java.util.Collection; +import java.util.Set; import java.util.regex.Matcher; import java.util.stream.Collectors; @@ -28,9 +31,16 @@ public class ProjectReactor { private static final String PACKAGE_NAME = "cn.iocoder.yudao"; private static final String TITLE = "芋道管理系统"; + /** + * 白名单文件,不进行重写,避免出问题 + */ + private static final Set WHITE_FILE_TYPES = SetUtils.asSet("gif", "jpg", "svg", "png", // 图片 + "eot", "woff2", "ttf", "woff"); // 字体 + public static void main(String[] args) { long start = System.currentTimeMillis(); String projectBaseDir = getProjectBaseDir(); + log.info("[main][原项目路劲改地址 ({})]", projectBaseDir); // ========== 配置,需要你手动修改 ========== String groupIdNew = "cn.star.gg"; @@ -38,7 +48,7 @@ public class ProjectReactor { String packageNameNew = "cn.start.pp"; String titleNew = "土豆管理系统"; String projectBaseDirNew = projectBaseDir + "-new"; // 一键改名后,“新”项目所在的目录 - log.info("[main][新项目路径地址]projectBaseDirNew: " + projectBaseDirNew); + log.info("[main][新项目路径地址 ({})]", projectBaseDirNew); // 获得需要复制的文件 log.info("[main][开始获得需要重写的文件,预计需要 10-20 秒]"); @@ -46,6 +56,13 @@ public class ProjectReactor { log.info("[main][需要重写的文件数量:{},预计需要 15-30 秒]", files.size()); // 写入文件 files.forEach(file -> { + // 如果是白名单的文件类型,不进行重写,直接拷贝 + String fileType = FileTypeUtil.getType(file); + if (WHITE_FILE_TYPES.contains(fileType)) { + copyFile(file, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew); + return; + } + // 如果非白名单的文件类型,重写内容,在生成文件 String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew); writeFile(file, content, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew); }); @@ -53,8 +70,11 @@ public class ProjectReactor { } private static String getProjectBaseDir() { - return StrUtil.subBefore(ProjectReactor.class.getClassLoader().getResource("").getFile(), - separator + "yudao-server", false); + String baseDir = System.getProperty("user.dir"); + if (StrUtil.isEmpty(baseDir)) { + throw new NullPointerException("项目基础路径不存在"); + } + return baseDir; } private static Collection listFiles(String projectBaseDir) { @@ -75,8 +95,14 @@ public class ProjectReactor { private static String replaceFileContent(File file, String groupIdNew, String artifactIdNew, String packageNameNew, String titleNew) { - return FileUtil.readString(file, StandardCharsets.UTF_8) - .replaceAll(GROUP_ID, groupIdNew) + String content = FileUtil.readString(file, StandardCharsets.UTF_8); + // 如果是白名单的文件类型,不进行重写 + String fileType = FileTypeUtil.getType(file); + if (WHITE_FILE_TYPES.contains(fileType)) { + return content; + } + // 执行文件内容都重写 + return content.replaceAll(GROUP_ID, groupIdNew) .replaceAll(PACKAGE_NAME, packageNameNew) .replaceAll(ARTIFACT_ID, artifactIdNew) // 必须放在最后替换,因为 ARTIFACT_ID 太短! .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)) @@ -85,11 +111,23 @@ public class ProjectReactor { private static void writeFile(File file, String fileContent, String projectBaseDir, String projectBaseDirNew, String packageNameNew, String artifactIdNew) { - String newPath = file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录 + String newPath = buildNewFilePath(file, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew); + FileUtil.writeUtf8String(fileContent, newPath); + } + + private static void copyFile(File file, String projectBaseDir, + String projectBaseDirNew, String packageNameNew, String artifactIdNew) { + String newPath = buildNewFilePath(file, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew); + FileUtil.copyFile(file, new File(newPath)); + } + + private static String buildNewFilePath(File file, String projectBaseDir, + String projectBaseDirNew, String packageNameNew, String artifactIdNew) { + return file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录 .replace(PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(separator)), packageNameNew.replaceAll("\\.", Matcher.quoteReplacement(separator))) .replace(ARTIFACT_ID, artifactIdNew) // .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); - FileUtil.writeUtf8String(fileContent, newPath); } + }