Skip to content

Commit

Permalink
icerockdev#530 generator update, replaced resource dir, remove MR pac…
Browse files Browse the repository at this point in the history
…kage
  • Loading branch information
ExNDY committed Jul 31, 2023
1 parent 506c5ef commit d2407b7
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion resources-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

plugins {
id("org.jetbrains.kotlin.jvm") version ("1.8.10")
id("org.jetbrains.kotlin.jvm") version ("1.8.21")
id("detekt-convention")
id("publication-convention")
id("com.gradle.plugin-publish") version ("1.2.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import dev.icerock.gradle.utils.getDependedFrom
import dev.icerock.gradle.utils.isDependsOn
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.SourceSet
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.getByType
Expand All @@ -41,10 +43,14 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
import org.jetbrains.kotlin.konan.target.HostManager
import java.io.File
import javax.inject.Inject
import javax.xml.parsers.DocumentBuilderFactory

@Suppress("TooManyFunctions")
class MultiplatformResourcesPlugin : Plugin<Project> {
abstract class MultiplatformResourcesPlugin : Plugin<Project> {
@Inject
protected abstract fun getObjectFactory(): ObjectFactory

override fun apply(target: Project) {
val mrExtension: MultiplatformResourcesPluginExtension = target.extensions.create(
"multiplatformResources",
Expand Down Expand Up @@ -72,10 +78,12 @@ class MultiplatformResourcesPlugin : Plugin<Project> {
mrExtension: MultiplatformResourcesPluginExtension,
multiplatformExtension: KotlinMultiplatformExtension
) {
val commonSourceSet = multiplatformExtension.sourceSets.getByName(mrExtension.sourceSetName)
val commonResources = commonSourceSet.resources
val commonSourceSet: KotlinSourceSet = multiplatformExtension.sourceSets.getByName(mrExtension.sourceSetName)
val commonResources: SourceDirectorySet = getObjectFactory()
.sourceDirectorySet("moko-resources", "moko-resources")
commonResources.srcDir("${target.projectDir}/src/${commonSourceSet.name}/moko-resources")

val generatedDir = File(target.buildDir, "generated/moko")
val generatedDir = File(target.buildDir, "generated/moko-resources")
val mrClassPackage: String = requireNotNull(mrExtension.multiplatformResourcesPackage) {
buildString {
appendLine("multiplatformResources.multiplatformResourcesPackage is required!")
Expand All @@ -88,9 +96,9 @@ class MultiplatformResourcesPlugin : Plugin<Project> {
visibility = mrExtension.multiplatformResourcesVisibility
)
val sourceInfo = SourceInfo(
generatedDir,
commonResources,
mrExtension.multiplatformResourcesPackage!!
generatedDir = generatedDir,
commonResources = commonResources,
mrClassPackage = mrExtension.multiplatformResourcesPackage!!
)

val strictLineBreaks: Boolean = target
Expand Down Expand Up @@ -223,6 +231,7 @@ class MultiplatformResourcesPlugin : Plugin<Project> {
target: Project
): GenerateMultiplatformResourcesTask {
val commonGeneratorSourceSet: MRGenerator.SourceSet = createSourceSet(commonSourceSet)

return CommonMRGenerator(
generatedDir,
commonGeneratorSourceSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class AssetsGenerator(
override val resourceClassName = ClassName("dev.icerock.moko.resources", "AssetResource")

private fun getBaseDir(file: File): String {
val relativePathToAssets = file.path.substringAfterLast(RES_ROOT)
val relativePathToAssets = file.path.substringAfterLast(ASSETS_DIR_NAME)
val fixedRelativePath = File(relativePathToAssets).path

val result: String = if (fixedRelativePath.startsWith(File.separatorChar)) {
Expand Down Expand Up @@ -74,7 +74,7 @@ abstract class AssetsGenerator(
): List<AssetSpec> {
val contentOfRootDir = mutableListOf<File>()
resFolders.forEach {
val assets = File(it, RES_ROOT)
val assets = File(it, ASSETS_DIR_NAME)

val content = assets.listFiles()
if (content != null) {
Expand Down Expand Up @@ -203,7 +203,5 @@ abstract class AssetsGenerator(
don't support it like apple.
*/
const val PATH_DELIMITER = '+'

private val RES_ROOT = "MR${File.separatorChar}$ASSETS_DIR_NAME"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ abstract class ColorsGenerator(
) : ResourceGeneratorFeature<ColorsGenerator> {

private val colorsFileTree =
info.commonResources.matching { it.include("MR/**/colors*.xml") }
info.commonResources.matching { it.include("colors/colors*.xml") }

override fun createCommonGenerator() = CommonColorsGenerator(colorsFileTree)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ abstract class FilesGenerator(
) : ResourceGeneratorFeature<FilesGenerator> {

private val fileTree = info.commonResources.matching {
it.include("MR/files/**")
it.include("files/**")
}

override fun createCommonGenerator() = CommonFilesGenerator(fileTree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ abstract class FontsGenerator(
private val mrSettings: MRGenerator.MRSettings
) : ResourceGeneratorFeature<FontsGenerator> {
private val stringsFileTree = info.commonResources.matching {
it.include("MR/fonts/**.ttf", "MR/fonts/**.otf")
it.include("fonts/**.ttf", "fonts/**.otf")
}

override fun createCommonGenerator() = CommonFontsGenerator(stringsFileTree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ abstract class ImagesGenerator(
private val logger: Logger
) : ResourceGeneratorFeature<ImagesGenerator> {
private val stringsFileTree = info.commonResources.matching {
it.include("MR/images/**/*.png", "MR/images/**/*.jpg", "MR/images/**/*.svg")
it.include("images/**/*.png", "images/**/*.jpg", "images/**/*.svg")
}

override fun createCommonGenerator() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ abstract class PluralsGenerator(
private val mrSettings: MRGenerator.MRSettings
) : ResourceGeneratorFeature<PluralsGenerator> {
private val stringsFileTree =
info.commonResources.matching { it.include("MR/**/plurals*.xml") }
info.commonResources.matching { it.include("**/plurals*.xml") }

override fun createCommonGenerator(): PluralsGenerator =
CommonPluralsGenerator(stringsFileTree, strictLineBreaks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ abstract class StringsGenerator(
private val mrSettings: MRGenerator.MRSettings
) : ResourceGeneratorFeature<StringsGenerator> {
private val stringsFileTree =
info.commonResources.matching { it.include("MR/**/strings*.xml") }
info.commonResources.matching { it.include("**/strings*.xml") }

override fun createCommonGenerator() =
CommonStringsGenerator(stringsFileTree, strictLineBreaks)
Expand Down

0 comments on commit d2407b7

Please sign in to comment.