1. 修复服务与模块生成器,未正确全量替换端口的错误

(cherry picked from commit 81f3387195)
This commit is contained in:
chenbowen
2025-09-02 10:30:55 +08:00
committed by chenbowen
parent 1e1216c150
commit 6a5893b702
5 changed files with 37 additions and 102 deletions

View File

@@ -1,25 +0,0 @@
碰到问题,请在 <https://gitee.com/zhijiantianya/yudao-cloud/issues> 搜索是否存在相似的 issue。
不按照模板提交的 issue会被系统自动删除。
### 基本信息
- ruoyi-vue-pro 版本:
- 操作系统:
- 数据库:
### 你猜测可能的原因
(必填)我花费了 2-4 小时自查发现可能的原因是xxxxxx
### 复现步骤
第一步,
第二步,
第三步,
### 报错信息
带上必要的截图

View File

@@ -1,34 +0,0 @@
---
name: 问题反馈
about: 请详细描述,以便更高快的获得到解决
title: ''
labels: ''
assignees: ''
---
碰到问题,请在 <https://github.com/YunaiV/yudao-cloud/issues> 搜索是否存在相似的 issue。
不按照模板提交的 issue会被系统自动删除。
### 基本信息
- ruoyi-vue-pro 版本:
- 操作系统:
- 数据库:
### 你猜测可能的原因
(必填)我花费了 2-4 小时自查发现可能的原因是xxxxxx
### 复现步骤
第一步,
第二步,
第三步,
### 报错信息
带上必要的截图

View File

@@ -1,30 +0,0 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven
on:
push:
branches: [ master ]
# pull_request:
# branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8', '11', '17' ]
steps:
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.Java }}
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml -Dmaven.test.skip=true

View File

@@ -158,6 +158,28 @@ public class ModuleGenerator {
return processErrorCodeConstants(content, moduleName, packageName, author);
}
// 处理配置文件
if (fileName.endsWith(".yml") || fileName.endsWith(".yaml")) {
String newContent = content;
// 替换应用名称
newContent = newContent.replace("name: yudao-module-template-server", "name: yudao-module-" + moduleName + "-server");
// 处理端口配置
if (newContent.contains("port:")) {
// 使用更精确的正则表达式来匹配端口行
newContent = newContent.replaceAll("(?m)^(\\s*)port:\\s*\\d+\\s*$", "$1port: " + port);
} else if (newContent.contains("server:")) {
// 如果有server配置但没有port在server下添加port
newContent = newContent.replaceAll("(?m)^(\\s*)server:\\s*$", "$1server:\n$1 port: " + port);
} else {
// 如果完全没有server配置在文件开头添加
newContent = "server:\n port: " + port + "\n\n" + newContent;
}
return newContent;
}
return content.replace("yudao-module-template", "yudao-module-" + moduleName)
.replace("cn.iocoder.yudao.module.template", BASE_PACKAGE + packageName)
.replace("TemplateServerApplication", capitalizedModuleName + "ServerApplication")

View File

@@ -35,10 +35,7 @@ public class ServerGenerator {
int startPort = Integer.parseInt(scanner.nextLine());
scanner.close();
// 分割服务
String[] servers = baseNames.split(",");
// 分割服务器名
// 分割服务名
String[] servers = baseNames.split(",");
// 2. 定义项目根路径
@@ -149,17 +146,22 @@ public class ServerGenerator {
// 移除对 yudao-module-xxx-server 的依赖,但保留 system-server 和 infra-server
return newContent.replaceAll("(?m)^\\s*<dependency>\\s*<groupId>cn\\.iocoder\\.cloud</groupId>\\s*<artifactId>yudao-module-(?!system-server|infra-server).*-server</artifactId>[\\s\\S]*?</dependency>\\s*", "");
case "application.yaml":
case "application.yml":
// 替换应用名称和端口号
case "application-dev.yaml":
case "application-prod.yaml":
case "application-test.yaml":
case "application-local.yaml":
// 替换应用名称
newContent = newContent.replace("name: yudao-server", "name: " + serverName);
// 如果有端口配置,替换端口号,如果没有则添加端口配置
if (newContent.contains("server:")) {
if (newContent.contains("port:")) {
newContent = newContent.replaceAll("(?m)^\\s*port:.*$", " port: " + port);
} else {
newContent = newContent.replace("server:", "server:\n port: " + port);
}
// 处理端口配置 - 更精确的替换逻辑
if (newContent.contains("port:")) {
// 使用更精确的正则表达式来匹配端口行
newContent = newContent.replaceAll("(?m)^(\\s*)port:\\s*\\d+\\s*$", "$1port: " + port);
} else if (newContent.contains("server:")) {
// 如果有server配置但没有port在server下添加port
newContent = newContent.replaceAll("(?m)^(\\s*)server:\\s*$", "$1server:\n$1 port: " + port);
} else {
// 如果完全没有server配置在文件开头添加
newContent = "server:\n port: " + port + "\n\n" + newContent;
}
return newContent;