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 {
|
||||
id("com.android.library")
|
||||
kotlin("android")
|
||||
@ -42,46 +39,20 @@ dependencies {
|
||||
}
|
||||
|
||||
tasks {
|
||||
val generateExtensions by registering {
|
||||
doLast {
|
||||
val isWindows = System.getProperty("os.name").toString().toLowerCase().contains("win")
|
||||
var classPath = (
|
||||
configurations.compileOnly.get().asFileTree.toList() +
|
||||
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 ":")
|
||||
register<JavaExec>("generateExtensions") {
|
||||
classpath = configurations.compileOnly.get() +
|
||||
configurations.androidApis.get() + // android.jar path
|
||||
files("$buildDir/intermediates/aar_main_jar/debug/classes.jar") // jar made from this module
|
||||
mainClass.set("generator.GeneratorMainKt")
|
||||
|
||||
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) {
|
||||
classPath = classPath.replace("/", "\\")
|
||||
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")
|
||||
}
|
||||
if (!logger.isInfoEnabled) {
|
||||
standardOutput = org.gradle.internal.io.NullOutputStream.INSTANCE
|
||||
}
|
||||
|
||||
dependsOn("ktLint", "assembleDebug")
|
||||
}
|
||||
|
||||
|
@ -132,9 +132,9 @@ interface ThemeSourceGenerator {
|
||||
File(projectRootPath).let { projectRootFile ->
|
||||
println("Generating $source")
|
||||
|
||||
projectRootFile.mkdirs()
|
||||
// remove everything from past runs
|
||||
cleanDirectory(projectRootFile)
|
||||
projectRootFile.deleteRecursively()
|
||||
projectRootFile.mkdirs()
|
||||
|
||||
writeGradle(projectGradleFile, source, themePkg, baseVersionCode, defaultAdditionalGradlePath, additionalGradleOverridePath)
|
||||
writeAndroidManifest(projectAndroidManifestFile, manifestOverridePath, defaultAndroidManifestPath)
|
||||
@ -232,15 +232,6 @@ interface ThemeSourceGenerator {
|
||||
""".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