Commit 94a818fc authored by pengjunjing's avatar pengjunjing

feat:增加过滤的目录,增加引用方式代码

parent 197f0d6c
## 应当项目中️以模块的形式导入,然后修改部分Java代码,以Java的形式运行即可
# 安卓项目辅助工具
## 工具列表
## 在项目中️以模块的形式导入,然后修改部分Java代码,以Java的形式运行即可
# 原理:
1. 遍历指定目录,读取出所有的切图文件,例如png jpg webp.......
......
......@@ -11,6 +11,10 @@ import java.util.ArrayList
*/
class ParseUtil {
//引用的代码,xml引用,java kt代码引用,布局文件
private val refCode =
listOf<String>("@drawable", "@mipmap", "R.drawable", "R.mipmap", "R.raw", "R.layout", "@layout", "@color","R.anim","@anim")
/**
* 返回引用了图片资源的该行文本内容
*/
......@@ -20,18 +24,12 @@ class ParseUtil {
val result = mutableListOf<String>()
for (readLine in readLines) {
//判断该行是否引用了图片资源
if (readLine.contains("@drawable") //xml引用
|| readLine.contains("@mipmap")
|| readLine.contains("R.drawable")//java kt代码引用
|| readLine.contains("R.mipmap")
|| readLine.contains("R.raw")
|| readLine.contains("R.layout")//布局文件
|| readLine.contains("@layout")
|| readLine.contains("@color")
) {
for (s in refCode) {
if (readLine.contains(s)) {
result.add(readLine)
}
}
}
return result
}
......
......@@ -36,7 +36,7 @@ class ReadUtil {
return codeResult
}
private val excludeXml = arrayOf("values", "AndroidManifest")
private val excludeXml = arrayOf("values", "AndroidManifest","res/xml","res\\xml")
/**
* 读取xml图片文件
......
......@@ -8,7 +8,7 @@ import java.io.File
const val realDelFile = false
/**
* 未使用资源删除工具
* 未使用资源删除工具,多运行几次,直到结果数量连续几次为0个
*/
fun main(args: Array<String>) {
println("开始读取文件")
......@@ -17,9 +17,9 @@ fun main(args: Array<String>) {
//这里打印的应该会是as项目所处的路径
println(projectRoot.absolutePath)
//要检查资源的目录
val baseFile = File("${projectRoot.absolutePath}${File.separator}laihuaBase${File.separator}src${File.separator}")
// val baseFile = File("${projectRoot.absolutePath}${File.separator}laihuaBase${File.separator}src${File.separator}")
//从项目根目录开始查找
// val baseFile = File("${projectRoot.absolutePath}")
val baseFile = File("${projectRoot.absolutePath}")
println(baseFile.absolutePath + "\n")
val readImageRes = ReadUtil().readImageRes(baseFile)
val readCodeFile = ReadUtil().readCodeFile(projectRootF)
......
......@@ -31,14 +31,16 @@ fun main(args: Array<String>) {
//从项目根目录开始查找
// val baseFile = File("${projectRoot.absolutePath}")
println(baseFile.absolutePath + "\n")
val readImageRes = ReadUtil().readImageRes(baseFile)
//图片文件和xml资源分别执行
// val readImageRes = ReadUtil().readImageRes(baseFile)
val readImageRes = ReadUtil().readXmlFile(baseFile)
val readCodeFile = ReadUtil().readCodeFile(projectRootF)
//查找单个依赖的文件
val singleList: List<FileCalc> = startFind(readImageRes, readCodeFile)
//这个单模块依赖的意思,包含本模块依赖的文件
println("一共有:${singleList.size}个文件是单模块依赖的,都需要进行移动")
println("一共有:${singleList.size}个文件是单模块依赖的")
val shellCmd = getShellCmd(singleList, projectPath)
println("------------------------------")
/**
......@@ -66,6 +68,7 @@ fun main(args: Array<String>) {
*/
private fun getShellCmd(singleList: List<FileCalc>, projectPath: String): List<String> {
val cmdList = mutableListOf<String>()
var fileCount = 0
for (fileCalc in singleList) {
val implementModuleName = fileCalc.implementModule.toList()[0]
if (fileCalc.belongModule != null && implementModuleName.lowercase() != fileCalc.belongModule.lowercase()) {
......@@ -87,8 +90,10 @@ private fun getShellCmd(singleList: List<FileCalc>, projectPath: String): List<S
val cmd = "git mv .$form .$to"
cmdList.add(cmd)
}
fileCount++
}
}
println("\n\n需要移动的文件一共${fileCount}个\n\n")
return cmdList
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment