Skip to content

Commit

Permalink
#535 fix apple targets for colors and image generators
Browse files Browse the repository at this point in the history
  • Loading branch information
ExNDY committed Dec 21, 2023
1 parent ec6de52 commit 3239efc
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ abstract class ColorsGenerator(
generatedProperties.add(generatedProperty)
}

generateResources(project, resourcesGenerationDir, allColors)
generateResources(
project = project,
assetsGenerationDir = assetsGenerationDir,
resourcesGenerationDir = resourcesGenerationDir,
colors = allColors
)

extendObjectBodyAtEnd(objectBuilder)

return if (generatedProperties.isNotEmpty()) {
Expand Down Expand Up @@ -154,6 +160,7 @@ abstract class ColorsGenerator(

protected open fun generateResources(
project: Project,
assetsGenerationDir: File,
resourcesGenerationDir: File,
colors: List<ColorNode>,
) = Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ abstract class FontsGenerator(
beforeGenerateResources(objectBuilder, allFontFiles)

val typeSpec = createTypeSpec(
project = project,
inputMetadata = inputMetadata,
generatedObjects = generatedObjects,
targetObject = targetObject,
Expand Down Expand Up @@ -123,7 +122,6 @@ abstract class FontsGenerator(
@param keys: names of files like anastasia-regular.ttf
*/
private fun createTypeSpec(
project: Project,
inputMetadata: MutableList<GeneratedObject>,
generatedObjects: MutableList<GeneratedObject>,
targetObject: GeneratedObject,
Expand Down Expand Up @@ -161,7 +159,6 @@ abstract class FontsGenerator(

var generatedProperty = GeneratedProperty(
modifier = addObjectActualOverrideModifier(
project = project,
propertyName = propertyName,
property = property,
inputMetadata = inputMetadata,
Expand Down Expand Up @@ -216,7 +213,6 @@ abstract class FontsGenerator(
}

private fun addObjectActualOverrideModifier(
project: Project,
propertyName: String,
property: TypeSpec.Builder,
inputMetadata: List<GeneratedObject>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ abstract class ImagesGenerator(
)

generateResources(
assetsGenerationDir = assetsGenerationDir,
resourcesGenerationDir = resourcesGenerationDir,
keyFileMap = allImagesMap.mapKeys { (key, _) ->
key.substringBeforeLast(".") // Remove file extension from keys
Expand Down Expand Up @@ -233,14 +234,13 @@ abstract class ImagesGenerator(
protected open fun beforeGenerateResources(
objectBuilder: TypeSpec.Builder,
keys: List<String>,
) {
}
) = Unit

protected open fun generateResources(
assetsGenerationDir: File,
resourcesGenerationDir: File,
keyFileMap: Map<String, List<File>>,
) {
}
) = Unit

abstract fun getClassModifiers(): Array<KModifier>

Expand All @@ -254,12 +254,10 @@ abstract class ImagesGenerator(
) : ResourceGeneratorFeature<ImagesGenerator> {
override fun createCommonGenerator(): ImagesGenerator = CommonImagesGenerator(
ownInputFileTree = settings.ownResourcesFileTree,
upperInputFileTree = settings.upperResourcesFileTree
)

override fun createAppleGenerator(): ImagesGenerator = AppleImagesGenerator(
ownInputFileTree = settings.ownResourcesFileTree,
lowerInputFileTree = settings.lowerResourcesFileTree,
)

override fun createAndroidGenerator(): ImagesGenerator = AndroidImagesGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AndroidColorsGenerator(

override fun generateResources(
project: Project,
assetsGenerationDir: File,
resourcesGenerationDir: File,
colors: List<ColorNode>
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class AndroidImagesGenerator(
)

override fun generateResources(
assetsGenerationDir: File,
resourcesGenerationDir: File,
keyFileMap: Map<String, List<File>>
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ class AppleColorsGenerator(

override fun generateResources(
project: Project,
assetsGenerationDir: File,
resourcesGenerationDir: File,
colors: List<ColorNode>
) {
val assetsDirectory = File(resourcesGenerationDir, ASSETS_DIR_NAME)
val assetsDirectory = File(assetsGenerationDir, ASSETS_DIR_NAME)

colors.forEach { colorNode ->
val assetDir = File(assetsDirectory, "${colorNode.name}.colorset")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import java.io.File

class AppleImagesGenerator(
ownInputFileTree: FileTree,
lowerInputFileTree: FileTree,
) : ImagesGenerator(resourcesFileTree = ownInputFileTree), ObjectBodyExtendable by AppleGeneratorHelper() {

override fun getClassModifiers(): Array<KModifier> = arrayOf(KModifier.ACTUAL)
Expand All @@ -35,10 +34,11 @@ class AppleImagesGenerator(
}

override fun generateResources(
assetsGenerationDir: File,
resourcesGenerationDir: File,
keyFileMap: Map<String, List<File>>
) {
val assetsDirectory = File(resourcesGenerationDir, ASSETS_DIR_NAME)
val assetsDirectory = File(assetsGenerationDir, ASSETS_DIR_NAME)

keyFileMap.forEach { (key, files) ->
val assetDir = File(assetsDirectory, "$key.imageset")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package dev.icerock.gradle.generator.apple.action
import dev.icerock.gradle.generator.apple.LoadableBundle
import dev.icerock.gradle.utils.unzipTo
import org.gradle.api.Action
import org.gradle.api.GradleException
import org.gradle.api.Task
import org.gradle.api.provider.Provider
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
Expand Down Expand Up @@ -67,6 +68,7 @@ internal class PackResourcesToKLibAction(
task.logger.error("can't compile assets - $result")
task.logger.info(input)
task.logger.error(errors)
throw GradleException("Assets compilation failed: $errors")
} else {
task.logger.info("assets compiled")
assetsDirectory.deleteRecursively()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.gradle.api.file.FileTree

class CommonImagesGenerator(
ownInputFileTree: FileTree,
upperInputFileTree: FileTree,
) : ImagesGenerator(ownInputFileTree), ObjectBodyExtendable by NOPObjectBodyExtendable() {
override fun getClassModifiers(): Array<KModifier> = emptyArray()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class JsImagesGenerator(
}

override fun generateResources(
assetsGenerationDir: File,
resourcesGenerationDir: File,
keyFileMap: Map<String, List<File>>
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class JvmImagesGenerator(
)

override fun generateResources(
assetsGenerationDir: File,
resourcesGenerationDir: File,
keyFileMap: Map<String, List<File>>
) {
Expand Down

0 comments on commit 3239efc

Please sign in to comment.