Fix wrong indentation in multisrc generated files (#13092)

* Fix wrong indentation in generated files.

* Lint the file.
This commit is contained in:
Alessandro Jean 2022-08-19 20:52:20 -03:00 committed by GitHub
parent a9aa05581a
commit 6fb71ea1a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 57 additions and 54 deletions

View File

@ -59,35 +59,40 @@ interface ThemeSourceGenerator {
val placeholders = mapOf( val placeholders = mapOf(
"SOURCEHOST" to source.baseUrl.toHttpUrlOrNull()?.host, "SOURCEHOST" to source.baseUrl.toHttpUrlOrNull()?.host,
"SOURCESCHEME" to source.baseUrl.toHttpUrlOrNull()?.scheme "SOURCESCHEME" to source.baseUrl.toHttpUrlOrNull()?.scheme
).filter { it.value != null } )
val placeholdersStr = placeholders
.filter { it.value != null }
.map { "${" ".repeat(12)}${it.key}: \"${it.value}\"" }
.joinToString(",\n")
gradle.writeText( gradle.writeText(
""" """
// THIS FILE IS AUTO-GENERATED; DO NOT EDIT |// THIS FILE IS AUTO-GENERATED; DO NOT EDIT
apply plugin: 'com.android.application' |apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' |apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization' |apply plugin: 'kotlinx-serialization'
|
ext { |ext {
extName = '${source.name}' | extName = '${source.name}'
pkgNameSuffix = '${pkgNameSuffix(source, ".")}' | pkgNameSuffix = '${pkgNameSuffix(source, ".")}'
extClass = '.${source.className}' | extClass = '.${source.className}'
extFactory = '$themePkg' | extFactory = '$themePkg'
extVersionCode = ${baseVersionCode + source.overrideVersionCode + multisrcLibraryVersion} | extVersionCode = ${baseVersionCode + source.overrideVersionCode + multisrcLibraryVersion}
${if (source.isNsfw) "isNsfw = true\n" else ""} | ${if (source.isNsfw) "isNsfw = true\n" else ""}
} |}
$defaultAdditionalGradleText |$defaultAdditionalGradleText
$additionalGradleOverrideText |$additionalGradleOverrideText
apply from: "${'$'}rootDir/common.gradle" |apply from: "${'$'}rootDir/common.gradle"
|
android { |android {
defaultConfig { | defaultConfig {
manifestPlaceholders += [ | manifestPlaceholders += [
${placeholders.map { "${" ".repeat(28)}${it.key}: \"${it.value}\""}.joinToString(",\n")} |$placeholdersStr
] | ]
} | }
} |}
""".trimIndent() """.trimMargin()
) )
} }
@ -101,10 +106,10 @@ ${placeholders.map { "${" ".repeat(28)}${it.key}: \"${it.value}\""}.joinToString
} else { } else {
androidManifestFile.writeText( androidManifestFile.writeText(
""" """
<?xml version="1.0" encoding="utf-8"?> |<?xml version="1.0" encoding="utf-8"?>
<!-- THIS FILE IS AUTO-GENERATED; DO NOT EDIT --> |<!-- THIS FILE IS AUTO-GENERATED; DO NOT EDIT -->
<manifest package="eu.kanade.tachiyomi.extension" /> |<manifest package="eu.kanade.tachiyomi.extension" />
""".trimIndent() """.trimMargin()
) )
} }
} }
@ -144,17 +149,15 @@ ${placeholders.map { "${" ".repeat(28)}${it.key}: \"${it.value}\""}.joinToString
private fun copyThemeReadmes(userDir: String, themePkg: String, overridesPath: String, projectRootPath: String) { private fun copyThemeReadmes(userDir: String, themePkg: String, overridesPath: String, projectRootPath: String) {
val sourcePath = "$userDir/multisrc/src/main/java/${themeSuffix(themePkg, "/")}" val sourcePath = "$userDir/multisrc/src/main/java/${themeSuffix(themePkg, "/")}"
val destinationPath = "$projectRootPath" File(projectRootPath).mkdirs()
File(destinationPath).mkdirs()
listOf(sourcePath, overridesPath).forEach { path -> listOf(sourcePath, overridesPath).forEach { path ->
File(path) File(path).list()
?.list()
?.filter { it.endsWith("README.md") || it.endsWith("CHANGELOG.md") } ?.filter { it.endsWith("README.md") || it.endsWith("CHANGELOG.md") }
?.forEach { ?.forEach {
Files.copy( Files.copy(
File("$path/$it").toPath(), File("$path/$it").toPath(),
File("$destinationPath/$it").toPath(), File("$projectRootPath/$it").toPath(),
StandardCopyOption.REPLACE_EXISTING StandardCopyOption.REPLACE_EXISTING
) )
} }
@ -167,8 +170,7 @@ ${placeholders.map { "${" ".repeat(28)}${it.key}: \"${it.value}\""}.joinToString
val themeDestPath = "$projectRootPath/src/${themeSuffix(themePkg, "/")}" val themeDestPath = "$projectRootPath/src/${themeSuffix(themePkg, "/")}"
File(themeDestPath).mkdirs() File(themeDestPath).mkdirs()
File(themeSrcPath) File(themeSrcPath).list()
?.list()
?.filter { it.endsWith(".kt") && !it.endsWith("Generator.kt") } ?.filter { it.endsWith(".kt") && !it.endsWith("Generator.kt") }
?.forEach { Files.copy(File("$themeSrcPath/$it").toPath(), File("$themeDestPath/$it").toPath(), StandardCopyOption.REPLACE_EXISTING) } ?.forEach { Files.copy(File("$themeSrcPath/$it").toPath(), File("$themeDestPath/$it").toPath(), StandardCopyOption.REPLACE_EXISTING) }
} }
@ -207,25 +209,26 @@ ${placeholders.map { "${" ".repeat(28)}${it.key}: \"${it.value}\""}.joinToString
} }
""" """
class ${source.className} : SourceFactory { |class ${source.className} : SourceFactory {
override fun createSources() = listOf( | override fun createSources() = listOf(
${sourceClasses.joinToString(",\n")} | ${sourceClasses.joinToString(",\n")}
) | )
} |}
""".trimIndent() """.trimMargin()
} }
} }
File("$classPath/${source.className}.kt").writeText( File("$classPath/${source.className}.kt").writeText(
"""/* ktlint-disable */ """
// THIS FILE IS AUTO-GENERATED; DO NOT EDIT |/* ktlint-disable */
package eu.kanade.tachiyomi.extension.${pkgNameSuffix(source, ".")} |// THIS FILE IS AUTO-GENERATED; DO NOT EDIT
|package eu.kanade.tachiyomi.extension.${pkgNameSuffix(source, ".")}
import eu.kanade.tachiyomi.multisrc.$themePkg.$themeClass |
${if (source is ThemeSourceData.MultiLang) "import eu.kanade.tachiyomi.source.SourceFactory" else ""} |import eu.kanade.tachiyomi.multisrc.$themePkg.$themeClass
|${if (source is ThemeSourceData.MultiLang) "import eu.kanade.tachiyomi.source.SourceFactory" else ""}
${factoryClassText()} |
""".trimIndent() |${factoryClassText()}
""".trimMargin()
) )
} }
@ -271,7 +274,7 @@ sealed class ThemeSourceData {
val lang: String, val lang: String,
override val isNsfw: Boolean = false, override val isNsfw: Boolean = false,
override val className: String = name.replace(" ", ""), override val className: String = name.replace(" ", ""),
override val pkgName: String = className.toLowerCase(Locale.ENGLISH), override val pkgName: String = className.lowercase(Locale.ENGLISH),
override val sourceName: String = name, override val sourceName: String = name,
override val overrideVersionCode: Int = 0, override val overrideVersionCode: Int = 0,
) : ThemeSourceData() ) : ThemeSourceData()
@ -282,7 +285,7 @@ sealed class ThemeSourceData {
val langs: List<String>, val langs: List<String>,
override val isNsfw: Boolean = false, override val isNsfw: Boolean = false,
override val className: String = name.replace(" ", "") + "Factory", override val className: String = name.replace(" ", "") + "Factory",
override val pkgName: String = className.substringBefore("Factory").toLowerCase(Locale.ENGLISH), override val pkgName: String = className.substringBefore("Factory").lowercase(Locale.ENGLISH),
override val sourceName: String = name, override val sourceName: String = name,
override val overrideVersionCode: Int = 0, override val overrideVersionCode: Int = 0,
) : ThemeSourceData() ) : ThemeSourceData()