Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibizlab-generator
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibizlab-generator
提交
8da6003a
提交
8da6003a
编写于
2月 14, 2022
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支持模型过滤,如-f appEntities:City -f ctrl@FORM:Main -f entity:City
上级
dbdcceba
变更
7
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
163 行增加
和
13 行删除
+163
-13
CodegenConfig.java
...-core/src/main/java/cn/ibizlab/codegen/CodegenConfig.java
+8
-1
DefaultGenerator.java
...re/src/main/java/cn/ibizlab/codegen/DefaultGenerator.java
+1
-1
CliFilter.java
...ore/src/main/java/cn/ibizlab/codegen/model/CliFilter.java
+63
-5
CliOption.java
...ore/src/main/java/cn/ibizlab/codegen/model/CliOption.java
+14
-1
ModelStorage.java
.../src/main/java/cn/ibizlab/codegen/model/ModelStorage.java
+5
-1
TemplateDefinition.java
...ava/cn/ibizlab/codegen/templating/TemplateDefinition.java
+71
-3
TemplateFileType.java
.../java/cn/ibizlab/codegen/templating/TemplateFileType.java
+1
-1
未找到文件。
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/CodegenConfig.java
浏览文件 @
8da6003a
package
cn
.
ibizlab
.
codegen
;
import
cn.ibizlab.codegen.config.GlobalSettings
;
import
cn.ibizlab.codegen.model.CliFilter
;
import
cn.ibizlab.codegen.templating.*
;
import
cn.ibizlab.codegen.templating.mustache.*
;
import
cn.ibizlab.codegen.utils.StringAdvUtils
;
...
...
@@ -35,6 +36,8 @@ public class CodegenConfig {
private
List
<
String
>
filters
;
private
CliFilter
cliFilter
;
private
List
<
String
>
templateDirs
;
private
String
auth
;
...
...
@@ -143,7 +146,11 @@ public class CodegenConfig {
return
this
;
}
public
CliFilter
getCliFilter
()
{
if
(
cliFilter
==
null
)
cliFilter
=
new
CliFilter
(
getFilters
());
return
cliFilter
;
}
private
Map
<
String
,
Object
>
additionalProperties
=
new
HashMap
<>();
...
...
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/DefaultGenerator.java
浏览文件 @
8da6003a
...
...
@@ -58,7 +58,7 @@ public class DefaultGenerator implements Generator {
for
(
TemplateDefinition
templateDefinition:
this
.
config
.
getTemplateDefinitions
())
{
for
(
CliOption
opt:
templateDefinition
.
get
TemplateDatas
().
getOptions
(
))
for
(
CliOption
opt:
templateDefinition
.
get
Options
(
this
.
config
.
getCliFilter
()
))
{
try
{
processTemplateToFile
(
opt
,
templateDefinition
.
getTemplateFile
());
...
...
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/model/CliFilter.java
浏览文件 @
8da6003a
package
cn
.
ibizlab
.
codegen
.
model
;
import
cn.ibizlab.codegen.templating.TemplateDefinition
;
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
org.springframework.util.StringUtils
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.*
;
@Getter
@Setter
...
...
@@ -18,7 +17,7 @@ import java.util.Set;
@Accessors
(
chain
=
true
)
public
class
CliFilter
{
private
Map
<
TemplateFileType
,
Set
<
String
>>
items
=
new
HashMap
<>();
private
Map
<
String
,
Set
<
String
>>
items
=
new
HashMap
<>();
public
CliFilter
(
List
<
String
>
exps
)
{
...
...
@@ -26,10 +25,69 @@ public class CliFilter {
{
for
(
String
exp:
exps
)
{
String
[]
pairs
=
exp
.
split
(
":"
);
if
(
pairs
.
length
==
2
)
{
String
key
=
pairs
[
0
].
trim
();
String
value
=
pairs
[
1
].
trim
();
if
((!
StringUtils
.
isEmpty
(
key
))&&(!
StringUtils
.
isEmpty
(
value
)))
{
String
type
=
""
;
String
subType
=
""
;
String
[]
types
=
key
.
split
(
"@"
);
type
=
types
[
0
].
trim
();
if
(!
StringUtils
.
isEmpty
(
type
))
{
type
=
TemplateFileType
.
forTemplateType
(
type
).
name
();
if
(
type
==
null
)
continue
;
key
=
type
;
if
(
types
.
length
>
1
)
{
subType
=
types
[
1
].
trim
().
toLowerCase
();
if
(!
StringUtils
.
isEmpty
(
subType
))
key
=
key
+
"@"
+
subType
;
}
Set
<
String
>
sets
=
null
;
if
(!
items
.
containsKey
(
key
))
{
sets
=
new
LinkedHashSet
<>();
items
.
put
(
key
,
sets
);
}
else
{
sets
=
items
.
get
(
key
);
}
sets
.
add
(
value
);
LabelExt
ext
=
new
LabelExt
(
value
);
sets
.
add
(
ext
.
toLowerCase
());
sets
.
add
(
ext
.
toUpperCase
());
sets
.
add
(
ext
.
toSpinalCase
());
sets
.
add
(
ext
.
toCamelCase
());
sets
.
add
(
ext
.
toPascalCase
());
sets
.
add
(
ext
.
toSnakeCase
());
sets
.
add
(
ext
.
toPluralize
());
}
}
}
}
}
}
public
Set
<
String
>
getTypes
()
{
Set
<
String
>
sets
=
new
HashSet
<>();
if
(!
ObjectUtils
.
isEmpty
(
items
))
{
items
.
keySet
().
forEach
(
key
->{
sets
.
add
(
key
.
split
(
"@"
)[
0
]);
});
}
return
sets
;
}
}
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/model/CliOption.java
浏览文件 @
8da6003a
...
...
@@ -40,7 +40,7 @@ public class CliOption extends DataObj
return
this
.
cliSubType
;
}
public
CliOption
baseData
(
Object
baseData
,
String
path
)
public
CliOption
baseData
(
BaseModel
baseData
,
String
path
)
{
Assert
.
notNull
(
templateFileType
,
"模板类型为空"
);
this
.
set
(
templateFileType
.
name
(),
baseData
);
...
...
@@ -50,6 +50,19 @@ public class CliOption extends DataObj
return
this
;
}
public
BaseModel
getBaseData
()
{
return
this
.
getBaseData
(
templateFileType
.
name
());
}
public
BaseModel
getBaseData
(
String
key
)
{
Object
obj
=
this
.
get
(
key
);
if
(
obj
!=
null
&&
obj
instanceof
BaseModel
)
return
(
BaseModel
)
obj
;
return
null
;
}
public
CliOption
set
(
String
key
,
Object
value
)
{
this
.
put
(
key
,
value
);
...
...
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/model/ModelStorage.java
浏览文件 @
8da6003a
...
...
@@ -176,8 +176,12 @@ public class ModelStorage {
// }
else
if
(
type
.
equals
(
TemplateFileType
.
module
))
{
getSystemModel
().
getSystem
().
getAllPSSystemModules
().
forEach
(
item
->
{
BaseModel
model
=
new
BaseModel
();
model
.
setCodeName
(
item
.
getCodeName
());
model
.
setName
(
item
.
getName
());
model
.
setOpt
(
item
);
CliOption
opt
=
newCliOption
(
TemplateFileType
.
module
)
.
baseData
(
item
,
item
.
getCodeName
());
.
baseData
(
model
,
item
.
getCodeName
());
rt
.
addOption
(
opt
);
});
}
...
...
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/templating/TemplateDefinition.java
浏览文件 @
8da6003a
package
cn
.
ibizlab
.
codegen
.
templating
;
import
cn.ibizlab.codegen.model.CliData
;
import
cn.ibizlab.codegen.model.CliOption
;
import
cn.ibizlab.codegen.model.ModelStorage
;
import
cn.ibizlab.codegen.model.*
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.nio.file.Paths
;
import
java.nio.file.Path
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
...
...
@@ -82,4 +83,71 @@ public class TemplateDefinition {
return
getType
(
path
.
getParent
());
}
public
List
<
CliOption
>
getOptions
(
CliFilter
filter
)
{
List
<
CliOption
>
options
=
new
ArrayList
<>();
if
(
ObjectUtils
.
isEmpty
(
filter
)||
ObjectUtils
.
isEmpty
(
filter
.
getItems
()))
return
getTemplateDatas
().
getOptions
();
Set
<
String
>
filters
=
null
;
String
tag
=
this
.
getTemplateType
().
name
()+(
StringUtils
.
isEmpty
(
this
.
getSubType
())?
""
:(
"@"
+
this
.
getSubType
())).
toLowerCase
();
if
(
filter
.
getItems
().
containsKey
(
tag
))
filters
=
filter
.
getItems
().
get
(
tag
);
else
{
tag
=
this
.
getTemplateType
().
name
();
if
(
filter
.
getItems
().
containsKey
(
tag
))
filters
=
filter
.
getItems
().
get
(
tag
);
else
return
options
;
}
for
(
CliOption
option:
getTemplateDatas
().
getOptions
())
{
BaseModel
model
=
option
.
getBaseData
();
if
(
model
!=
null
)
{
if
(
(
(!
StringUtils
.
isEmpty
(
model
.
getCodeName
()))
&&
filters
.
contains
(
model
.
getCodeName
())
)
||
(
(!
StringUtils
.
isEmpty
(
model
.
getName
()))
&&
filters
.
contains
(
model
.
getName
())
)
)
{
boolean
matched
=
true
;
for
(
String
key:
filter
.
getItems
().
keySet
())
{
Set
<
String
>
subFilters
=
filter
.
getItems
().
get
(
key
);
TemplateFileType
type
=
TemplateFileType
.
forTemplateType
(
key
.
split
(
"@"
)[
0
]);
if
(
type
==
null
)
continue
;
if
(
type
.
name
().
equalsIgnoreCase
(
this
.
templateType
.
name
()))
continue
;
BaseModel
exModel
=
option
.
getBaseData
(
type
.
name
());
if
(
exModel
==
null
)
exModel
=
option
.
getBaseData
(
type
.
value
());
if
(
exModel
!=
null
)
{
matched
=(
(!
StringUtils
.
isEmpty
(
exModel
.
getCodeName
()))
&&
subFilters
.
contains
(
exModel
.
getCodeName
())
)
||
(
(!
StringUtils
.
isEmpty
(
exModel
.
getName
()))
&&
subFilters
.
contains
(
exModel
.
getName
())
);
}
else
{
String
path
=
option
.
getStringValue
(
type
.
value
());
if
(!
StringUtils
.
isEmpty
(
path
))
matched
=
subFilters
.
contains
(
path
);
else
continue
;
}
if
(!
matched
)
break
;
}
if
(
matched
)
options
.
add
(
option
);
}
}
}
return
options
;
}
}
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/templating/TemplateFileType.java
浏览文件 @
8da6003a
...
...
@@ -45,7 +45,7 @@ public enum TemplateFileType {
return
value
;
}
}
throw
new
IllegalArgumentException
(
"templateType not found in the available values."
)
;
return
null
;
}
public
static
class
Constants
{
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录