From 37900a7394880d793ab85216cee3f546ecdac0dd Mon Sep 17 00:00:00 2001 From: zhoulc Date: Wed, 30 Mar 2022 10:08:55 +0800 Subject: [PATCH 1/8] =?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 2/8] =?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 3/8] =?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 4/8] =?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 5/8] =?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 6/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0html.gz=E6=96=87=E4=BB=B6?= =?UTF-8?q?=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 7/8] =?UTF-8?q?code=20review=20ProjectReactor=20=E7=9A=84?= =?UTF-8?q?=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 8/8] =?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());