Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibizlab-generator
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibizlab-generator
提交
ff40a4b9
提交
ff40a4b9
编写于
9月 06, 2022
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
整改cmd
上级
ac294684
变更
27
展开全部
隐藏空白字符变更
内嵌
并排
正在显示
27 个修改的文件
包含
591 行增加
和
506 行删除
+591
-506
ExecuteResult.java
...i/src/main/java/cn/ibizlab/codegen/cmd/ExecuteResult.java
+16
-0
Generate.java
...or-cli/src/main/java/cn/ibizlab/codegen/cmd/Generate.java
+133
-101
LocalCommandExecutor.java
...ain/java/cn/ibizlab/codegen/cmd/LocalCommandExecutor.java
+123
-0
StreamGobbler.java
...i/src/main/java/cn/ibizlab/codegen/cmd/StreamGobbler.java
+68
-0
CodegenConfig.java
...-core/src/main/java/cn/ibizlab/codegen/CodegenConfig.java
+12
-11
CodegenConfigurator.java
...n/java/cn/ibizlab/codegen/config/CodegenConfigurator.java
+76
-59
Context.java
...core/src/main/java/cn/ibizlab/codegen/config/Context.java
+0
-31
DynamicSettings.java
.../main/java/cn/ibizlab/codegen/config/DynamicSettings.java
+12
-51
EmbedTemplate.java
...rc/main/java/cn/ibizlab/codegen/config/EmbedTemplate.java
+36
-0
GeneratorSettings.java
...ain/java/cn/ibizlab/codegen/config/GeneratorSettings.java
+25
-196
Volume.java
...-core/src/main/java/cn/ibizlab/codegen/config/Volume.java
+51
-0
ModelStorage.java
.../src/main/java/cn/ibizlab/codegen/model/ModelStorage.java
+3
-0
.gitignore.hbs
...ab-generator-core/src/main/resources/templ/.gitignore.hbs
+0
-15
.ibizlab-generator-ignore
...r-core/src/main/resources/templ/.ibizlab-generator-ignore
+2
-0
generator.xml.hbs
...generator-core/src/main/resources/templ/generator.xml.hbs
+11
-0
GenerateMojo.java
...plugin/src/main/java/cn/ibizlab/codegen/GenerateMojo.java
+1
-42
.ibizlab-generator-ignore
...client/src/main/resources/templ/.ibizlab-generator-ignore
+2
-0
.ibizlab-generator-ignore
...apis}}/src/main/resources/templ/.ibizlab-generator-ignore
+2
-0
.ibizlab-generator-ignore
...te-doc/src/main/resources/templ/.ibizlab-generator-ignore
+2
-0
.ibizlab-generator-ignore
...izboot/src/main/resources/templ/.ibizlab-generator-ignore
+2
-0
.ibizlab-generator-ignore
...ovider/src/main/resources/templ/.ibizlab-generator-ignore
+2
-0
.ibizlab-generator-ignore
...izedge/src/main/resources/templ/.ibizlab-generator-ignore
+2
-0
.ibizlab-generator-ignore
...}-boot/src/main/resources/templ/.ibizlab-generator-ignore
+2
-0
.ibizlab-generator-ignore
...ate-r7/src/main/resources/templ/.ibizlab-generator-ignore
+2
-0
.ibizlab-generator-ignore
...}-boot/src/main/resources/templ/.ibizlab-generator-ignore
+2
-0
.ibizlab-generator-ignore
...ate-r8/src/main/resources/templ/.ibizlab-generator-ignore
+2
-0
.ibizlab-generator-ignore
...ovider/src/main/resources/templ/.ibizlab-generator-ignore
+2
-0
未找到文件。
modules/ibizlab-generator-cli/src/main/java/cn/ibizlab/codegen/cmd/ExecuteResult.java
0 → 100644
浏览文件 @
ff40a4b9
package
cn
.
ibizlab
.
codegen
.
cmd
;
import
lombok.Data
;
import
lombok.ToString
;
@Data
@ToString
public
class
ExecuteResult
{
private
int
exitCode
;
private
String
executeOut
;
private
String
errorOut
;
public
ExecuteResult
(
int
exitCode
,
String
executeOut
)
{
this
.
exitCode
=
exitCode
;
this
.
executeOut
=
executeOut
;
}
}
\ No newline at end of file
modules/ibizlab-generator-cli/src/main/java/cn/ibizlab/codegen/cmd/Generate.java
浏览文件 @
ff40a4b9
此差异已折叠。
点击以展开。
modules/ibizlab-generator-cli/src/main/java/cn/ibizlab/codegen/cmd/LocalCommandExecutor.java
0 → 100644
浏览文件 @
ff40a4b9
package
cn
.
ibizlab
.
codegen
.
cmd
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.*
;
import
java.util.concurrent.*
;
public
class
LocalCommandExecutor
{
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
LocalCommandExecutor
.
class
);
static
ExecutorService
pool
=
new
ThreadPoolExecutor
(
0
,
50
,
3L
,
TimeUnit
.
SECONDS
,
new
SynchronousQueue
<
Runnable
>());
private
static
LocalCommandExecutor
instance
;
static
{
instance
=
new
LocalCommandExecutor
();
}
public
static
LocalCommandExecutor
getInstance
()
{
return
instance
;
}
private
void
closeQuietly
(
Closeable
c
)
{
try
{
if
(
c
!=
null
)
{
c
.
close
();
}
}
catch
(
IOException
e
)
{
logger
.
error
(
"exception"
,
e
);
}
}
public
ExecuteResult
executeCommand
(
String
command
,
long
timeout
)
{
Future
<
ExecuteResult
>
executeFuture
=
null
;
try
{
logger
.
info
(
command
);
// create a Callable for the command's Process which can be called by an Executor
Callable
<
ExecuteResult
>
call
=
new
Callable
<
ExecuteResult
>()
{
public
ExecuteResult
call
()
throws
Exception
{
ProcessBuilder
processBuilder
=
null
;
Process
process
=
null
;
InputStream
pIn
=
null
;
StreamGobbler
outputGobbler
=
null
;
try
{
processBuilder
=
new
ProcessBuilder
(
new
String
[]{
"sh"
,
"-c"
,
command
});
processBuilder
.
redirectErrorStream
(
true
);
process
=
processBuilder
.
start
();
logger
.
debug
(
command
+
" started()"
);
// close process's output stream.
process
.
getOutputStream
().
close
();
pIn
=
process
.
getInputStream
();
outputGobbler
=
new
StreamGobbler
(
pIn
,
"OUTPUT"
);
outputGobbler
.
start
();
System
.
out
.
println
(
Thread
.
currentThread
().
getName
()
+
" is running"
);
process
.
waitFor
();
return
new
ExecuteResult
(
process
.
exitValue
(),
outputGobbler
.
getContent
());
}
catch
(
Exception
ex
)
{
String
errorMessage
=
"The command ["
+
command
+
"] execute failed."
;
logger
.
error
(
errorMessage
,
ex
);
return
new
ExecuteResult
(-
1
,
""
);
}
finally
{
if
(
pIn
!=
null
)
{
closeQuietly
(
pIn
);
if
(
outputGobbler
!=
null
&&
!
outputGobbler
.
isInterrupted
())
{
outputGobbler
.
interrupt
();
}
}
if
(
process
!=
null
)
{
process
.
destroy
();
}
}
}
};
// submit the command's call and get the result from a
executeFuture
=
pool
.
submit
(
call
);
return
executeFuture
.
get
(
timeout
,
TimeUnit
.
MILLISECONDS
);
}
catch
(
TimeoutException
ex
)
{
String
errorMessage
=
"The command ["
+
command
+
"] timed out."
;
logger
.
error
(
errorMessage
,
ex
);
return
new
ExecuteResult
(-
1
,
""
);
}
catch
(
ExecutionException
ex
)
{
String
errorMessage
=
"The command ["
+
command
+
"] did not complete due to an execution error."
;
logger
.
error
(
errorMessage
,
ex
);
return
new
ExecuteResult
(-
1
,
""
);
}
catch
(
InterruptedException
ex
)
{
String
errorMessage
=
"The command ["
+
command
+
"] did not complete due to an interrupted error."
;
logger
.
error
(
errorMessage
,
ex
);
return
new
ExecuteResult
(-
1
,
""
);
}
finally
{
if
(
executeFuture
!=
null
)
{
try
{
executeFuture
.
cancel
(
true
);
}
catch
(
Exception
ignore
)
{
ignore
.
printStackTrace
();
}
}
}
}
}
\ No newline at end of file
modules/ibizlab-generator-cli/src/main/java/cn/ibizlab/codegen/cmd/StreamGobbler.java
0 → 100644
浏览文件 @
ff40a4b9
package
cn
.
ibizlab
.
codegen
.
cmd
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
StreamGobbler
extends
Thread
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
StreamGobbler
.
class
);
private
InputStream
inputStream
;
private
String
streamType
;
private
StringBuilder
buf
;
private
volatile
boolean
isStopped
=
false
;
/**
* @param inputStream the InputStream to be consumed
* @param streamType the stream type (should be OUTPUT or ERROR)
*/
public
StreamGobbler
(
final
InputStream
inputStream
,
final
String
streamType
)
{
this
.
inputStream
=
inputStream
;
this
.
streamType
=
streamType
;
this
.
buf
=
new
StringBuilder
();
this
.
isStopped
=
false
;
}
/**
* Consumes the output from the input stream and displays the lines consumed
* if configured to do so.
*/
@Override
public
void
run
()
{
try
{
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
inputStream
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
inputStreamReader
);
String
line
=
null
;
while
((
line
=
bufferedReader
.
readLine
())
!=
null
)
{
this
.
buf
.
append
(
line
+
"\n"
);
System
.
out
.
println
(
line
);
}
}
catch
(
IOException
ex
)
{
logger
.
trace
(
"Failed to successfully consume and display the input stream of type "
+
streamType
+
"."
,
ex
);
}
finally
{
this
.
isStopped
=
true
;
synchronized
(
this
)
{
notify
();
}
}
}
public
String
getContent
()
{
if
(!
this
.
isStopped
)
{
synchronized
(
this
)
{
try
{
wait
();
}
catch
(
InterruptedException
ignore
)
{
ignore
.
printStackTrace
();
}
}
}
return
this
.
buf
.
toString
();
}
public
String
getText
()
{
return
this
.
buf
.
toString
();
}
}
\ No newline at end of file
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/CodegenConfig.java
浏览文件 @
ff40a4b9
package
cn
.
ibizlab
.
codegen
;
import
cn.ibizlab.codegen.config.EmbedTemplate
;
import
cn.ibizlab.codegen.config.GlobalSettings
;
import
cn.ibizlab.codegen.model.CliFilter
;
import
cn.ibizlab.codegen.templating.*
;
...
...
@@ -42,7 +43,7 @@ public class CodegenConfig {
private
List
<
String
>
templateDirs
;
private
String
embedTemplate
;
private
List
<
EmbedTemplate
>
embedTemplates
;
private
String
auth
;
...
...
@@ -172,8 +173,7 @@ public class CodegenConfig {
public
CommonTemplateContentLocator
getCommonTemplateContentLocator
()
{
if
(
commonTemplateContentLocator
==
null
)
{
String
path
=
"templ"
;
if
(!
StringUtils
.
isEmpty
(
embedTemplate
))
path
=
Paths
.
get
(
"templ"
,
embedTemplate
).
toString
();
String
loc
=
TemplateManager
.
getCPResourcePath
(
path
);
URL
url
=
this
.
getClass
().
getClassLoader
().
getResource
(
loc
);
if
(
url
!=
null
)
{
...
...
@@ -197,15 +197,16 @@ public class CodegenConfig {
this
.
getTemplateDirs
().
forEach
(
templateDir
->{
list
.
add
(
new
GeneratorTemplateContentLocator
(
templateDir
));
});
if
(
getCommonTemplateContentLocator
()!=
null
)
{
list
.
add
(
commonTemplateContentLocator
);
}
this
.
templateProcessor
=
new
TemplateManager
(
new
TemplateManagerOptions
(
this
.
isEnableMinimalUpdate
(),
this
.
isSkipOverwrite
()),
templatingEngine
,
list
);
}
if
(
getCommonTemplateContentLocator
()!=
null
)
{
list
.
add
(
commonTemplateContentLocator
);
}
this
.
templateProcessor
=
new
TemplateManager
(
new
TemplateManagerOptions
(
this
.
isEnableMinimalUpdate
(),
this
.
isSkipOverwrite
()),
templatingEngine
,
list
);
}
return
templateProcessor
;
...
...
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/config/CodegenConfigurator.java
浏览文件 @
ff40a4b9
...
...
@@ -41,7 +41,8 @@ public final class CodegenConfigurator {
private
String
outputDir
;
private
List
<
String
>
filters
;
private
List
<
String
>
templateDirs
;
private
String
embedTemplate
;
private
List
<
EmbedTemplate
>
embedTemplates
;
private
List
<
Volume
>
volumes
;
private
List
<
String
>
templatePaths
;
private
List
<
String
>
templateFilters
;
private
String
auth
;
...
...
@@ -52,7 +53,6 @@ public final class CodegenConfigurator {
private
Map
<
String
,
Object
>
additionalProperties
=
new
HashMap
<>();
private
GeneratorSettings
generatorSettings
=
new
GeneratorSettings
();
public
CodegenConfigurator
()
{
...
...
@@ -60,24 +60,36 @@ public final class CodegenConfigurator {
}
@SuppressWarnings
(
"DuplicatedCode"
)
public
static
CodegenConfigurator
fromFile
(
String
configFile
,
Module
...
modules
)
{
public
static
List
<
CodegenConfigurator
>
fromFile
(
String
configFile
,
Module
...
modules
)
{
if
(
isNotEmpty
(
configFile
))
{
DynamicSettings
settings
=
readDynamicSettings
(
configFile
,
modules
);
CodegenConfigurator
configurator
=
new
CodegenConfigurator
();
GeneratorSettings
generatorSettings
=
settings
.
getGeneratorSettings
();
if
(
generatorSettings
.
getAdditionalProperties
()
!=
null
)
{
configurator
.
additionalProperties
.
putAll
(
generatorSettings
.
getAdditionalProperties
());
DynamicSettings
dynamicSettings
=
readDynamicSettings
(
configFile
,
modules
);
if
(!
ObjectUtils
.
isEmpty
(
dynamicSettings
))
{
List
<
CodegenConfigurator
>
list
=
new
ArrayList
<>();
dynamicSettings
.
values
().
forEach
(
settings
->{
CodegenConfigurator
configurator
=
new
CodegenConfigurator
();
configurator
.
setAuth
(
settings
.
getAuth
());
configurator
.
setOutputDir
(
settings
.
getOutput
());
configurator
.
setInputSpec
(
settings
.
getInputSpec
());
configurator
.
setFilters
(
settings
.
getInputSpecFilters
());
configurator
.
setTemplateDirs
(
settings
.
getTemplateDirs
());
configurator
.
setTemplatePaths
(
settings
.
getTemplatePaths
());
configurator
.
setTemplateFilters
(
settings
.
getInputSpecFilters
());
configurator
.
setEmbedTemplates
(
settings
.
getEmbedTemplates
());
configurator
.
setPackageName
(
settings
.
getPackageName
());
configurator
.
setVolumes
(
settings
.
getVolumes
());
configurator
.
setProjectName
(
settings
.
getProjectName
());
if
(
settings
.
getAdditionalProperties
()
!=
null
)
{
configurator
.
additionalProperties
.
putAll
(
settings
.
getAdditionalProperties
());
}
list
.
add
(
configurator
);
});
return
list
;
}
return
configurator
;
}
return
null
;
}
...
...
@@ -108,7 +120,6 @@ public final class CodegenConfigurator {
public
CodegenConfigurator
addAdditionalProperty
(
String
key
,
Object
value
)
{
this
.
additionalProperties
.
put
(
key
,
value
);
generatorSettings
.
getAdditionalProperties
().
put
(
key
,
value
);
return
this
;
}
...
...
@@ -121,7 +132,6 @@ public final class CodegenConfigurator {
public
CodegenConfigurator
setAdditionalProperties
(
Map
<
String
,
Object
>
additionalProperties
)
{
this
.
additionalProperties
=
additionalProperties
;
generatorSettings
.
setAdditionalProperties
(
additionalProperties
);
return
this
;
}
...
...
@@ -137,7 +147,6 @@ public final class CodegenConfigurator {
if
(
StringUtils
.
isNotEmpty
(
projectName
))
{
addAdditionalProperty
(
CodegenConstants
.
PROJECT_NAME
,
projectName
);
}
generatorSettings
.
setProjectName
(
projectName
);
return
this
;
}
...
...
@@ -146,62 +155,55 @@ public final class CodegenConfigurator {
if
(
StringUtils
.
isNotEmpty
(
packageName
))
{
addAdditionalProperty
(
CodegenConstants
.
PACKAGE_NAME
,
packageName
);
}
generatorSettings
.
setPackageName
(
packageName
);
return
this
;
}
public
CodegenConfigurator
setGitRepoId
(
String
gitRepoId
)
{
if
(
StringUtils
.
isNotEmpty
(
gitRepoId
))
{
addAdditionalProperty
(
CodegenConstants
.
GIT_REPO_ID
,
gitRepoId
);
public
CodegenConfigurator
setAuth
(
String
auth
)
{
// do not cache this in additional properties.
this
.
auth
=
auth
;
if
(
StringUtils
.
isNotEmpty
(
auth
))
{
addAdditionalProperty
(
"auth"
,
auth
);
}
generatorSettings
.
setGitRepoId
(
gitRepoId
);
return
this
;
}
public
CodegenConfigurator
setGitHost
(
String
gitHost
)
{
if
(
StringUtils
.
isNotEmpty
(
gitHost
))
{
addAdditionalProperty
(
CodegenConstants
.
GIT_HOST
,
gitHost
);
}
generatorSettings
.
setGitHost
(
gitHost
);
public
CodegenConfigurator
setInputSpec
(
String
inputSpec
)
{
this
.
inputSpec
=
inputSpec
;
return
this
;
}
public
CodegenConfigurator
setGitUserId
(
String
gitUserId
)
{
if
(
StringUtils
.
isNotEmpty
(
gitUserId
))
{
addAdditionalProperty
(
CodegenConstants
.
GIT_USER_ID
,
gitUserId
);
}
generatorSettings
.
setGitUserId
(
gitUserId
);
return
this
;
public
String
getInputSpec
()
{
return
this
.
inputSpec
;
}
public
String
getOutputDir
()
{
return
outputDir
;
}
public
CodegenConfigurator
setReleaseNote
(
String
releaseNote
)
{
if
(
StringUtils
.
isNotEmpty
(
releaseNote
))
{
addAdditionalProperty
(
CodegenConstants
.
RELEASE_NOTE
,
releaseNote
);
}
generatorSettings
.
setReleaseNote
(
releaseNote
);
return
this
;
public
List
<
String
>
getFilters
()
{
return
filters
;
}
public
CodegenConfigurator
setHttpUserAgent
(
String
httpUserAgent
)
{
if
(
StringUtils
.
isNotEmpty
(
httpUserAgent
))
{
addAdditionalProperty
(
CodegenConstants
.
HTTP_USER_AGENT
,
httpUserAgent
);
}
generatorSettings
.
setHttpUserAgent
(
httpUserAgent
);
return
this
;
public
List
<
String
>
getTemplateDirs
()
{
return
templateDirs
;
}
public
List
<
String
>
getTemplatePaths
()
{
return
templatePaths
;
}
public
List
<
String
>
getTemplateFilters
()
{
return
templateFilters
;
}
public
CodegenConfigurator
setAuth
(
String
auth
)
{
// do not cache this in additional properties.
this
.
auth
=
auth
;
return
this
;
public
String
getAuth
()
{
return
auth
;
}
public
CodegenConfigurator
setInputSpec
(
String
inputSpec
)
{
this
.
inputSpec
=
inputSpec
;
return
this
;
public
Map
<
String
,
Object
>
getAdditionalProperties
()
{
return
additionalProperties
;
}
public
CodegenConfigurator
setOutputDir
(
String
outputDir
)
{
...
...
@@ -214,11 +216,26 @@ public final class CodegenConfigurator {
return
this
;
}
public
CodegenConfigurator
setEmbedTemplate
(
String
embedTemplate
)
{
this
.
embedTemplate
=
embedTemplate
;
public
CodegenConfigurator
setEmbedTemplates
(
List
<
EmbedTemplate
>
embedTemplates
)
{
this
.
embedTemplates
=
embedTemplates
;
return
this
;
}
public
List
<
EmbedTemplate
>
getEmbedTemplates
()
{
return
embedTemplates
;
}
public
CodegenConfigurator
setVolumes
(
List
<
Volume
>
volumes
)
{
this
.
volumes
=
volumes
;
return
this
;
}
public
List
<
Volume
>
getVolumes
()
{
return
volumes
;
}
public
CodegenConfigurator
setTemplatePaths
(
List
<
String
>
templatePaths
)
{
this
.
templatePaths
=
templatePaths
;
return
this
;
...
...
@@ -264,8 +281,8 @@ public final class CodegenConfigurator {
config
.
setTemplateDirs
(
this
.
templateDirs
);
}
if
(!
StringUtils
.
isEmpty
(
embedTemplate
))
{
config
.
setEmbedTemplate
(
this
.
embedTemplate
);
if
(!
ObjectUtils
.
isEmpty
(
embedTemplates
))
{
config
.
setEmbedTemplate
s
(
this
.
embedTemplates
);
}
if
(!
ObjectUtils
.
isEmpty
(
templatePaths
))
{
...
...
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/config/Context.java
浏览文件 @
ff40a4b9
...
...
@@ -35,35 +35,4 @@ public class Context<TSpecDocument> {
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
Path
path
=
Paths
.
get
(
"/122/33/abc.java"
);
System
.
out
.
println
(
path
.
getParent
().
getFileName
());
System
.
out
.
println
(
TemplateFileType
.
entity
.
toString
());
System
.
out
.
println
(
TemplateFileType
.
entity
.
value
());
HashMap
<
String
,
Object
>
scopes
=
new
HashMap
<
String
,
Object
>();
scopes
.
put
(
"name"
,
"Mustache"
);
GeneratorSettings
generatorSettings
=
new
GeneratorSettings
().
setGitHost
(
"host"
);
generatorSettings
.
getAdditionalProperties
().
put
(
"sub"
,
new
GeneratorSettings
().
setGitHost
(
"son"
));
scopes
.
put
(
"feature"
,
generatorSettings
);
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"a"
);
list
.
add
(
"b"
);
scopes
.
put
(
"list"
,
list
);
Map
map
=
new
HashMap
();
map
.
put
(
"01"
,
"a01"
);
map
.
put
(
"02"
,
"a02"
);
scopes
.
put
(
"map1"
,
map
);
scopes
.
put
(
"opt"
,
new
PojoOption
().
set
(
"system_name"
,
"ab"
).
set
(
"persistent"
,
false
));
scopes
.
put
(
"type"
,
TemplateFileType
.
entity
);
Writer
writer
=
new
OutputStreamWriter
(
System
.
out
);
DefaultMustacheFactory
mf
=
new
DefaultMustacheFactory
();
mf
.
setObjectHandler
(
new
MapMethodReflectionHandler
());
Mustache
mustache
=
mf
.
compile
(
new
StringReader
(
"{{type}},{{type.value}},{{name}},{{opt.system}},{{opt.physicalField}}, {{map1.entrySet}}{{#map1.entrySet}}{{key}}{{/map1.entrySet}}!"
),
"example"
);
mustache
.
execute
(
writer
,
scopes
);
writer
.
flush
();
}
}
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/config/DynamicSettings.java
浏览文件 @
ff40a4b9
package
cn
.
ibizlab
.
codegen
.
config
;
import
com.fasterxml.jackson.annotation.JsonAnySetter
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonUnwrapped
;
import
com.fasterxml.jackson.annotation.*
;
import
com.fasterxml.jackson.databind.annotation.JsonDeserialize
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
java.lang.reflect.Field
;
import
java.util.*
;
public
class
DynamicSettings
{
@JsonAnySetter
private
Map
<
String
,
Object
>
dynamicProperties
=
new
HashMap
<>();
@Getter
@Setter
@NoArgsConstructor
@Accessors
(
chain
=
true
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
DynamicSettings
extends
LinkedHashMap
<
String
,
GeneratorSettings
>{
@JsonUnwrapped
@JsonDeserialize
(
builder
=
GeneratorSettings
.
Builder
.
class
)
private
GeneratorSettings
generatorSettings
;
public
GeneratorSettings
getGeneratorSettings
()
{
excludeSettingsFromDynamicProperties
();
GeneratorSettings
.
Builder
builder
=
GeneratorSettings
.
newBuilder
(
generatorSettings
);
// This allows us to put any unknown top-level properties into additionalProperties of the generator object.
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
dynamicProperties
.
entrySet
())
{
builder
.
withAdditionalProperty
(
entry
.
getKey
(),
entry
.
getValue
());
}
return
builder
.
build
();
}
/**
* <p>Constructor for DynamicSettings.</p>
*/
@JsonCreator
public
DynamicSettings
()
{
}
/**
* Gets all "custom" properties included in the config object.
*
* @return All user-specified custom properties.
*/
public
Map
<
String
,
Object
>
getDynamicProperties
()
{
return
dynamicProperties
;
}
private
void
excludeSettingsFromDynamicProperties
(){
Set
<
String
>
fieldNames
=
new
HashSet
<>();
for
(
Field
field
:
GeneratorSettings
.
class
.
getDeclaredFields
())
{
fieldNames
.
add
(
field
.
getName
());
}
dynamicProperties
.
keySet
().
removeAll
(
fieldNames
);
}
}
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/config/EmbedTemplate.java
0 → 100644
浏览文件 @
ff40a4b9
package
cn
.
ibizlab
.
codegen
.
config
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.springframework.util.ObjectUtils
;
@Getter
@Setter
@NoArgsConstructor
@Accessors
(
chain
=
true
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
EmbedTemplate
{
private
String
name
;
private
String
version
;
@JsonCreator
public
static
EmbedTemplate
from
(
String
tag
)
{
if
(
ObjectUtils
.
isEmpty
(
tag
))
return
null
;
EmbedTemplate
template
=
new
EmbedTemplate
();
String
tags
[]=
tag
.
split
(
":"
);
template
.
setName
(
tags
[
0
]);
if
(
tags
.
length
>
1
)
template
.
setVersion
(
tags
[
1
]);
else
template
.
setVersion
(
"1.0-SNAPSHOT"
);
return
template
;
}
}
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/config/GeneratorSettings.java
浏览文件 @
ff40a4b9
package
cn
.
ibizlab
.
codegen
.
config
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.*
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
...
...
@@ -14,221 +16,48 @@ import java.util.*;
@Setter
@NoArgsConstructor
@Accessors
(
chain
=
true
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
GeneratorSettings
implements
Serializable
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
GeneratorSettings
.
class
);
private
static
final
String
DEFAULT_GIT_HOST
=
"github.com"
;
private
static
final
String
DEFAULT_GIT_USER_ID
=
"GIT_USER_ID"
;
private
static
final
String
DEFAULT_GIT_REPO_ID
=
"GIT_REPO_ID"
;
private
static
final
String
DEFAULT_RELEASE_NOTE
=
"Minor update"
;
private
String
projectName
;
private
String
packageName
;
@JsonIgnore
private
Map
<
String
,
Object
>
additionalProperties
=
new
LinkedHashMap
<>();
private
String
gitHost
;
private
String
gitUserId
;
private
String
gitRepoId
;
private
String
releaseNote
;
private
String
httpUserAgent
;
private
String
output
;
private
Map
<
String
,
String
>
typeMappings
;
private
String
inputSpec
;
public
String
getHost
()
{
return
gitHost
+
"abc"
;
}
private
List
<
String
>
inputSpecFilters
;
private
List
<
String
>
templateDirs
;
private
GeneratorSettings
(
Builder
builder
)
{
projectName
=
builder
.
projectName
;
packageName
=
builder
.
packageName
;
typeMappings
=
Collections
.
unmodifiableMap
(
builder
.
typeMappings
);
gitHost
=
builder
.
gitHost
;
gitUserId
=
builder
.
gitUserId
;
gitRepoId
=
builder
.
gitRepoId
;
releaseNote
=
builder
.
releaseNote
;
httpUserAgent
=
builder
.
httpUserAgent
;
Map
<
String
,
Object
>
additional
=
new
HashMap
<>(
builder
.
additionalProperties
);
additionalProperties
=
Collections
.
unmodifiableMap
(
additional
);
}
private
List
<
String
>
templatePaths
;
private
List
<
String
>
templateFilters
;
private
List
<
Volume
>
volumes
;
private
String
auth
;
private
List
<
EmbedTemplate
>
embedTemplates
;
public
static
Builder
newBuilder
(
GeneratorSettings
copy
)
{
Builder
builder
=
new
Builder
();
builder
.
projectName
=
copy
.
projectName
;
builder
.
packageName
=
copy
.
packageName
;
builder
.
typeMappings
=
Collections
.
unmodifiableMap
(
copy
.
typeMappings
);
builder
.
gitHost
=
copy
.
gitHost
;
builder
.
gitUserId
=
copy
.
gitUserId
;
builder
.
gitRepoId
=
copy
.
gitRepoId
;
builder
.
releaseNote
=
copy
.
releaseNote
;
builder
.
httpUserAgent
=
copy
.
httpUserAgent
;
Map
<
String
,
Object
>
additional
=
new
HashMap
<>(
copy
.
additionalProperties
);
builder
.
additionalProperties
=
Collections
.
unmodifiableMap
(
additional
);
return
builder
;
@JsonAnyGetter
public
Map
<
String
,
Object
>
any
()
{
return
additionalProperties
;
}
public
static
final
class
Builder
{
private
String
projectName
;
private
String
packageName
;
private
String
gitHost
;
private
String
gitUserId
;
private
String
gitRepoId
;
private
String
releaseNote
;
private
String
httpUserAgent
;
private
Map
<
String
,
String
>
typeMappings
;
private
Map
<
String
,
Object
>
additionalProperties
;
/**
* Instantiates a new Builder.
*/
public
Builder
()
{
typeMappings
=
new
HashMap
<>();
additionalProperties
=
new
HashMap
<>();
gitHost
=
DEFAULT_GIT_HOST
;
gitUserId
=
DEFAULT_GIT_USER_ID
;
gitRepoId
=
DEFAULT_GIT_REPO_ID
;
releaseNote
=
DEFAULT_RELEASE_NOTE
;
}
public
Builder
withProjectName
(
String
projectName
)
{
this
.
projectName
=
projectName
;
return
this
;
}
/**
* Sets the {@code packageName} and returns a reference to this Builder so that the methods can be chained together.
*
* @param packageName the {@code packageName} to set
* @return a reference to this Builder
*/
public
Builder
withPackageName
(
String
packageName
)
{
this
.
packageName
=
packageName
;
return
this
;
}
/**
* Sets the {@code typeMappings} and returns a reference to this Builder so that the methods can be chained together.
*
* @param typeMappings the {@code typeMappings} to set
* @return a reference to this Builder
*/
public
Builder
withTypeMappings
(
Map
<
String
,
String
>
typeMappings
)
{
this
.
typeMappings
=
typeMappings
;
return
this
;
}
public
Builder
withTypeMapping
(
String
key
,
String
value
)
{
if
(
this
.
typeMappings
==
null
)
{
this
.
typeMappings
=
new
HashMap
<>();
}
this
.
typeMappings
.
put
(
key
,
value
);
return
this
;
}
/**
* Sets the {@code additionalProperties} and returns a reference to this Builder so that the methods can be chained together.
*
* @param additionalProperties the {@code additionalProperties} to set
* @return a reference to this Builder
*/
public
Builder
withAdditionalProperties
(
Map
<
String
,
Object
>
additionalProperties
)
{
this
.
additionalProperties
=
additionalProperties
;
return
this
;
}
/**
* Sets the {@code additionalProperties} and returns a reference to this Builder so that the methods can be chained together.
*
* @param key A key for some additional property
* @param value The value of some additional property
* @return a reference to this Builder
*/
public
Builder
withAdditionalProperty
(
String
key
,
Object
value
)
{
if
(
this
.
additionalProperties
==
null
)
{
this
.
additionalProperties
=
new
HashMap
<>();
}
this
.
additionalProperties
.
put
(
key
,
value
);
return
this
;
}
/**
* Sets the {@code gitHost} and returns a reference to this Builder so that the methods can be chained together.
*
* @param gitHost the {@code gitHost} to set
* @return a reference to this Builder
*/
public
Builder
withGitHost
(
String
gitHost
)
{
this
.
gitHost
=
gitHost
;
return
this
;
}
/**
* Sets the {@code gitUserId} and returns a reference to this Builder so that the methods can be chained together.
*
* @param gitUserId the {@code gitUserId} to set
* @return a reference to this Builder
*/
public
Builder
withGitUserId
(
String
gitUserId
)
{
this
.
gitUserId
=
gitUserId
;
return
this
;
}
/**
* Sets the {@code gitRepoId} and returns a reference to this Builder so that the methods can be chained together.
*
* @param gitRepoId the {@code gitRepoId} to set
* @return a reference to this Builder
*/
public
Builder
withGitRepoId
(
String
gitRepoId
)
{
this
.
gitRepoId
=
gitRepoId
;
return
this
;
}
/**
* Sets the {@code releaseNote} and returns a reference to this Builder so that the methods can be chained together.
*
* @param releaseNote the {@code releaseNote} to set
* @return a reference to this Builder
*/
public
Builder
withReleaseNote
(
String
releaseNote
)
{
this
.
releaseNote
=
releaseNote
;
return
this
;
}
/**
* Sets the {@code httpUserAgent} and returns a reference to this Builder so that the methods can be chained together.
*
* @param httpUserAgent the {@code httpUserAgent} to set
* @return a reference to this Builder
*/
public
Builder
withHttpUserAgent
(
String
httpUserAgent
)
{
this
.
httpUserAgent
=
httpUserAgent
;
return
this
;
}
/**
* Returns a {@code GeneratorSettings} built from the parameters previously set.
*
* @return a {@code GeneratorSettings} built with parameters of this {@code GeneratorSettings.Builder}
*/
public
GeneratorSettings
build
()
{
GeneratorSettings
instance
=
new
GeneratorSettings
(
this
);
//noinspection PlaceholderCountMatchesArgumentCount
LOGGER
.
debug
(
"GeneratorSettings#build: %s"
,
instance
.
toString
());
return
instance
;
}
@JsonAnySetter
public
void
set
(
String
field
,
Object
value
)
{
this
.
additionalProperties
.
put
(
field
,
value
);
}
}
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/config/Volume.java
0 → 100644
浏览文件 @
ff40a4b9
package
cn
.
ibizlab
.
codegen
.
config
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.springframework.util.ObjectUtils
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
@Getter
@Setter
@NoArgsConstructor
@Accessors
(
chain
=
true
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
Volume
{
private
String
source
;
private
String
target
;
public
void
setSource
(
String
source
)
{
this
.
source
=
source
.
replace
(
"\\"
,
"/"
);
}
public
void
setTarget
(
String
target
)
{
this
.
target
=
target
.
replace
(
"\\"
,
"/"
);
}
public
Path
getSourcePath
()
{
return
Paths
.
get
(
source
);
}
@JsonCreator
public
static
Volume
from
(
String
tag
)
{
if
(
ObjectUtils
.
isEmpty
(
tag
))
return
null
;
Volume
volume
=
new
Volume
();
String
tags
[]=
tag
.
split
(
":"
);
volume
.
setSource
(
tags
[
0
]);
if
(
tags
.
length
>
1
)
volume
.
setTarget
(
tags
[
1
]);
else
volume
.
setTarget
(
tags
[
0
]);
return
volume
;
}
}
modules/ibizlab-generator-core/src/main/java/cn/ibizlab/codegen/model/ModelStorage.java
浏览文件 @
ff40a4b9
...
...
@@ -9,6 +9,7 @@ import cn.ibizlab.codegen.utils.StringAdvUtils;
import
net.ibizsys.model.IPSSystem
;
import
net.ibizsys.model.PSModelServiceImpl
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.nio.file.Files
;
...
...
@@ -86,6 +87,8 @@ public class ModelStorage {
opt
.
setProjectDesc
(
systemModel
.
getProjectDesc
());
opt
.
setPackageName
(
systemModel
.
getPackageName
());
opt
.
set
(
"system"
,
systemModel
);
if
(!
ObjectUtils
.
isEmpty
(
config
.
getEmbedTemplates
()))
opt
.
set
(
"embedTemplates"
,
config
.
getEmbedTemplates
());
return
opt
;
}
...
...
modules/ibizlab-generator-core/src/main/resources/templ/.gitignore.hbs
已删除
100644 → 0
浏览文件 @
ac294684
*volumes
*target
.settings
*node_modules
*bin
*.project
*.classpath
*.factorypath
.history
.vscode
.idea
**.iml
*.jar
*.log
.DS_Store
modules/ibizlab-generator-core/src/main/resources/templ/.ibizlab-generator-ignore
浏览文件 @
ff40a4b9
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
modules/ibizlab-generator-core/src/main/resources/templ/
pom
.xml.hbs
→
modules/ibizlab-generator-core/src/main/resources/templ/
generator
.xml.hbs
浏览文件 @
ff40a4b9
...
...
@@ -103,6 +103,17 @@
${project.artifactId}
</name>
</configuration>
{{#if
embedTemplates
}}
<dependencies>
{{#
each
embedTemplates
}}
<dependency>
<groupId>
cn.ibizlab
</groupId>
<artifactId>
{{
name
}}
</artifactId>
<version>
{{
version
}}
</version>
</dependency>
{{/
each
}}
</dependencies>
{{/if}}
</plugin>
</plugins>
</build>
...
...
modules/ibizlab-generator-plugin/src/main/java/cn/ibizlab/codegen/GenerateMojo.java
浏览文件 @
ff40a4b9
...
...
@@ -2,6 +2,7 @@ package cn.ibizlab.codegen;
import
cn.ibizlab.codegen.config.CodegenConfigurator
;
import
cn.ibizlab.codegen.config.CodegenConfiguratorUtils
;
import
cn.ibizlab.codegen.config.EmbedTemplate
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.maven.plugin.AbstractMojo
;
...
...
@@ -41,8 +42,6 @@ public class GenerateMojo extends AbstractMojo {
@Parameter
private
String
[]
templateDirs
;
@Parameter
private
String
embedTemplate
;
@Parameter
private
String
[]
templatePaths
;
...
...
@@ -57,8 +56,6 @@ public class GenerateMojo extends AbstractMojo {
@Parameter
private
String
[]
globalProperties
;
@Parameter
private
String
configFile
;
@Parameter
private
String
name
;
...
...
@@ -74,20 +71,6 @@ public class GenerateMojo extends AbstractMojo {
@Parameter
private
String
gitHost
;
@Parameter
private
String
gitUserId
;
@Parameter
private
String
gitRepoId
;
@Parameter
private
String
releaseNote
;
@Parameter
private
String
httpUserAgent
;
/**
...
...
@@ -136,10 +119,6 @@ public class GenerateMojo extends AbstractMojo {
configurator
.
setTemplateDirs
(
Arrays
.
asList
(
templateDirs
));
}
if
(!
StringUtils
.
isEmpty
(
embedTemplate
))
{
configurator
.
setEmbedTemplate
(
this
.
embedTemplate
);
}
if
(!
ObjectUtils
.
isEmpty
(
templatePaths
))
{
configurator
.
setTemplatePaths
(
Arrays
.
asList
(
templatePaths
));
}
...
...
@@ -161,26 +140,6 @@ public class GenerateMojo extends AbstractMojo {
}
if
(
isNotEmpty
(
gitHost
))
{
configurator
.
setGitHost
(
gitHost
);
}
if
(
isNotEmpty
(
gitUserId
))
{
configurator
.
setGitUserId
(
gitUserId
);
}
if
(
isNotEmpty
(
gitRepoId
))
{
configurator
.
setGitRepoId
(
gitRepoId
);
}
if
(
isNotEmpty
(
releaseNote
))
{
configurator
.
setReleaseNote
(
releaseNote
);
}
if
(
isNotEmpty
(
httpUserAgent
))
{
configurator
.
setHttpUserAgent
(
httpUserAgent
);
}
if
(!
ObjectUtils
.
isEmpty
(
globalProperties
))
{
...
...
modules/ibizlab-template/ibizlab-template-apiclient/src/main/resources/templ/.ibizlab-generator-ignore
浏览文件 @
ff40a4b9
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
modules/ibizlab-template/ibizlab-template-apiclient/src/main/resources/templ/{{projectName}}-apiclient-{{apis}}/src/main/resources/templ/.ibizlab-generator-ignore
浏览文件 @
ff40a4b9
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
modules/ibizlab-template/ibizlab-template-doc/src/main/resources/templ/.ibizlab-generator-ignore
浏览文件 @
ff40a4b9
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
modules/ibizlab-template/ibizlab-template-ibizboot/src/main/resources/templ/.ibizlab-generator-ignore
浏览文件 @
ff40a4b9
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
modules/ibizlab-template/ibizlab-template-ibizboot/src/main/resources/templ/{{projectName}}-provider/src/main/resources/templ/.ibizlab-generator-ignore
浏览文件 @
ff40a4b9
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
modules/ibizlab-template/ibizlab-template-ibizedge/src/main/resources/templ/.ibizlab-generator-ignore
浏览文件 @
ff40a4b9
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
modules/ibizlab-template/ibizlab-template-ibizedge/src/main/resources/templ/{{projectName}}-boot/src/main/resources/templ/.ibizlab-generator-ignore
浏览文件 @
ff40a4b9
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
modules/ibizlab-template/ibizlab-template-r7/src/main/resources/templ/.ibizlab-generator-ignore
浏览文件 @
ff40a4b9
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
modules/ibizlab-template/ibizlab-template-r7/src/main/resources/templ/{{projectName}}-boot/src/main/resources/templ/.ibizlab-generator-ignore
浏览文件 @
ff40a4b9
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
modules/ibizlab-template/ibizlab-template-r8/src/main/resources/templ/.ibizlab-generator-ignore
浏览文件 @
ff40a4b9
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
modules/ibizlab-template/ibizlab-template-r8/src/main/resources/templ/{{projectName}}-provider/src/main/resources/templ/.ibizlab-generator-ignore
浏览文件 @
ff40a4b9
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录