Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
R
RemoveUnusedImg
Project
Project
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
pengjunjing
RemoveUnusedImg
Commits
b35a9f8c
Commit
b35a9f8c
authored
Dec 12, 2024
by
pengjunjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:增加修改gradle的脚本
parent
660e6a0c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
0 deletions
+94
-0
InsertNameSpace.kt
src/main/java/com/laihua/projecthelper/InsertNameSpace.kt
+78
-0
ReadUtil.kt
src/main/java/com/laihua/projecthelper/unuse/ReadUtil.kt
+16
-0
No files found.
src/main/java/com/laihua/projecthelper/InsertNameSpace.kt
0 → 100644
View file @
b35a9f8c
package
com.laihua.projecthelper
import
com.laihua.projecthelper.unuse.ReadUtil
import
java.io.File
/**
* Author: pengjunjing
* Date: 2024/12/11
* Description: 快速增加命名空间的脚本
*/
fun
main
()
{
println
(
"开始读取文件"
)
val
projectRoot
=
File
(
""
)
val
projectRootF
=
File
(
projectRoot
.
absolutePath
)
//这里打印的应该会是as项目所处的路径
println
(
projectRoot
.
absolutePath
)
//要检查资源的目录
// val baseFile = File("${projectRoot.absolutePath}${File.separator}laihuaBase${File.separator}src${File.separator}")
//从项目根目录开始查找
val
baseFile
=
File
(
"${projectRoot.absolutePath}"
)
println
(
baseFile
.
absolutePath
+
"\n"
)
val
readGradleList
=
ReadUtil
().
readGradleFile
(
baseFile
)
for
(
file
:
File
in
readGradleList
)
{
val
pathGradle
=
file
.
absolutePath
if
((
pathGradle
.
contains
(
"mod_video"
)
||
pathGradle
.
contains
(
"mod_kt"
)
||
pathGradle
.
contains
(
"mod_design"
)
||
pathGradle
.
contains
(
"mod_common"
))
)
{
val
readText
=
file
.
readText
()
var
newText
=
""
if
(!
readText
.
contains
(
"namespace"
))
{
val
nameSpace
=
getNameSpace
(
file
)
println
(
"没有定义命名空间:${file.parent} 包名是:$nameSpace"
)
for
(
line
in
readText
.
lines
())
{
newText
+=
line
newText
+=
"\n"
if
(
line
.
contains
(
"android {"
))
{
newText
+=
" namespace '${nameSpace}'\n"
}
}
println
(
"新结果:\n${newText.trim()}"
)
//写入结果
// file.writeText(newText.trim())
}
}
}
for
(
file
:
File
in
readGradleList
)
{
val
pathGradle
=
file
.
absolutePath
if
((
pathGradle
.
contains
(
"mod_video"
)
||
pathGradle
.
contains
(
"mod_kt"
)
||
pathGradle
.
contains
(
"mod_design"
)
||
pathGradle
.
contains
(
"mod_common"
))
)
{
val
readText
=
file
.
readText
()
println
(
"去除前后空格:\n${readText.trim()}"
)
//写入结果
file
.
writeText
(
readText
.
trim
())
}
}
}
//获取 AndroidManifest的包名
fun
getNameSpace
(
file
:
File
):
String
{
val
module
:
String
=
file
.
parent
val
androidManifest
=
File
(
"$module/src/main/AndroidManifest.xml"
)
val
readText
=
androidManifest
.
readText
()
val
split
=
readText
.
split
(
"package="
)
val
s
=
split
[
1
]
val
substring
=
s
.
substring
(
1
)
val
substring1
=
substring
.
substring
(
0
,
substring
.
indexOf
(
"\""
))
return
substring1
}
src/main/java/com/laihua/projecthelper/unuse/ReadUtil.kt
View file @
b35a9f8c
...
@@ -36,6 +36,22 @@ class ReadUtil {
...
@@ -36,6 +36,22 @@ class ReadUtil {
return
codeResult
return
codeResult
}
}
/**
* 读取gradle文件
*/
fun
readGradleFile
(
file
:
File
):
MutableList
<
File
>
{
val
codeResult
=
mutableListOf
<
File
>()
codeResult
.
clear
()
if
(
file
.
exists
()
&&
file
.
isDirectory
)
{
readChildFile
(
file
,
".gradle"
,
resultList
=
codeResult
)
}
else
{
println
(
"资源目录不存在或者传入的不是目录:${file.absolutePath}"
)
}
return
codeResult
}
val
valuesDirName
=
"values"
val
valuesDirName
=
"values"
private
val
excludeXml
=
arrayOf
(
"values"
,
"AndroidManifest"
,
"res/xml"
,
"res\\xml"
)
private
val
excludeXml
=
arrayOf
(
"values"
,
"AndroidManifest"
,
"res/xml"
,
"res\\xml"
)
...
...
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