Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
fix gen-arch配置覆盖
Browse files Browse the repository at this point in the history
  • Loading branch information
binking338 committed Aug 18, 2024
1 parent 2490afd commit 6e99935
Show file tree
Hide file tree
Showing 4 changed files with 338 additions and 323 deletions.
73 changes: 52 additions & 21 deletions src/main/java/org/netcorepal/cap4j/ddd/codegen/GenArchMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
import org.netcorepal.cap4j.ddd.codegen.misc.SourceFileUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
* 生成项目目录结构
Expand All @@ -22,23 +21,7 @@
* @date 2024/8/15
*/
@Mojo(name = "gen-arch")
public class GenArchMojo extends AbstractMojo {

/**
* 基础包路径
*
* @parameter expression="${basePackage}"
*/
@Parameter(property = "basePackage", defaultValue = "")
private String basePackage = "";

/**
* 模板文件地址
*
* @parameter expression="${archTemplate}"
*/
@Parameter(property = "archTemplate", defaultValue = "")
private String archTemplate = "";
public class GenArchMojo extends MyAbstractMojo {

/**
* 脚手架模板配置节点
Expand Down Expand Up @@ -90,7 +73,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
} catch (IOException e) {
throw new RuntimeException(e);
}
if(basePackage==null || basePackage.isEmpty()){
if (basePackage == null || basePackage.isEmpty()) {
getLog().warn("请设置basePackage参数");
return;
}
Expand Down Expand Up @@ -204,13 +187,61 @@ public String escapePath(String path) {
}

public String escapeContent(String content) {
content = content.replace("${basePackage}", basePackage);
content = content.replace("${groupId}", projectGroupId);
content = content.replace("${artifactId}", projectArtifactId);
content = content.replace("${version}", projectVersion);
content = content.replace("${archTemplate}", archTemplate);
content = content.replace("${basePackage}", basePackage);
content = content.replace("${multiModule}", multiModule ? "true" : "false");
content = content.replace("${moduleNameSuffix4Adapter}", moduleNameSuffix4Adapter);
content = content.replace("${moduleNameSuffix4Domain}", moduleNameSuffix4Domain);
content = content.replace("${moduleNameSuffix4Application}", moduleNameSuffix4Application);
content = content.replace("${connectionString}", connectionString);
content = content.replace("${user}", user);
content = content.replace("${pwd}", pwd);
content = content.replace("${schema}", schema);
content = content.replace("${table}", table);
content = content.replace("${ignoreTable}", ignoreTable);
content = content.replace("${idField}", idField);
content = content.replace("${versionField}", versionField);
content = content.replace("${deletedField}", deletedField);
content = content.replace("${readonlyFields}", readonlyFields);
content = content.replace("${ignoreFields}", ignoreFields);
content = content.replace("${entityBaseClass}", entityBaseClass);
content = content.replace("${entityMetaInfoClassOutputPackage}", entityMetaInfoClassOutputPackage);
content = content.replace("${entityMetaInfoClassOutputMode}", entityMetaInfoClassOutputMode);
content = content.replace("${idGenerator}", idGenerator);
content = content.replace("${fetchType}", fetchType);
content = content.replace("${fetchMode}", fetchMode);
content = content.replace("${enumValueField}", enumValueField);
content = content.replace("${enumNameField}", enumNameField);
content = content.replace("${enumUnmatchedThrowException}", enumUnmatchedThrowException ? "true" : "false");
content = content.replace("${datePackage4Java}", datePackage4Java);
content = content.replace("${typeRemapping}", stringfyTypeRemapping());
content = content.replace("${generateDefault}", generateDefault ? "true" : "false");
content = content.replace("${generateDbType}", generateDbType ? "true" : "false");
content = content.replace("${generateSchema}", generateSchema ? "true" : "false");
content = content.replace("${generateBuild}", generateBuild ? "true" : "false");
content = content.replace("${aggregateRootAnnotation}", aggregateRootAnnotation);
content = content.replace("${aggregateRepositoryBaseClass}", aggregateRepositoryBaseClass);
content = content.replace("${aggregateIdentityClass}", aggregateIdentityClass);
content = content.replace("${aggregateRepositoryCustomerCode}", aggregateRepositoryCustomerCode);
content = content.replace("${ignoreAggregateRoots}", ignoreAggregateRoots);
content = content.replace("${symbol_pound}", "#");
content = content.replace("${symbol_escape}", "\\");
content = content.replace("${symbol_dollar}", "$");
return content;
}

private String stringfyTypeRemapping() {
if (typeRemapping == null || typeRemapping.isEmpty()) {
return "";
}
String result = "";
for (Map.Entry<String, String> kv :
typeRemapping.entrySet()) {
result += "<" + kv.getKey() + ">" + kv.getValue() + "</\"+kv.getKey()+\">";
}
return result;
}
}
231 changes: 4 additions & 227 deletions src/main/java/org/netcorepal/cap4j/ddd/codegen/GenEntityMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import org.netcorepal.cap4j.ddd.codegen.misc.MysqlSchemaUtils;
import org.netcorepal.cap4j.ddd.codegen.misc.SourceFileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.BufferedWriter;
import java.io.File;
Expand All @@ -28,228 +26,7 @@
* @date 2022-02-16
*/
@Mojo(name = "gen-entity")
public class GenEntityMojo extends AbstractMojo {
/**
* 是否多项目
*
* @parameter expression="${multiModule}"
*/
@Parameter(property = "multiModule", defaultValue = "false")
private Boolean multiModule = false;
/**
* domain模块名称
*
* @parameter expression="${moduleNameDomain}"
*/
@Parameter(property = "moduleNameDomain", defaultValue = "-domain")
private String moduleNameDomain = "-domain";
/**
* application模块名称
*
* @parameter expression="${moduleNameApplication}"
*/
@Parameter(property = "moduleNameApplication", defaultValue = "-application")
private String moduleNameApplication = "-application";
/**
* adapter模块名称
*
* @parameter expression="${moduleNameAdapter}"
*/
@Parameter(property = "moduleNameAdapter", defaultValue = "-adapter")
private String moduleNameAdapter = "-adapter";

/**
* 基础包路径
*
* @parameter expression="${basePackage}"
*/
@Parameter(property = "basePackage", defaultValue = "")
private String basePackage = "";

/**
* @parameter expression="${connectionString}"
*/
@Parameter(property = "connectionString")
private String connectionString;
/**
* @parameter expression="${user}"
*/
@Parameter(property = "user")
private String user;
/**
* @parameter expression="${pwd}"
*/
@Parameter(property = "pwd")
private String pwd;
/**
* @parameter expression="${schema}"
*/
@Parameter(property = "schema")
private String schema;
/**
* @parameter expression="${table}"
*/
@Parameter(property = "table", defaultValue = "%")
private String table;
/**
* @parameter expression="${ignoreTable}"
*/
@Parameter(property = "ignoreTable", defaultValue = "")
private String ignoreTable;
/**
* 主键字段名 默认 id
*
* @parameter expression="${idField}"
*/
@Parameter(property = "idField", defaultValue = "id")
private String idField = "id";
/**
* 主键生成器 默认自增策略
*
* @parameter expression="${idGenerator}"
*/
@Parameter(property = "idGenerator", defaultValue = "")
private String idGenerator = "";

/**
* 乐观锁字段
*
* @parameter expression="${versionField}"
*/
@Parameter(property = "versionField", defaultValue = "version")
private String versionField = "version";
/**
* 软删字段
*
* @parameter expression="${deletedField}"
*/
@Parameter(property = "deletedField", defaultValue = "deleted")
private String deletedField = "deleted";
/**
* 标记只读字段,逗号","或分号";"分割,不会通过ORM更新到数据库
*
* @parameter expression="${readonlyFields}"
*/
@Parameter(property = "readonlyFields", defaultValue = "")
private String readonlyFields = "";
/**
* 标记忽略字段,逗号","或分号";"分割,不会通过ORM绑定到实体
*
* @parameter expression="${ignoreFields}"
*/
@Parameter(property = "ignoreFields", defaultValue = "")
private String ignoreFields = "";
/**
* 枚举【值】字段配置
*
* @parameter expression="${enumValueField}"
*/
@Parameter(property = "enumValueField", defaultValue = "value")
private String enumValueField = "value";
/**
* 枚举【名】字段配置
*
* @parameter expression="${enumNameField}"
*/
@Parameter(property = "enumNameField", defaultValue = "name")
private String enumNameField = "name";
/**
* 枚举不匹配时,是否抛出异常
*
* @parameter expression="${enumUnmatchedThrowException}"
*/
@Parameter(property = "enumUnmatchedThrowException", defaultValue = "true")
private Boolean enumUnmatchedThrowException = true;
/**
* 生成默认值,来源数据库默认值
*
* @parameter expression="${generateDefault}"
*/
@Parameter(property = "generateDefault", defaultValue = "false")
private Boolean generateDefault = false;
/**
* 数据库字段类型 到 代码类型 映射
*
* @parameter expression="${typeRemapping}"
*/
@Parameter(property = "typeRemapping", defaultValue = "")
private Map<String, String> typeRemapping = new HashMap<>();

/**
* 日期类型映射使用的包 默认java.util
* java.util | java.time
*
* @parameter expression="${datePackage}"
*/
@Parameter(property = "datePackage4Java", defaultValue = "java.util")
private String datePackage4Java = "java.util";

/**
* 生成数据库字段类型到字段注释中
*
* @parameter expression="${generateDbType}"
*/
@Parameter(property = "generateDbType", defaultValue = "false")
private Boolean generateDbType = false;
/**
* 生成Schema类
*
* @parameter expression="${generateSchema}"
*/
@Parameter(property = "generateSchema", defaultValue = "false")
private Boolean generateSchema = false;

/**
* 关联实体加载模式 LAZY | EAGER
*
* @parameter expression="${fetchType}"
*/
@Parameter(property = "fetchType", defaultValue = "EAGER")
private String fetchType = "EAGER";
/**
* 关联实体加载模式 SUBSELECT | JOIN | SELECT
*
* @parameter expression="${fetchMode}"
*/
@Parameter(property = "fetchMode", defaultValue = "SUBSELECT")
private String fetchMode = "SUBSELECT";
/**
* 生成EntitBuilder类
*
* @parameter expression="${generateBuild}"
*/
@Parameter(property = "generateBuild", defaultValue = "false")
private Boolean generateBuild = false;

/**
* 实体辅助类输出包
*
* @parameter expression="${entityMetaInfoClassOutputPackage}"
*/
@Parameter(property = "entityMetaInfoClassOutputPackage", defaultValue = "domain._share.meta")
private String entityMetaInfoClassOutputPackage = "domain._share.meta";
/**
* 实体辅助类输出模式,绝对路径或相对路径,abs|ref
*
* @parameter expression="${entityMetaInfoClassOutputMode}"
*/
@Parameter(property = "entityMetaInfoClassOutputMode", defaultValue = "")
private String entityMetaInfoClassOutputMode = "abs";
/**
* 实体基础类
*
* @parameter expression="${entityBaseClass}"
*/
@Parameter(property = "entityBaseClass", defaultValue = "")
private String entityBaseClass = "";
/**
* 聚合根注解
*
* @parameter expression="${aggregateRootAnnotation}"
*/
@Parameter(property = "aggregateRootAnnotation", defaultValue = "")
private String aggregateRootAnnotation = "";

public class GenEntityMojo extends MyAbstractMojo {

private Map<String, Map<String, Object>> TableMap = new HashMap<>();
private Map<String, List<Map<String, Object>>> ColumnsMap = new HashMap<>();
Expand All @@ -270,13 +47,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
: new File(absoluteCurrentDir).getParent();

domainModulePath = Arrays.stream(new File(projectDir).listFiles())
.filter(path -> path.getAbsolutePath().endsWith(moduleNameDomain))
.filter(path -> path.getAbsolutePath().endsWith(moduleNameSuffix4Domain))
.findFirst().get().getAbsolutePath();
applicationModulePath = Arrays.stream(new File(projectDir).listFiles())
.filter(path -> path.getAbsolutePath().endsWith(moduleNameApplication))
.filter(path -> path.getAbsolutePath().endsWith(moduleNameSuffix4Application))
.findFirst().get().getAbsolutePath();
adapterModulePath = Arrays.stream(new File(projectDir).listFiles())
.filter(path -> path.getAbsolutePath().endsWith(moduleNameAdapter))
.filter(path -> path.getAbsolutePath().endsWith(moduleNameSuffix4Adapter))
.findFirst().get().getAbsolutePath();
} else {
projectDir = absoluteCurrentDir;
Expand Down
Loading

0 comments on commit 6e99935

Please sign in to comment.