Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dankal-simple-code-util
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
仲光辉
dankal-simple-code-util
Commits
959eeaef
Commit
959eeaef
authored
Nov 10, 2020
by
仲光辉
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修正记录:
- 修正代码提高可读性 - 提供对于忽略相关文件的支持(便于模板的即改即用) at 2020-11-10 10:29 ZGH.MercyModest
parent
f2142f8a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
13 deletions
+92
-13
README.md
README.md
+7
-1
CodeGenerator.java
src/main/java/cn/dankal/code/util/CodeGenerator.java
+4
-4
CodeUtil.java
src/main/java/cn/dankal/code/util/common/CodeUtil.java
+81
-8
No files found.
README.md
View file @
959eeaef
...
@@ -8,5 +8,10 @@
...
@@ -8,5 +8,10 @@
> - projectDescription : 项目描述
> - projectDescription : 项目描述
> - templateProjectPath : 模板代码路径
> - templateProjectPath : 模板代码路径
> - projectCreatePath : 项目生成路径
> - projectCreatePath : 项目生成路径
> - isOverride : 项目名称已经存在的行为
> - isOverride : 项目名称已经存在的行为: 报错/删除覆盖
### 执行 `CodeGenerator#mian` 方法
### 执行 `CodeGenerator#mian` 方法
## 关于如何实现文件的直接拷贝/文件的忽略
!
[
](https://img.mercymodest.com/public/20201110102731.png)
\ No newline at end of file
src/main/java/cn/dankal/code/util/CodeGenerator.java
View file @
959eeaef
...
@@ -17,22 +17,22 @@ public class CodeGenerator {
...
@@ -17,22 +17,22 @@ public class CodeGenerator {
// 项目参数: 必须全部非空
// 项目参数: 必须全部非空
// 项目名称
// 项目名称
final
String
projectName
=
"
tudgo-global-permissoon
"
;
final
String
projectName
=
"
dankal-code-util-test
"
;
// 项目基础包名 etc. com.tudgo.global.permission
// 项目基础包名 etc. com.tudgo.global.permission
final
String
basePackageName
=
"c
om.tudgo.global.permission
"
;
final
String
basePackageName
=
"c
n.dankal.code
"
;
// 项目描述 etc.土地工权限管理系统
// 项目描述 etc.土地工权限管理系统
final
String
projectDescription
=
"土地工权限管理系统"
;
final
String
projectDescription
=
"土地工权限管理系统"
;
// 模板项目路径 : C:\dev\test 目前只支持一套模板[dankal-microservice-code-template-v1]
// 模板项目路径 : C:\dev\test 目前只支持一套模板[dankal-microservice-code-template-v1]
final
String
templateProjectPath
=
"C:/
dev/tes
t/dankal-microservice-code-template-v1"
;
final
String
templateProjectPath
=
"C:/
IDEAProjec
t/dankal-microservice-code-template-v1"
;
// 项目生成路径 C:\dev\test
// 项目生成路径 C:\dev\test
final
String
projectCreatePath
=
"C:/dev/test"
;
final
String
projectCreatePath
=
"C:/dev/test"
;
// 如果 项目目录已经存在( projectCreatePath/projectName ) 是否覆盖
// 如果 项目目录已经存在( projectCreatePath/projectName ) 是否覆盖
final
boolean
isOverride
=
fals
e
;
final
boolean
isOverride
=
tru
e
;
//构建项目信息对象
//构建项目信息对象
ProjectInfo
projectInfo
=
CodeUtil
.
builderProjectInfo
(
projectName
,
basePackageName
,
projectDescription
,
templateProjectPath
,
projectCreatePath
,
isOverride
);
ProjectInfo
projectInfo
=
CodeUtil
.
builderProjectInfo
(
projectName
,
basePackageName
,
projectDescription
,
templateProjectPath
,
projectCreatePath
,
isOverride
);
...
...
src/main/java/cn/dankal/code/util/common/CodeUtil.java
View file @
959eeaef
...
@@ -23,18 +23,30 @@ import java.util.List;
...
@@ -23,18 +23,30 @@ import java.util.List;
public
class
CodeUtil
{
public
class
CodeUtil
{
/**
/**
*
需要忽略不需要读取的文件(直接复制)
*
直接复制的文件 --> 文件名
*/
*/
public
static
final
List
<
String
>
IGNORE
_FILE_NAME_LIST
;
public
static
final
List
<
String
>
DIRECT_COPY
_FILE_NAME_LIST
;
/**
/**
*
需要忽略的文件后缀:直接复制
*
直接复制文件 --> 文件拓展名
*/
*/
public
static
final
List
<
String
>
IGNORE_FILE_SUFFIX
;
public
static
final
List
<
String
>
DIRECT_COPY_FILE_EXTENSION
;
/**
* 需要忽略的文件夹,不拷贝 (文件名称)
*/
public
static
final
List
<
String
>
IGNORE_FOLDER_NAME_LIST
;
/**
* 需要忽略的文件 不拷贝 (文件拓展名)
*/
public
static
final
List
<
String
>
IGNORE_FILE_EXTENSION_LIST
;
static
{
static
{
// 工具集合初始化
// 工具集合初始化
IGNORE_FILE_NAME_LIST
=
CollectionUtil
.
newArrayList
(
".gitignore"
);
DIRECT_COPY_FILE_NAME_LIST
=
CollectionUtil
.
newArrayList
(
".gitignore"
);
IGNORE_FILE_SUFFIX
=
CollectionUtil
.
newArrayList
(
".yml"
);
DIRECT_COPY_FILE_EXTENSION
=
CollectionUtil
.
newArrayList
(
""
);
IGNORE_FOLDER_NAME_LIST
=
CollectionUtil
.
newArrayList
(
".idea"
,
".git"
,
"target"
);
IGNORE_FILE_EXTENSION_LIST
=
CollectionUtil
.
newArrayList
(
".iml"
);
}
}
...
@@ -117,12 +129,20 @@ public class CodeUtil {
...
@@ -117,12 +129,20 @@ public class CodeUtil {
}
}
for
(
File
file
:
rootTemplateFileList
)
{
for
(
File
file
:
rootTemplateFileList
)
{
if
(
file
.
isDirectory
())
{
if
(
file
.
isDirectory
())
{
if
(
isIgnore
(
file
))
{
// 需要忽略当前文夹
continue
;
}
// 二级目录
// 二级目录
CodeUtil
.
operateChildFolder
(
file
,
projectInfo
);
CodeUtil
.
operateChildFolder
(
file
,
projectInfo
);
continue
;
continue
;
}
}
if
(
isIgnore
(
file
))
{
// 需要忽略当前文件
continue
;
}
// 根目录下的文件
// 根目录下的文件
boolean
isDirectCopy
=
CodeUtil
.
IGNORE_FILE_NAME_LIST
.
contains
(
file
.
getName
())
||
CodeUtil
.
IGNORE_FILE_SUFFIX
.
contains
(
"."
+
FileUtil
.
extName
(
file
));
boolean
isDirectCopy
=
CodeUtil
.
DIRECT_COPY_FILE_NAME_LIST
.
contains
(
file
.
getName
())
||
CodeUtil
.
DIRECT_COPY_FILE_EXTENSION
.
contains
(
"."
+
FileUtil
.
extName
(
file
));
if
(
isDirectCopy
)
{
if
(
isDirectCopy
)
{
// 直接执行文件拷贝
// 直接执行文件拷贝
String
fileCanonicalPath
=
file
.
getCanonicalPath
();
String
fileCanonicalPath
=
file
.
getCanonicalPath
();
...
@@ -297,6 +317,9 @@ public class CodeUtil {
...
@@ -297,6 +317,9 @@ public class CodeUtil {
}
}
for
(
File
file
:
childProjectRootFileList
)
{
for
(
File
file
:
childProjectRootFileList
)
{
if
(
file
.
isDirectory
())
{
if
(
file
.
isDirectory
())
{
if
(
isIgnore
(
file
))
{
continue
;
}
// 文件夹
// 文件夹
String
fileName
=
file
.
getName
();
String
fileName
=
file
.
getName
();
final
String
testStr
=
"test"
;
final
String
testStr
=
"test"
;
...
@@ -307,8 +330,10 @@ public class CodeUtil {
...
@@ -307,8 +330,10 @@ public class CodeUtil {
// 非 test 文件夹迭代处理
// 非 test 文件夹迭代处理
operateChildFolder
(
file
,
projectInfo
);
operateChildFolder
(
file
,
projectInfo
);
}
}
}
else
{
}
else
{
if
(
isIgnore
(
file
))
{
continue
;
}
// 文件
// 文件
doFileCopy
(
file
,
projectInfo
);
doFileCopy
(
file
,
projectInfo
);
}
}
...
@@ -330,4 +355,52 @@ public class CodeUtil {
...
@@ -330,4 +355,52 @@ public class CodeUtil {
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
}
}
/**
* 是否需要忽略对当前 file 的拷贝
*
* @param file File
* @return 如果需要忽略将返回 true
*/
public
static
boolean
isIgnore
(
File
file
)
{
if
(
file
==
null
)
{
return
true
;
}
boolean
isDirectory
=
file
.
isDirectory
();
if
(
isDirectory
)
{
// 查看是否是需要忽略的文件夹
// 文件夹 --> 校验文件名称
String
fileName
=
file
.
getName
();
return
IGNORE_FOLDER_NAME_LIST
.
contains
(
fileName
);
}
// 查看是否需要忽略文件
String
extName
=
FileUtil
.
extName
(
file
);
extName
=
"."
+
extName
;
return
IGNORE_FILE_EXTENSION_LIST
.
contains
(
extName
);
}
/**
* 是否需要忽略当前文件路径对应的文件夹
*
* @param filePath filePath
* @return 如果需要忽略将返回 true
*/
public
static
boolean
isIgnore
(
String
filePath
)
{
if
(
StrUtil
.
isBlank
(
filePath
))
{
return
true
;
}
boolean
isDirectory
=
FileUtil
.
isDirectory
(
filePath
);
if
(
isDirectory
)
{
// 查看是否是需要忽略的文件夹
// 文件夹 --> 校验文件名称
String
fileName
=
FileUtil
.
getName
(
filePath
);
return
IGNORE_FOLDER_NAME_LIST
.
contains
(
fileName
);
}
// 查看是否需要忽略文件
String
extName
=
FileUtil
.
extName
(
filePath
);
extName
=
"."
+
extName
;
return
IGNORE_FILE_EXTENSION_LIST
.
contains
(
extName
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment