|
@@ -1,7 +1,10 @@
|
|
|
package io.nexilis
|
|
|
|
|
|
+import org.gradle.BuildListener
|
|
|
+import org.gradle.BuildResult
|
|
|
import org.gradle.api.Plugin
|
|
|
import org.gradle.api.initialization.Settings
|
|
|
+import org.gradle.api.invocation.Gradle
|
|
|
import org.w3c.dom.Document
|
|
|
import org.w3c.dom.Element
|
|
|
import org.xml.sax.SAXException
|
|
@@ -29,40 +32,60 @@ import kotlin.io.path.nameWithoutExtension
|
|
|
const val libNameSpace = "com.example.dm"
|
|
|
|
|
|
class SettingsPlugin: Plugin<Settings> {
|
|
|
- override fun apply(settings: Settings) {
|
|
|
+ override fun apply(target: Settings) {
|
|
|
println(">>>>>>>>>>> Settings")
|
|
|
- settings.gradle.settingsEvaluated {
|
|
|
- println(">>>>>>>>>>> settingsEvaluated")
|
|
|
- try {
|
|
|
- val moduleDir = File(settings.rootDir, "dynamic_core")
|
|
|
+ target.gradle.addBuildListener(object: BuildListener {
|
|
|
+ override fun settingsEvaluated(settings: Settings) {
|
|
|
+ println(">>>>>>>>>>> addBuildListener:settingsEvaluated")
|
|
|
+ try {
|
|
|
+ val moduleDir = File(target.rootDir, "dynamic_core")
|
|
|
+ if (moduleDir.exists()) {
|
|
|
+ moduleDir.deleteRecursively()
|
|
|
+ println(">>>>>>>>>>> delete:dir:${moduleDir.toPath()}")
|
|
|
+ }
|
|
|
+ if (!moduleDir.exists()) {
|
|
|
+ println(">>>>>>>>>>> create:dir:${moduleDir.toPath()}")
|
|
|
+ moduleDir.mkdirs()
|
|
|
+ }
|
|
|
+ val projectApp = target.project(File(target.rootDir, "app"))
|
|
|
+ println(">>>>>>>>>>> copy:from:${projectApp.projectDir.toPath()}")
|
|
|
+ projectApp.projectDir.toPath().copy(moduleDir.toPath())
|
|
|
+ println(">>>>>>>>>>> copy:done")
|
|
|
+ moduleDir.toPath().refactor()
|
|
|
+ println(">>>>>>>>>>> refactor:done")
|
|
|
+ target.include(":dynamic_core")
|
|
|
+ println(">>>>>>>>>>> include module:dynamic_core")
|
|
|
+ val tmpBaseDir = File(projectApp.projectDir, "src/custom/java/io/nexilis/app")
|
|
|
+ println(">>>>>>>>>>> create:base:dir:${tmpBaseDir.toPath()}")
|
|
|
+ if (!tmpBaseDir.exists()) {
|
|
|
+ tmpBaseDir.mkdirs()
|
|
|
+ }
|
|
|
+ val activity = Paths.get(tmpBaseDir.toPath().toString(), "NexilisActivity.java")
|
|
|
+ Files.writeString(activity, mainActivity)
|
|
|
+ println(">>>>>>>>>>> create:activity:$activity")
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun projectsLoaded(gradle: Gradle) {
|
|
|
+ println(">>>>>>>>>>> addBuildListener:projectsLoaded")
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun projectsEvaluated(gradle: Gradle) {
|
|
|
+ println(">>>>>>>>>>> addBuildListener:projectsEvaluated")
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun buildFinished(result: BuildResult) {
|
|
|
+ println(">>>>>>>>>>> addBuildListener:buildFinished")
|
|
|
+ val moduleDir = File(target.rootDir, "dynamic_core")
|
|
|
if (moduleDir.exists()) {
|
|
|
moduleDir.deleteRecursively()
|
|
|
println(">>>>>>>>>>> delete:dir:${moduleDir.toPath()}")
|
|
|
}
|
|
|
- if (!moduleDir.exists()) {
|
|
|
- println(">>>>>>>>>>> create:dir:${moduleDir.toPath()}")
|
|
|
- moduleDir.mkdirs()
|
|
|
- }
|
|
|
- val projectApp = settings.project(File(settings.rootDir, "app"))
|
|
|
- println(">>>>>>>>>>> copy:from:${projectApp.projectDir.toPath()}")
|
|
|
- projectApp.projectDir.toPath().copy(moduleDir.toPath())
|
|
|
- println(">>>>>>>>>>> copy:done")
|
|
|
- moduleDir.toPath().refactor()
|
|
|
- println(">>>>>>>>>>> refactor:done")
|
|
|
- settings.include(":dynamic_core")
|
|
|
- println(">>>>>>>>>>> include module:dynamic_core")
|
|
|
- val tmpBaseDir = File(projectApp.projectDir, "src/custom/java/io/nexilis/app")
|
|
|
- println(">>>>>>>>>>> create:base:dir:${tmpBaseDir.toPath()}")
|
|
|
- if (!tmpBaseDir.exists()) {
|
|
|
- tmpBaseDir.mkdirs()
|
|
|
- }
|
|
|
- val activity = Paths.get(tmpBaseDir.toPath().toString(), "NexilisActivity.java")
|
|
|
- Files.writeString(activity, mainActivity)
|
|
|
- println(">>>>>>>>>>> create:activity:$activity")
|
|
|
- } catch (e: Exception) {
|
|
|
- e.printStackTrace()
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -127,14 +150,17 @@ fun Path.copy(target: Path) {
|
|
|
var updatedContent = """plugins\s*\{[^}]*}""".toRegex()
|
|
|
.replace(
|
|
|
Files.readString(file).trimIndent(),
|
|
|
- "plugins {\n id 'com.android.dynamic-feature'\n}\n"
|
|
|
+ "plugins {\n" +
|
|
|
+ " id 'com.android.dynamic-feature'\n" +
|
|
|
+ " id 'org.jetbrains.kotlin.android' version '1.9.24'" +
|
|
|
+ "\n}\n"
|
|
|
)
|
|
|
// updatedContent = """namespace\s+(['"])[^'"]+"\s*""".toRegex()
|
|
|
// .replace(updatedContent, "'$libNameSpace'")
|
|
|
// updatedContent = """applicationId\s+(['"])[^'"]+"\s*""".toRegex()
|
|
|
// .replace(updatedContent, "")
|
|
|
- updatedContent = """kotlinOptions\s*\{\s*jvmTarget\s*=\s*"11"\s*\}""".toRegex()
|
|
|
- .replace(updatedContent, "")
|
|
|
+// updatedContent = """kotlinOptions\s*\{\s*jvmTarget\s*=\s*"11"\s*\}""".toRegex()
|
|
|
+// .replace(updatedContent, "")
|
|
|
Files.writeString(targetPath, updatedContent)
|
|
|
}
|
|
|
if (file.fileName.name == "AndroidManifest.xml") {
|