Commit d6333fc353441ce22486f5f67f04191bb3ec4d12
1 parent
fc4b677b
增加 ProjectReactor 程序,实现一键改包名
Showing
8 changed files
with
105 additions
and
25 deletions
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/util/TenantUtils.java
yudao-module-infra/yudao-module-infra-impl/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java
| ... | ... | @@ -38,7 +38,7 @@ public class FileServiceTest extends BaseDbUnitTest { |
| 38 | 38 | public void testGetFilePage() { |
| 39 | 39 | // mock 数据 |
| 40 | 40 | FileDO dbFile = randomPojo(FileDO.class, o -> { // 等会查询到 |
| 41 | - o.setId("yudao"); | |
| 41 | + o.setId("yunai"); | |
| 42 | 42 | o.setType("jpg"); |
| 43 | 43 | o.setCreateTime(buildTime(2021, 1, 15)); |
| 44 | 44 | }); |
| ... | ... | @@ -47,17 +47,17 @@ public class FileServiceTest extends BaseDbUnitTest { |
| 47 | 47 | fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> o.setId("tudou"))); |
| 48 | 48 | // 测试 type 不匹配 |
| 49 | 49 | fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> { |
| 50 | - o.setId("yudao02"); | |
| 50 | + o.setId("yunai02"); | |
| 51 | 51 | o.setType("png"); |
| 52 | 52 | })); |
| 53 | 53 | // 测试 createTime 不匹配 |
| 54 | 54 | fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> { |
| 55 | - o.setId("yudao03"); | |
| 55 | + o.setId("yunai03"); | |
| 56 | 56 | o.setCreateTime(buildTime(2020, 1, 15)); |
| 57 | 57 | })); |
| 58 | 58 | // 准备参数 |
| 59 | 59 | FilePageReqVO reqVO = new FilePageReqVO(); |
| 60 | - reqVO.setId("yudao"); | |
| 60 | + reqVO.setId("yunai"); | |
| 61 | 61 | reqVO.setType("jp"); |
| 62 | 62 | reqVO.setBeginCreateTime(buildTime(2021, 1, 10)); |
| 63 | 63 | reqVO.setEndCreateTime(buildTime(2021, 1, 20)); | ... | ... |
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java
| ... | ... | @@ -163,7 +163,7 @@ public class UserController { |
| 163 | 163 | public void importTemplate(HttpServletResponse response) throws IOException { |
| 164 | 164 | // 手动创建导出 demo |
| 165 | 165 | List<UserImportExcelVO> list = Arrays.asList( |
| 166 | - UserImportExcelVO.builder().username("yudao").deptId(1L).email("yudao@iocoder.cn").mobile("15601691300") | |
| 166 | + UserImportExcelVO.builder().username("yunai").deptId(1L).email("yunai@iocoder.cn").mobile("15601691300") | |
| 167 | 167 | .nickname("芋道").status(CommonStatusEnum.ENABLE.getStatus()).sex(SexEnum.MALE.getSex()).build(), |
| 168 | 168 | UserImportExcelVO.builder().username("yuanma").deptId(2L).email("yuanma@iocoder.cn").mobile("15601701300") |
| 169 | 169 | .nickname("源码").status(CommonStatusEnum.DISABLE.getStatus()).sex(SexEnum.FEMALE.getSex()).build() | ... | ... |
yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java
| ... | ... | @@ -92,9 +92,9 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { |
| 92 | 92 | // 准备参数 |
| 93 | 93 | ErrorCodePageReqVO reqVO = new ErrorCodePageReqVO(); |
| 94 | 94 | reqVO.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); |
| 95 | - reqVO.setApplicationName("yudao"); | |
| 95 | + reqVO.setApplicationName("tu"); | |
| 96 | 96 | reqVO.setCode(1); |
| 97 | - reqVO.setMessage("yu"); | |
| 97 | + reqVO.setMessage("ma"); | |
| 98 | 98 | reqVO.setBeginCreateTime(buildTime(2020, 11, 1)); |
| 99 | 99 | reqVO.setEndCreateTime(buildTime(2020, 11, 30)); |
| 100 | 100 | |
| ... | ... | @@ -112,16 +112,16 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { |
| 112 | 112 | private ErrorCodeDO initGetErrorCodePage() { |
| 113 | 113 | ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> { // 等会查询到 |
| 114 | 114 | o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); |
| 115 | - o.setApplicationName("yudaoyuanma"); | |
| 115 | + o.setApplicationName("tudou"); | |
| 116 | 116 | o.setCode(1); |
| 117 | - o.setMessage("yudao"); | |
| 117 | + o.setMessage("yuanma"); | |
| 118 | 118 | o.setCreateTime(buildTime(2020, 11, 11)); |
| 119 | 119 | }); |
| 120 | 120 | errorCodeMapper.insert(dbErrorCode); |
| 121 | 121 | // 测试 type 不匹配 |
| 122 | 122 | errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()))); |
| 123 | 123 | // 测试 applicationName 不匹配 |
| 124 | - errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setApplicationName("yunai"))); | |
| 124 | + errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setApplicationName("yuan"))); | |
| 125 | 125 | // 测试 code 不匹配 |
| 126 | 126 | errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setCode(2))); |
| 127 | 127 | // 测试 message 不匹配 |
| ... | ... | @@ -138,9 +138,9 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { |
| 138 | 138 | // 准备参数 |
| 139 | 139 | ErrorCodeExportReqVO reqVO = new ErrorCodeExportReqVO(); |
| 140 | 140 | reqVO.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); |
| 141 | - reqVO.setApplicationName("yudao"); | |
| 141 | + reqVO.setApplicationName("tu"); | |
| 142 | 142 | reqVO.setCode(1); |
| 143 | - reqVO.setMessage("yu"); | |
| 143 | + reqVO.setMessage("ma"); | |
| 144 | 144 | reqVO.setBeginCreateTime(buildTime(2020, 11, 1)); |
| 145 | 145 | reqVO.setEndCreateTime(buildTime(2020, 11, 30)); |
| 146 | 146 | ... | ... |
yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceTest.java
| ... | ... | @@ -201,7 +201,7 @@ public class SmsTemplateServiceTest extends BaseDbUnitTest { |
| 201 | 201 | SmsTemplateDO dbSmsTemplate = randomPojo(SmsTemplateDO.class, o -> { // 等会查询到 |
| 202 | 202 | o.setType(SmsTemplateTypeEnum.PROMOTION.getType()); |
| 203 | 203 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 204 | - o.setCode("yudaoyuanma"); | |
| 204 | + o.setCode("tudou"); | |
| 205 | 205 | o.setContent("芋道源码"); |
| 206 | 206 | o.setApiTemplateId("yunai"); |
| 207 | 207 | o.setChannelId(1L); |
| ... | ... | @@ -226,7 +226,7 @@ public class SmsTemplateServiceTest extends BaseDbUnitTest { |
| 226 | 226 | SmsTemplatePageReqVO reqVO = new SmsTemplatePageReqVO(); |
| 227 | 227 | reqVO.setType(SmsTemplateTypeEnum.PROMOTION.getType()); |
| 228 | 228 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 229 | - reqVO.setCode("yudao"); | |
| 229 | + reqVO.setCode("tu"); | |
| 230 | 230 | reqVO.setContent("芋道"); |
| 231 | 231 | reqVO.setApiTemplateId("yu"); |
| 232 | 232 | reqVO.setChannelId(1L); |
| ... | ... | @@ -247,7 +247,7 @@ public class SmsTemplateServiceTest extends BaseDbUnitTest { |
| 247 | 247 | SmsTemplateDO dbSmsTemplate = randomPojo(SmsTemplateDO.class, o -> { // 等会查询到 |
| 248 | 248 | o.setType(SmsTemplateTypeEnum.PROMOTION.getType()); |
| 249 | 249 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 250 | - o.setCode("yudaoyuanma"); | |
| 250 | + o.setCode("tudou"); | |
| 251 | 251 | o.setContent("芋道源码"); |
| 252 | 252 | o.setApiTemplateId("yunai"); |
| 253 | 253 | o.setChannelId(1L); |
| ... | ... | @@ -272,7 +272,7 @@ public class SmsTemplateServiceTest extends BaseDbUnitTest { |
| 272 | 272 | SmsTemplateExportReqVO reqVO = new SmsTemplateExportReqVO(); |
| 273 | 273 | reqVO.setType(SmsTemplateTypeEnum.PROMOTION.getType()); |
| 274 | 274 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 275 | - reqVO.setCode("yudao"); | |
| 275 | + reqVO.setCode("tu"); | |
| 276 | 276 | reqVO.setContent("芋道"); |
| 277 | 277 | reqVO.setApiTemplateId("yu"); |
| 278 | 278 | reqVO.setChannelId(1L); | ... | ... |
yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java
| ... | ... | @@ -176,7 +176,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { |
| 176 | 176 | }), eq(RoleTypeEnum.SYSTEM.getType()))).thenReturn(200L); |
| 177 | 177 | // mock 用户 300L |
| 178 | 178 | when(userService.createUser(argThat(user -> { |
| 179 | - assertEquals("yudao", user.getUsername()); | |
| 179 | + assertEquals("yunai", user.getUsername()); | |
| 180 | 180 | assertEquals("yuanma", user.getPassword()); |
| 181 | 181 | assertEquals("芋道", user.getNickname()); |
| 182 | 182 | assertEquals("15601691300", user.getMobile()); |
| ... | ... | @@ -190,7 +190,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { |
| 190 | 190 | o.setPackageId(100L); |
| 191 | 191 | o.setStatus(randomCommonStatus()); |
| 192 | 192 | o.setDomain("https://www.iocoder.cn"); |
| 193 | - o.setUsername("yudao"); | |
| 193 | + o.setUsername("yunai"); | |
| 194 | 194 | o.setPassword("yuanma"); |
| 195 | 195 | }); |
| 196 | 196 | ... | ... |
yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/user/UserServiceImplTest.java
| ... | ... | @@ -175,12 +175,12 @@ public class UserServiceImplTest extends BaseDbUnitTest { |
| 175 | 175 | @Test |
| 176 | 176 | public void testUpdateUserPassword_success() { |
| 177 | 177 | // mock 数据 |
| 178 | - AdminUserDO dbUser = randomAdminUserDO(o -> o.setPassword("encode:yudao")); | |
| 178 | + AdminUserDO dbUser = randomAdminUserDO(o -> o.setPassword("encode:tudou")); | |
| 179 | 179 | userMapper.insert(dbUser); |
| 180 | 180 | // 准备参数 |
| 181 | 181 | Long userId = dbUser.getId(); |
| 182 | 182 | UserProfileUpdatePasswordReqVO reqVO = randomPojo(UserProfileUpdatePasswordReqVO.class, o -> { |
| 183 | - o.setOldPassword("yudao"); | |
| 183 | + o.setOldPassword("tudou"); | |
| 184 | 184 | o.setNewPassword("yuanma"); |
| 185 | 185 | }); |
| 186 | 186 | // mock 方法 |
| ... | ... | @@ -272,7 +272,7 @@ public class UserServiceImplTest extends BaseDbUnitTest { |
| 272 | 272 | AdminUserDO dbUser = initGetUserPageData(); |
| 273 | 273 | // 准备参数 |
| 274 | 274 | UserPageReqVO reqVO = new UserPageReqVO(); |
| 275 | - reqVO.setUsername("yudao"); | |
| 275 | + reqVO.setUsername("tu"); | |
| 276 | 276 | reqVO.setMobile("1560"); |
| 277 | 277 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 278 | 278 | reqVO.setBeginTime(buildTime(2020, 12, 1)); |
| ... | ... | @@ -296,7 +296,7 @@ public class UserServiceImplTest extends BaseDbUnitTest { |
| 296 | 296 | AdminUserDO dbUser = initGetUserPageData(); |
| 297 | 297 | // 准备参数 |
| 298 | 298 | UserExportReqVO reqVO = new UserExportReqVO(); |
| 299 | - reqVO.setUsername("yudao"); | |
| 299 | + reqVO.setUsername("tu"); | |
| 300 | 300 | reqVO.setMobile("1560"); |
| 301 | 301 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 302 | 302 | reqVO.setBeginTime(buildTime(2020, 12, 1)); |
| ... | ... | @@ -319,7 +319,7 @@ public class UserServiceImplTest extends BaseDbUnitTest { |
| 319 | 319 | private AdminUserDO initGetUserPageData() { |
| 320 | 320 | // mock 数据 |
| 321 | 321 | AdminUserDO dbUser = randomAdminUserDO(o -> { // 等会查询到 |
| 322 | - o.setUsername("yudaoyuanma"); | |
| 322 | + o.setUsername("tudou"); | |
| 323 | 323 | o.setMobile("15601691300"); |
| 324 | 324 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 325 | 325 | o.setCreateTime(buildTime(2020, 12, 12)); |
| ... | ... | @@ -327,7 +327,7 @@ public class UserServiceImplTest extends BaseDbUnitTest { |
| 327 | 327 | }); |
| 328 | 328 | userMapper.insert(dbUser); |
| 329 | 329 | // 测试 username 不匹配 |
| 330 | - userMapper.insert(ObjectUtils.cloneIgnoreId(dbUser, o -> o.setUsername("yuanma"))); | |
| 330 | + userMapper.insert(ObjectUtils.cloneIgnoreId(dbUser, o -> o.setUsername("dou"))); | |
| 331 | 331 | // 测试 mobile 不匹配 |
| 332 | 332 | userMapper.insert(ObjectUtils.cloneIgnoreId(dbUser, o -> o.setMobile("18818260888"))); |
| 333 | 333 | // 测试 status 不匹配 | ... | ... |
yudao-server/src/test/java/cn/iocoder/yudao/ProjectReactor.java
0 → 100644
| 1 | +package cn.iocoder.yudao; | |
| 2 | + | |
| 3 | +import cn.hutool.core.io.FileUtil; | |
| 4 | +import cn.hutool.core.util.StrUtil; | |
| 5 | +import lombok.extern.slf4j.Slf4j; | |
| 6 | +import org.apache.commons.io.FileUtils; | |
| 7 | + | |
| 8 | +import java.io.File; | |
| 9 | +import java.nio.charset.StandardCharsets; | |
| 10 | +import java.util.Collection; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 项目修改器,一键替换 Maven 的 groupId、artifactId,项目的 package 等 | |
| 14 | + * | |
| 15 | + * 通过修改 groupIdNew、artifactIdNew、projectBaseDirNew 三个变量 | |
| 16 | + * | |
| 17 | + * @author 芋道源码 | |
| 18 | + */ | |
| 19 | +@Slf4j | |
| 20 | +public class ProjectReactor { | |
| 21 | + | |
| 22 | + private static final String GROUP_ID = "cn.iocoder.boot"; | |
| 23 | + private static final String ARTIFACT_ID = "yudao"; | |
| 24 | + private static final String PACKAGE_NAME = "cn.iocoder.yudao"; | |
| 25 | + | |
| 26 | + public static void main(String[] args) { | |
| 27 | + String projectBaseDir = getProjectBaseDir(); | |
| 28 | + // ========== 配置,需要你手动修改 ========== | |
| 29 | + String groupIdNew = "cn.star.gg"; | |
| 30 | + String artifactIdNew = "star"; | |
| 31 | + String packageNameNew = "cn.start.pp"; | |
| 32 | + String projectBaseDirNew = projectBaseDir + "-new"; | |
| 33 | + // ========== ========== | |
| 34 | + | |
| 35 | + // 获得需要复制的文件 | |
| 36 | + log.info("[main][开始获得需要重写的文件]"); | |
| 37 | + Collection<File> files = listFiles(projectBaseDir); | |
| 38 | + log.info("[main][需要重写的文件数量:{},预计需要 5-10 秒]", files.size()); | |
| 39 | + // 写入文件 | |
| 40 | + files.forEach(file -> { | |
| 41 | + String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew); | |
| 42 | + writeFile(file, content, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew); | |
| 43 | + }); | |
| 44 | + log.info("[main][重写完成]"); | |
| 45 | + } | |
| 46 | + | |
| 47 | + private static String getProjectBaseDir() { | |
| 48 | + // noinspection ConstantConditions | |
| 49 | + return StrUtil.subBefore(ProjectReactor.class.getClassLoader().getResource("").getFile(), | |
| 50 | + "/yudao-server", false); | |
| 51 | + } | |
| 52 | + | |
| 53 | + private static Collection<File> listFiles(String projectBaseDir) { | |
| 54 | + Collection<File> files = FileUtils.listFiles(new File(projectBaseDir), null, true); | |
| 55 | + files.removeIf(file -> file.getPath().contains("/target/")); | |
| 56 | + files.removeIf(file -> file.getPath().contains("/node_modules/")); | |
| 57 | + files.removeIf(file -> file.getPath().contains("/.idea/")); // 移除 IDEA 自身的文件 | |
| 58 | + files.removeIf(file -> file.getPath().contains("/.git/")); // 移除 Git 自身的文件 | |
| 59 | + files.removeIf(file -> file.getPath().contains("/dist/")); // 移除 Node 编译出来的 | |
| 60 | + return files; | |
| 61 | + } | |
| 62 | + | |
| 63 | + private static String replaceFileContent(File file, String groupIdNew, | |
| 64 | + String artifactIdNew, String packageNameNew) { | |
| 65 | + return FileUtil.readString(file, StandardCharsets.UTF_8) | |
| 66 | + .replaceAll(GROUP_ID, groupIdNew) | |
| 67 | + .replaceAll(PACKAGE_NAME, packageNameNew) | |
| 68 | + .replaceAll(ARTIFACT_ID, artifactIdNew) // 必须放在最后替换,因为 ARTIFACT_ID 太短! | |
| 69 | + .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); | |
| 70 | + } | |
| 71 | + | |
| 72 | + private static void writeFile(File file, String fileContent, String projectBaseDir, | |
| 73 | + String projectBaseDirNew, String packageNameNew, String artifactIdNew) { | |
| 74 | + String newPath = file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录 | |
| 75 | + .replace(PACKAGE_NAME.replaceAll("\\.", "/"), packageNameNew.replaceAll("\\.", "/")) | |
| 76 | + .replace(ARTIFACT_ID, artifactIdNew) // | |
| 77 | + .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew)); | |
| 78 | + FileUtil.writeUtf8String(fileContent, newPath); | |
| 79 | + } | |
| 80 | + | |
| 81 | +} | ... | ... |