Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibizlab-generator
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibizlab-generator
提交
ce7f195c
提交
ce7f195c
编写于
9月 07, 2022
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支持环境变量
上级
8afb82ad
变更
7
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
143 行增加
和
8 行删除
+143
-8
Generate.java
...or-cli/src/main/java/cn/ibizlab/codegen/cmd/Generate.java
+13
-6
CodegenConfigurator.java
...n/java/cn/ibizlab/codegen/config/CodegenConfigurator.java
+2
-1
DynamicParamUtils.java
...ain/java/cn/ibizlab/codegen/config/DynamicParamUtils.java
+77
-0
EmbedTemplate.java
...rc/main/java/cn/ibizlab/codegen/config/EmbedTemplate.java
+1
-0
GeneratorSettings.java
...ain/java/cn/ibizlab/codegen/config/GeneratorSettings.java
+40
-1
Volume.java
...-core/src/main/java/cn/ibizlab/codegen/config/Volume.java
+2
-0
generator.xml.hbs
...generator-core/src/main/resources/templ/generator.xml.hbs
+8
-0
未找到文件。
modules/ibizlab-generator-cli/src/main/java/cn/ibizlab/codegen/cmd/Generate.java
浏览文件 @
ce7f195c
...
@@ -135,15 +135,22 @@ public class Generate extends IbizLabGeneratorCommand {
...
@@ -135,15 +135,22 @@ public class Generate extends IbizLabGeneratorCommand {
configs
.
forEach
(
configurator
->{
configs
.
forEach
(
configurator
->{
if
(
isEmpty
(
configurator
.
getInputSpec
())&&
isNotEmpty
(
spec
))
{
if
(
isEmpty
(
configurator
.
getInputSpec
())&&
isNotEmpty
(
spec
))
{
if
(!
spec
.
matches
(
"^http(s)?://.*"
)
&&
!
new
File
(
spec
).
exists
())
{
System
.
err
.
println
(
"[error] The spec file is not found: "
+
spec
);
System
.
err
.
println
(
"[error] Check the path of the ibizlab-Model spec and try again."
);
System
.
exit
(
1
);
}
configurator
.
setInputSpec
(
spec
);
configurator
.
setInputSpec
(
spec
);
}
}
if
(
isEmpty
(
configurator
.
getInputSpec
()))
{
System
.
err
.
println
(
"[error] The spec file is not found: "
+
spec
);
System
.
err
.
println
(
"[error] Check the path of the ibizlab-Model spec and try again."
);
System
.
exit
(
1
);
}
File
specFile
=
new
File
(
configurator
.
getInputSpec
());
if
(!
configurator
.
getInputSpec
().
matches
(
"^http(s)?://.*"
)
&&
!
specFile
.
exists
())
{
System
.
err
.
println
(
"[error] The spec file is not found: "
+
spec
);
System
.
err
.
println
(
"[error] Check the path of the ibizlab-Model spec and try again."
);
System
.
exit
(
1
);
}
configurator
.
addAdditionalProperty
(
"inputSpecPath"
,
specFile
.
getAbsolutePath
());
...
...
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/config/CodegenConfigurator.java
浏览文件 @
ce7f195c
...
@@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory;
...
@@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.util.*
;
import
java.util.*
;
...
@@ -62,7 +63,7 @@ public final class CodegenConfigurator {
...
@@ -62,7 +63,7 @@ public final class CodegenConfigurator {
@SuppressWarnings
(
"DuplicatedCode"
)
@SuppressWarnings
(
"DuplicatedCode"
)
public
static
List
<
CodegenConfigurator
>
fromFile
(
String
configFile
,
Module
...
modules
)
{
public
static
List
<
CodegenConfigurator
>
fromFile
(
String
configFile
,
Module
...
modules
)
{
if
(
isNotEmpty
(
configFile
))
{
if
(
isNotEmpty
(
configFile
)
&&
Files
.
exists
(
Paths
.
get
(
configFile
))
)
{
DynamicSettings
dynamicSettings
=
readDynamicSettings
(
configFile
,
modules
);
DynamicSettings
dynamicSettings
=
readDynamicSettings
(
configFile
,
modules
);
if
(!
ObjectUtils
.
isEmpty
(
dynamicSettings
))
if
(!
ObjectUtils
.
isEmpty
(
dynamicSettings
))
{
{
...
...
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/config/DynamicParamUtils.java
0 → 100644
浏览文件 @
ce7f195c
package
cn
.
ibizlab
.
codegen
.
config
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
public
class
DynamicParamUtils
{
private
static
final
String
DYNAMIC_PARAM_PREFIX
=
"${"
;
private
static
final
String
DYNAMIC_PARAM_SUFFIX
=
"}"
;
public
static
Object
processObject
(
Object
content
)
{
if
(
ObjectUtils
.
isEmpty
(
content
))
return
content
;
else
if
(
content
instanceof
String
)
return
process
(
content
.
toString
());
else
if
(
content
instanceof
List
&&
((
List
)
content
).
get
(
0
)
instanceof
String
)
{
return
process
((
List
)
content
);
}
return
content
;
}
public
static
String
process
(
String
content
)
{
return
processDynamicParams
(
content
,
System
.
getenv
());
}
public
static
List
<
String
>
process
(
List
<
String
>
content
)
{
if
(
content
==
null
)
return
null
;
List
<
String
>
rt
=
new
ArrayList
<>();
content
.
forEach
(
item
->{
rt
.
add
(
process
(
item
));
});
return
rt
;
}
// 多变量,data 为 key - value 形式
public
static
String
processDynamicParams
(
String
content
,
Map
data
)
{
if
(
content
==
null
)
return
null
;
int
begin
=
content
.
indexOf
(
DYNAMIC_PARAM_PREFIX
);
int
end
=
content
.
indexOf
(
DYNAMIC_PARAM_SUFFIX
);
if
(
begin
==
-
1
||
end
==
-
1
||
begin
>
end
)
{
return
content
;
}
String
startContent
=
content
.
substring
(
0
,
begin
);
String
substring
=
content
.
substring
(
begin
,
end
+
1
);
if
(
StringUtils
.
isNotEmpty
(
substring
))
{
String
key
=
substring
.
replace
(
"${"
,
""
).
replace
(
"}"
,
""
);
String
[]
pairs
=
key
.
split
(
":"
);
String
defaultValue
=
null
;
if
(
pairs
.
length
>
1
)
{
key
=
pairs
[
0
];
defaultValue
=
pairs
[
1
];
}
Object
value
=
data
.
get
(
key
);
if
(
ObjectUtils
.
isEmpty
(
value
))
value
=
data
.
getOrDefault
(
key
.
toUpperCase
(),
defaultValue
);
if
(
value
!=
null
)
{
startContent
=
startContent
+
value
.
toString
();
}
else
{
startContent
+=
substring
;
}
}
int
length
=
content
.
length
();
if
(
length
==
end
+
1
)
{
return
startContent
;
}
else
{
return
startContent
+
processDynamicParams
(
content
.
substring
(
end
+
1
,
length
),
data
);
}
}
}
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/config/EmbedTemplate.java
浏览文件 @
ce7f195c
...
@@ -23,6 +23,7 @@ public class EmbedTemplate {
...
@@ -23,6 +23,7 @@ public class EmbedTemplate {
public
static
EmbedTemplate
from
(
String
tag
)
{
public
static
EmbedTemplate
from
(
String
tag
)
{
if
(
ObjectUtils
.
isEmpty
(
tag
))
if
(
ObjectUtils
.
isEmpty
(
tag
))
return
null
;
return
null
;
tag
=
DynamicParamUtils
.
process
(
tag
);
EmbedTemplate
template
=
new
EmbedTemplate
();
EmbedTemplate
template
=
new
EmbedTemplate
();
String
tags
[]=
tag
.
split
(
":"
);
String
tags
[]=
tag
.
split
(
":"
);
template
.
setName
(
tags
[
0
]);
template
.
setName
(
tags
[
0
]);
...
...
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/config/GeneratorSettings.java
浏览文件 @
ce7f195c
...
@@ -57,7 +57,46 @@ public class GeneratorSettings implements Serializable {
...
@@ -57,7 +57,46 @@ public class GeneratorSettings implements Serializable {
@JsonAnySetter
@JsonAnySetter
public
void
set
(
String
field
,
Object
value
)
{
public
void
set
(
String
field
,
Object
value
)
{
this
.
additionalProperties
.
put
(
field
,
value
);
this
.
additionalProperties
.
put
(
field
,
DynamicParamUtils
.
processObject
(
value
));
}
public
void
setProjectName
(
String
projectName
)
{
this
.
projectName
=
DynamicParamUtils
.
process
(
projectName
);
}
public
void
setPackageName
(
String
packageName
)
{
this
.
packageName
=
DynamicParamUtils
.
process
(
packageName
);
}
public
void
setOutput
(
String
output
)
{
this
.
output
=
DynamicParamUtils
.
process
(
output
);
}
public
void
setInputSpec
(
String
inputSpec
)
{
this
.
inputSpec
=
DynamicParamUtils
.
process
(
inputSpec
);
}
public
void
setInputSpecFilters
(
List
<
String
>
inputSpecFilters
)
{
this
.
inputSpecFilters
=
DynamicParamUtils
.
process
(
inputSpecFilters
);
}
public
void
setTemplateDirs
(
List
<
String
>
templateDirs
)
{
this
.
templateDirs
=
DynamicParamUtils
.
process
(
templateDirs
);
}
public
void
setTemplatePaths
(
List
<
String
>
templatePaths
)
{
this
.
templatePaths
=
DynamicParamUtils
.
process
(
templatePaths
);
}
public
void
setTemplateFilters
(
List
<
String
>
templateFilters
)
{
this
.
templateFilters
=
DynamicParamUtils
.
process
(
templateFilters
);
}
public
void
setAuth
(
String
auth
)
{
this
.
auth
=
DynamicParamUtils
.
process
(
auth
);
}
}
}
}
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/config/Volume.java
浏览文件 @
ce7f195c
...
@@ -38,6 +38,7 @@ public class Volume {
...
@@ -38,6 +38,7 @@ public class Volume {
public
static
Volume
from
(
String
tag
)
{
public
static
Volume
from
(
String
tag
)
{
if
(
ObjectUtils
.
isEmpty
(
tag
))
if
(
ObjectUtils
.
isEmpty
(
tag
))
return
null
;
return
null
;
tag
=
DynamicParamUtils
.
process
(
tag
);
Volume
volume
=
new
Volume
();
Volume
volume
=
new
Volume
();
String
tags
[]=
tag
.
split
(
":"
);
String
tags
[]=
tag
.
split
(
":"
);
volume
.
setSource
(
tags
[
0
]);
volume
.
setSource
(
tags
[
0
]);
...
@@ -48,4 +49,5 @@ public class Volume {
...
@@ -48,4 +49,5 @@ public class Volume {
return
volume
;
return
volume
;
}
}
}
}
modules/ibizlab-generator-core/src/main/resources/templ/generator.xml.hbs
浏览文件 @
ce7f195c
...
@@ -91,7 +91,15 @@
...
@@ -91,7 +91,15 @@
${basedir}/
${basedir}/
</output>
</output>
<inputSpec>
<inputSpec>
{{#if
embedTemplates
}}
{{#if
inputSpecPath
}}
{{
inputSpecPath
}}
{{else}}
${basedir}/
{{
system
.
modelFolder
}}
${basedir}/
{{
system
.
modelFolder
}}
{{/if}}
{{else}}
${basedir}/
{{
system
.
modelFolder
}}
{{/if}}
</inputSpec>
</inputSpec>
<templateDirs>
<templateDirs>
${basedir}/src/main/resources/templ
${basedir}/src/main/resources/templ
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录