提交 2e1570c5 编写于 作者: sq3536's avatar sq3536

准备支持模型过滤,更改多参数传入方式,支持命令参数重复传递进List

上级 5f9130ef
......@@ -9,6 +9,7 @@ import cn.ibizlab.codegen.config.CodegenConfiguratorUtils;
import cn.ibizlab.codegen.*;
import io.airlift.airline.Command;
import io.airlift.airline.Option;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
......@@ -34,19 +35,27 @@ public class Generate extends IbizLabGeneratorCommand {
description = "location of the ibizlab-Model spec, as URL or file (required if not loaded via config using -c)")
private String spec;
@Option(name = {"-f", "--input-spec-filter"}, title = "model's filter regex",
description = "input spec model file's filter regex, multiple regex are supported, the format of page:EntityAEditView,page:EntityAEditView,appEntity:EntityA,ctrl:main " +
"(or multiple options, each with -f page:EntityAEditView -f page:EntityAEditView -f appEntity:EntityA -f ctrl:main)")
private List<String> filters;
@Option(name = {"-t", "--template-dir"}, title = "template directories",
description = "folder containing the template files, multiple paths are supported, separated by commas. (e.g. /templateA,/tmp/templateB).")
private String templateDir;
description = "folder containing the template files, multiple paths are supported, the format of /templateA,/tmp/templateB " +
"(or multiple options, each with --template-dir /templateA --template-dir /tmp/templateB)")
private List<String> templateDirs;
@Option(name = {"--template-path"}, title = "template files relative path",
description = "special template file's relative path, multiple paths are supported, separated by commas. (e.g. /folderA/README.md.hbs,/folderB/sub/file.json.hbs).")
private String templatePath;
description = "special template file's relative path, multiple paths are supported, the format of /folderA/README.md.hbs,/folderB/sub/file.json.hbs " +
"(or multiple options, each with --template-path /folderA/README.md.hbs --template-path /folderB/sub/file.json.hbs)")
private List<String> templatePaths;
@Option(name = {"--template-filter"}, title = "template file's filter regex",
description = "template file's filter regex, multiple regex are supported, separated by commas. (e.g. /folderA,/folderB/.*/{{entities}}.java.hbs).")
private String templateFilter;
description = "template file's filter regex, multiple regex are supported, the format of /folderA,/folderB/.*/{{entities}}.java.hbs " +
"(or multiple options, each with --template-filter /folderA --template-filter /folderB/.*/{{entities}}.java.hbs)")
private List<String> templateFilters;
@Option(
name = {"-a", "--auth"},
......@@ -156,16 +165,20 @@ public class Generate extends IbizLabGeneratorCommand {
configurator.setAuth(auth);
}
if (isNotEmpty(templateDir)) {
configurator.setTemplateDir(templateDir);
if (!ObjectUtils.isEmpty(templateDirs)) {
configurator.setTemplateDirs(templateDirs);
}
if (!ObjectUtils.isEmpty(templatePaths)) {
configurator.setTemplatePaths(templatePaths);
}
if (isNotEmpty(templatePath)) {
configurator.setTemplatePath(templatePath);
if (!ObjectUtils.isEmpty(templateFilters)) {
configurator.setTemplateFilters(templateFilters);
}
if (isNotEmpty(templateFilter)) {
configurator.setTemplateFilter(templateFilter);
if (!ObjectUtils.isEmpty(filters)) {
configurator.setFilters(filters);
}
if (isNotEmpty(packageName)) {
......
......@@ -33,6 +33,8 @@ public class CodegenConfig {
private String inputSpec;
private String outputDir;
private List<String> filters;
private List<String> templateDirs;
private String auth;
......@@ -59,11 +61,29 @@ public class CodegenConfig {
}
public CodegenConfig setFilter(List<String> filters) {
if(ObjectUtils.isEmpty(filters))
return this;
this.filters=new ArrayList<>();
if(filters.size()==1)
filters=Arrays.asList(filters.get(0).split(";|,"));
for(String filter:filters)
{
filter=filter.trim();
if(!StringUtils.isEmpty(filter))
{
this.filters.add(filter);
}
}
return this;
}
public CodegenConfig setTemplateDirs(List<String> templateDirs) {
if(ObjectUtils.isEmpty(templateDirs))
return this;
this.templateDirs=new ArrayList<>();
if(templateDirs.size()==1)
templateDirs=Arrays.asList(templateDirs.get(0).split(";|,"));
for(String templateDir:templateDirs)
{
templateDir=templateDir.trim();
......@@ -78,16 +98,13 @@ public class CodegenConfig {
return this;
}
public CodegenConfig setTemplateDirs(String dirs) {
if(!StringUtils.isEmpty(dirs))
setTemplateDirs(Arrays.asList(dirs.split(";|,")));
return this;
}
public CodegenConfig setTemplatePaths(List<String> templatePaths) {
if(ObjectUtils.isEmpty(templatePaths))
return this;
this.templatePaths=new ArrayList<>();
if(templatePaths.size()==1)
templatePaths=Arrays.asList(templatePaths.get(0).split(";|,"));
for(String templatePath:templatePaths)
{
templatePath=templatePath.trim();
......@@ -104,16 +121,12 @@ public class CodegenConfig {
return this;
}
public CodegenConfig setTemplatePaths(String paths) {
if(!StringUtils.isEmpty(paths))
setTemplatePaths(Arrays.asList(paths.split(";|,")));
return this;
}
public CodegenConfig setTemplateFilters(List<String> templateFilters) {
if(ObjectUtils.isEmpty(templateFilters))
return this;
this.templateFilters=new ArrayList<>();
if(templateFilters.size()==1)
templateFilters=Arrays.asList(templateFilters.get(0).split(";|,"));
for(String filter:templateFilters)
{
filter=filter.trim();
......@@ -130,18 +143,6 @@ public class CodegenConfig {
return this;
}
public CodegenConfig setTemplateFilters(String templateFilters) {
if(!StringUtils.isEmpty(templateFilters))
setTemplateFilters(Arrays.asList(templateFilters.split(";|,")));
return this;
}
public String getTemplateDir()
{
if(!ObjectUtils.isEmpty(this.getTemplateDirs()))
return this.getTemplateDirs().get(0);
return null;
}
private Map<String, Object> additionalProperties = new HashMap<>();
......
......@@ -13,6 +13,7 @@ import cn.ibizlab.codegen.templating.TemplatingEngineLoader;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.core.util.Yaml;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -37,12 +38,13 @@ public final class CodegenConfigurator {
private String inputSpec;
private String outputDir;
private String templateDir;
private String templatePath;
private String templateFilter;
private List<String> filters;
private List<String> templateDirs;
private List<String> templatePaths;
private List<String> templateFilters;
private String auth;
private String templatingEngineName="mustache";
private String templatingEngineName="handlebars";
private Map<String, String> globalProperties = new HashMap<>();
private Map<String, Object> additionalProperties = new HashMap<>();
......@@ -207,21 +209,26 @@ public final class CodegenConfigurator {
}
public CodegenConfigurator setTemplateDir(String templateDir) {
this.templateDir = templateDir;
public CodegenConfigurator setTemplateDirs(List<String> templateDirs) {
this.templateDirs = templateDirs;
return this;
}
public CodegenConfigurator setTemplatePath(String templatePath) {
this.templatePath = templatePath;
public CodegenConfigurator setTemplatePaths(List<String> templatePaths) {
this.templatePaths = templatePaths;
return this;
}
public CodegenConfigurator setTemplateFilter(String templateFilter) {
this.templateFilter = templateFilter;
public CodegenConfigurator setTemplateFilters(List<String> templateFilters) {
this.templateFilters = templateFilters;
return this;
}
public CodegenConfigurator setFilters(List<String> filters) {
this.filters = filters;
return this;
}
public CodegenConfig toClientOptInput() {
......@@ -230,13 +237,8 @@ public final class CodegenConfigurator {
// regardless of entrypoint (CLI sets properties on this type, config deserialization sets on generatorSettings).
CodegenConfig config = new CodegenConfig();
// TODO: Work toward CodegenConfig having a "WorkflowSettings" property, or better a "Workflow" object which itself has a "WorkflowSettings" property.
TemplatingEngineAdapter templatingEngine = new HandlebarsEngineAdapter();
config.setTemplatingEngine(templatingEngine);
......@@ -249,12 +251,23 @@ public final class CodegenConfigurator {
config.setInputSpec(this.inputSpec);
if(!StringUtils.isEmpty(this.outputDir))
config.setOutputDir(this.outputDir);
if(!StringUtils.isEmpty(this.templateDir))
config.setTemplateDirs(this.templateDir);
if(!StringUtils.isEmpty(this.templatePath))
config.setTemplatePaths(this.templatePath);
if(!StringUtils.isEmpty(this.templateFilter))
config.setTemplateFilters(this.templateFilter);
if(!ObjectUtils.isEmpty(filters)) {
config.setFilters(this.filters);
}
if(!ObjectUtils.isEmpty(templateDirs)) {
config.setTemplateDirs(this.templateDirs);
}
if(!ObjectUtils.isEmpty(templatePaths)) {
config.setTemplatePaths(this.templatePaths);
}
if(!ObjectUtils.isEmpty(templateFilters)) {
config.setTemplateFilters(this.templateFilters);
}
if(!StringUtils.isEmpty(this.auth))
config.setAuth(this.auth);
......
package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.templating.TemplateFileType;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.ObjectUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class CliFilter {
private Map<TemplateFileType,Set<String>> items=new HashMap<>();
public CliFilter(List<String> exps)
{
if(!ObjectUtils.isEmpty(exps))
{
for(String exp:exps)
{
}
}
}
}
......@@ -123,4 +123,6 @@ public class CliOption extends DataObj
{
return super.size();
}
}
......@@ -82,12 +82,4 @@ public class TemplateDefinition {
return getType(path.getParent());
}
public static void main(String[] args) {
String m="src/main/resources/templ/r7/{{projectName}}-boot/src/main/java/{{packageName@NONE}}/config/DevBootAutoConfiguration.java.hbs"
.replace("{{","\\{\\{").replace("}}","\\}\\}");
System.out.println("src/main/resources/templ/r7/{{projec1tName}}-boot/src/main/java/{{packageName@NONE}}/config/DevBootAutoConfiguration.java.hbs"
.matches(".*"+m+".*"));
}
}
......@@ -41,7 +41,7 @@ public enum TemplateFileType {
*/
public static TemplateFileType forTemplateType(String templateType) {
for (TemplateFileType value : values()) {
if (value.templateType.equals(templateType)) {
if (value.templateType.equalsIgnoreCase(templateType)||value.name().equalsIgnoreCase(templateType)) {
return value;
}
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册