Skip to content

Commit

Permalink
moveDir任务兼容aidl文件夹 #54
Browse files Browse the repository at this point in the history
  • Loading branch information
liujingxing committed Sep 23, 2023
1 parent 1d5f2dc commit cc7d13e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ android {

buildFeatures {
dataBinding = true
aidl = true
}
}

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/aidl/com/ljx/example/IMyAidlInterface.aidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// IMyAidlInterface.aidl
package com.ljx.example;

// Declare any non-default types here with import statements

interface IMyAidlInterface {
/**
* Demonstrates some basic types that you can use as parameters
* and return values in AIDL.
*/
void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
double aDouble, String aString);
}
5 changes: 4 additions & 1 deletion app/src/main/java/com/ljx/example/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package com.ljx.example.activity
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.ljx.example.R
import com.ljx.example.IMyAidlInterface
import com.ljx.example.KtTopTest1
import com.ljx.example.R
import com.ljx.example.i
import com.ljx.example.j
import com.ljx.example.k
Expand All @@ -13,6 +14,8 @@ import com.ljx.example.m
import com.ljx.example.toB

class MainActivity : AppCompatActivity() {

val list = mutableListOf<IMyAidlInterface>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand Down
8 changes: 7 additions & 1 deletion plugin/src/main/java/com/xml/guard/tasks/MoveDirTask.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.xml.guard.tasks

import com.xml.guard.entensions.GuardExtension
import com.xml.guard.utils.aidlDirs
import com.xml.guard.utils.allDependencyAndroidProjects
import com.xml.guard.utils.findPackage
import com.xml.guard.utils.findXmlDirs
Expand Down Expand Up @@ -41,16 +42,21 @@ open class MoveDirTask @Inject constructor(
//1、替换manifest文件 、layout、navigation、xml目录下的文件、Java、Kt文件
val dirs = findXmlDirs(variantName, "layout", "navigation", "xml")
dirs.add(manifestFile())
val aidlDirs = aidlDirs(variantName)
dirs.addAll(aidlDirs)
val javaDirs = javaDirs(variantName)
dirs.addAll(javaDirs)
val moveDirs = mutableListOf<File>()
moveDirs.addAll(aidlDirs)
moveDirs.addAll(javaDirs)
files(dirs).asFileTree.forEach {
it.replaceText(moveFile, manifestPackage)
}

// 2、开始移动目录
moveFile.forEach { (oldPath, newPath) ->
val oldPackagePath = oldPath.replace(".", File.separator)
for (javaDir in javaDirs) {
for (javaDir in moveDirs) {
val oldDir = File(javaDir, oldPackagePath)
if (!oldDir.exists()) {
continue
Expand Down
18 changes: 18 additions & 0 deletions plugin/src/main/java/com/xml/guard/utils/ProjectExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ fun Project.javaDirs(variantName: String): List<File> {
return javaDirs
}

fun Project.aidlDirs(variantName: String): List<File> {
val sourceSet = (extensions.getByName("android") as BaseExtension).sourceSets
val nameSet = mutableSetOf<String>()
nameSet.add("main")
if (isAndroidProject()) {
nameSet.addAll(variantName.splitWords())
}
val javaDirs = mutableListOf<File>()
sourceSet.names.forEach { name ->
if (nameSet.contains(name)) {
sourceSet.getByName(name).aidl.srcDirs.mapNotNullTo(javaDirs) {
if (it.exists()) it else null
}
}
}
return javaDirs
}

fun Project.findLayoutDirs(variantName: String) = findXmlDirs(variantName, "layout")
fun Project.findXmlDirs(variantName: String, vararg dirName: String): ArrayList<File> {
return resDirs(variantName).flatMapTo(ArrayList()) { dir ->
Expand Down

0 comments on commit cc7d13e

Please sign in to comment.