Clean up multisrc generate task (#17023)
This commit is contained in:
parent
b8a8e04537
commit
99b3cb4ce3
@ -1,6 +1,3 @@
|
|||||||
import java.io.BufferedReader
|
|
||||||
import java.io.InputStreamReader
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.library")
|
id("com.android.library")
|
||||||
kotlin("android")
|
kotlin("android")
|
||||||
@ -42,46 +39,20 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
val generateExtensions by registering {
|
register<JavaExec>("generateExtensions") {
|
||||||
doLast {
|
classpath = configurations.compileOnly.get() +
|
||||||
val isWindows = System.getProperty("os.name").toString().toLowerCase().contains("win")
|
configurations.androidApis.get() + // android.jar path
|
||||||
var classPath = (
|
files("$buildDir/intermediates/aar_main_jar/debug/classes.jar") // jar made from this module
|
||||||
configurations.compileOnly.get().asFileTree.toList() +
|
mainClass.set("generator.GeneratorMainKt")
|
||||||
listOf(
|
|
||||||
configurations.androidApis.get().asFileTree.first().absolutePath, // android.jar path
|
|
||||||
"$projectDir/build/intermediates/aar_main_jar/debug/classes.jar" // jar made from this module
|
|
||||||
))
|
|
||||||
.joinToString(if (isWindows) ";" else ":")
|
|
||||||
|
|
||||||
var javaPath = "${System.getProperty("java.home")}/bin/java"
|
workingDir = workingDir.parentFile // project root
|
||||||
|
|
||||||
val mainClass = "generator.GeneratorMainKt" // Main class we want to execute
|
errorOutput = System.out // for GitHub workflow commands
|
||||||
|
|
||||||
if (isWindows) {
|
if (!logger.isInfoEnabled) {
|
||||||
classPath = classPath.replace("/", "\\")
|
standardOutput = org.gradle.internal.io.NullOutputStream.INSTANCE
|
||||||
javaPath = javaPath.replace("/", "\\")
|
|
||||||
}
|
|
||||||
|
|
||||||
val javaProcess = ProcessBuilder()
|
|
||||||
.directory(null).command(javaPath, "-classpath", classPath, mainClass)
|
|
||||||
.redirectErrorStream(true).start()
|
|
||||||
|
|
||||||
val inputStreamReader = InputStreamReader(javaProcess.inputStream)
|
|
||||||
val bufferedReader = BufferedReader(inputStreamReader)
|
|
||||||
|
|
||||||
var s: String?
|
|
||||||
while (bufferedReader.readLine().also { s = it } != null) {
|
|
||||||
logger.info(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
bufferedReader.close()
|
|
||||||
inputStreamReader.close()
|
|
||||||
|
|
||||||
val exitCode = javaProcess.waitFor()
|
|
||||||
if (exitCode != 0) {
|
|
||||||
throw Exception("Java process failed with exit code: $exitCode")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependsOn("ktLint", "assembleDebug")
|
dependsOn("ktLint", "assembleDebug")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +132,9 @@ interface ThemeSourceGenerator {
|
|||||||
File(projectRootPath).let { projectRootFile ->
|
File(projectRootPath).let { projectRootFile ->
|
||||||
println("Generating $source")
|
println("Generating $source")
|
||||||
|
|
||||||
projectRootFile.mkdirs()
|
|
||||||
// remove everything from past runs
|
// remove everything from past runs
|
||||||
cleanDirectory(projectRootFile)
|
projectRootFile.deleteRecursively()
|
||||||
|
projectRootFile.mkdirs()
|
||||||
|
|
||||||
writeGradle(projectGradleFile, source, themePkg, baseVersionCode, defaultAdditionalGradlePath, additionalGradleOverridePath)
|
writeGradle(projectGradleFile, source, themePkg, baseVersionCode, defaultAdditionalGradlePath, additionalGradleOverridePath)
|
||||||
writeAndroidManifest(projectAndroidManifestFile, manifestOverridePath, defaultAndroidManifestPath)
|
writeAndroidManifest(projectAndroidManifestFile, manifestOverridePath, defaultAndroidManifestPath)
|
||||||
@ -232,15 +232,6 @@ interface ThemeSourceGenerator {
|
|||||||
""".trimMargin(),
|
""".trimMargin(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanDirectory(dir: File) {
|
|
||||||
dir.listFiles()?.forEach {
|
|
||||||
if (it.isDirectory) {
|
|
||||||
cleanDirectory(it)
|
|
||||||
}
|
|
||||||
it.delete()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user