diff --git a/TODO.md b/TODO.md index 29f30b6..3c41dc8 100644 --- a/TODO.md +++ b/TODO.md @@ -15,3 +15,7 @@ Capture: Flags: - ways to disable class count and resource count (--no-class-count on task) +Generation +- Fetch resource artifact from AGP to reference resources from other modules +- Two-pass resource generation so menu resources can be generated with code references +- Implement random raw resource generation. Also implement random java resource generation and asset generation. \ No newline at end of file diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/FieldModel.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/FieldModel.kt index 230fe6d..30d2398 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/FieldModel.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/FieldModel.kt @@ -16,8 +16,6 @@ */ package com.android.gradle.replicator.codegen -import kotlin.reflect.KClass - data class FieldModel( val name: String, override val classModel: ClassModel<*>, diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/GeneratorDriver.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/GeneratorDriver.kt index 7aaa1ac..9ec2b91 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/GeneratorDriver.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/GeneratorDriver.kt @@ -16,6 +16,7 @@ */ package com.android.gradle.replicator.codegen +import com.android.gradle.replicator.resourceModel.ResourceModel import java.io.File import java.lang.reflect.Modifier import java.net.URLClassLoader @@ -39,20 +40,25 @@ class GeneratorDriver( /** * Generate a single class * + * @param moduleName the root package for the module (where the R class is located). * @param packageName the package name for the class to generate. * @param className the class name to generate. * @param printStream the [PrettyPrintStream] to use to generate the code. * @param listeners optional list of code generation listeners to further customize generated code. */ override fun generateClass( + moduleName: String, packageName: String, className: String, printStream: PrettyPrintStream, - listeners: List) { + listeners: List, + resourceModel: ResourceModel) { SingleClassGenerator( generator = generatorAllocator(printStream, listeners), + moduleName = moduleName, packageName = packageName, className = className, + resourceModel = resourceModel, random = random, apiClassPicker = apiImportClassPicker, implClassPicker = implementationImportClassPicker, diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/ImportClassPicker.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/ImportClassPicker.kt index e91f9a4..28b07af 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/ImportClassPicker.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/ImportClassPicker.kt @@ -89,6 +89,16 @@ open class ImportClassPicker( return classModel } + /** + * find a specific class in the class loader by name. + * + * @param className the name of the class. + * @return the class or null if it could not be found. + */ + fun getClassByName(className: String): ClassModel<*>? { + return isClassEligible(loadClass(className)) + } + /** * Loads a class from the classloader. * diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/Main.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/Main.kt index bf67fe6..1534ada 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/Main.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/Main.kt @@ -16,9 +16,19 @@ */ package com.android.gradle.replicator.codegen +import com.android.gradle.replicator.model.AndroidResourcesInfo +import com.android.gradle.replicator.model.FilesWithSizeMetadataInfo +import com.android.gradle.replicator.model.internal.AndroidResourcesAdapter +import com.android.gradle.replicator.model.internal.DefaultAndroidResourcesInfo +import com.android.gradle.replicator.model.internal.DefaultFilesWithSizeMetadataInfo +import com.android.gradle.replicator.model.internal.FilesWithSizeMetadataAdapter import com.android.gradle.replicator.parsing.ArgsParser +import com.android.gradle.replicator.resourceModel.ResourceModel +import com.android.gradle.replicator.resourceModel.ResourceModelAdapter +import com.google.gson.stream.JsonReader import java.io.File import java.io.PrintStream +import java.nio.file.Files fun main(args: Array) { val main= Main() @@ -34,6 +44,7 @@ class Main { val parser = ArgsParser() val pathToArgumentsFileOption = parser.option(longName = "argsFile", shortName = "i", argc = 1) + val resourceModelFileOption = parser.option(longName = "resModel", shortName = "rm", argc = 1) val outputFolderOption = parser.option(longName = "outputFolder", shortName = "o", argc = 1) val moduleOption = parser.option(longName = "module", shortName = "m", argc = 1) val implClasspathElementOption = parser.option( @@ -61,11 +72,19 @@ class Main { parser.parseArgs(args) val parametersBuilder = CodeGenerationParameters.Builder() - val pathToArgumentsFile = pathToArgumentsFileOption.orNull?.first - if (pathToArgumentsFile!=null - && File(pathToArgumentsFile).exists()) { - parser.parsePropertyFile(File(pathToArgumentsFile)) + val pathToArgumentsFile = pathToArgumentsFileOption.orNull?.asFile + if (pathToArgumentsFile != null + && pathToArgumentsFile.exists()) { + parser.parsePropertyFile(pathToArgumentsFile) } + val resourceModelFile = resourceModelFileOption.orNull?.asFile + val resourceModel = + if (resourceModelFile != null + && resourceModelFile.exists()) { + loadResourceModel(resourceModelFile) + } else { + ResourceModel() + } buildParameters( parametersBuilder, apiOption.orNull?.argv, @@ -80,7 +99,7 @@ class Main { val kotlinGenerator: GeneratorType = GeneratorType.Kotlin val javaGenerator = GeneratorType.Java - val outputFolder = File(checkNotNull(outputFolderOption.orNull?.first)) + val outputFolder = outputFolderOption.asFile outputFolder.deleteRecursively() outputFolder.mkdirs() println("Generating in $outputFolder") @@ -94,6 +113,7 @@ class Main { javaGenerator, arguments, moduleName, + resourceModel, outputFolder ) } @@ -103,6 +123,7 @@ class Main { kotlinGenerator, arguments, moduleName, + resourceModel, outputFolder ) } @@ -113,6 +134,7 @@ class Main { generatorType: GeneratorType, parameters: CodeGenerationParameters, moduleName: String, + resourceModel: ResourceModel, outputFolder: File) { val generator = generatorType.initialize(parameters) repeat(numberOfSources) { count -> @@ -124,14 +146,27 @@ class Main { println("Generating ${generatorType.name} source ${outputFile.absolutePath}") PrintStream(outputFile).use { generator.generateClass( + moduleName = "com.android.example.${moduleName}", packageName = "com.android.example.${moduleName}", className = className, printStream = PrettyPrintStream(it), - listeners = listOf()) + listeners = listOf(), + resourceModel = resourceModel) } } } + // read generated android resource model + private fun loadResourceModel(resourceModelFile: File): ResourceModel { + var resourceModel: ResourceModel + + with(JsonReader(Files.newBufferedReader(resourceModelFile.toPath()))) { + resourceModel = ResourceModelAdapter().read(this) + } + + return resourceModel + } + private fun buildParameters( parametersBuilder: CodeGenerationParameters.Builder, apiClasspath: List?, diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/SingleClassGenerator.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/SingleClassGenerator.kt index 118fa67..eb506f2 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/SingleClassGenerator.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/SingleClassGenerator.kt @@ -16,6 +16,7 @@ */ package com.android.gradle.replicator.codegen +import com.android.gradle.replicator.resourceModel.ResourceModel import java.lang.reflect.Modifier import kotlin.random.Random import kotlin.reflect.* @@ -28,10 +29,12 @@ import kotlin.reflect.jvm.kotlinFunction class SingleClassGenerator( generator: ClassGenerator, private val params: ClassGenerationParameters, + private val moduleName: String, private val packageName: String, private val className: String, private val apiClassPicker: ImportClassPicker, private val implClassPicker: ImportClassPicker, + private val resourceModel: ResourceModel, private val random: Random ) { @@ -39,6 +42,8 @@ class SingleClassGenerator( private var currentBlockDepth: Int = 0; + private val rClassName = "$moduleName.R" + /** * Generate a single class using the provided generation parameters. */ @@ -222,6 +227,10 @@ class SingleClassGenerator( } } + private fun addResourceReferenceAndMethodCall() { + // To be implemented + } + private fun findMethodReturning(desiredReturnType: KType): MethodCall? { return findMethodReturning(classGenerator.getMethodParametersVariables(), desiredReturnType) ?: findMethodReturning(classGenerator.getLocalVariables(), desiredReturnType) diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/SourceGenerator.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/SourceGenerator.kt index fcf3582..8f49235 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/SourceGenerator.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/codegen/SourceGenerator.kt @@ -16,6 +16,8 @@ */ package com.android.gradle.replicator.codegen +import com.android.gradle.replicator.resourceModel.ResourceModel + /** * A SourceGenerator is capable of generating various types of source files for a particular language. * @@ -24,15 +26,18 @@ package com.android.gradle.replicator.codegen interface SourceGenerator { /** * Generate a class + * @param moduleName the root package for the module (where the R class is located). * @param packageName the class package. * @param className the class name. * @param printStream the stream to write the source code to. * @param listeners listeners for code generation events. */ fun generateClass( + moduleName: String, packageName: String, className: String, printStream: PrettyPrintStream, - listeners: List = listOf() + listeners: List = listOf(), + resourceModel: ResourceModel ) } \ No newline at end of file diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/parsing/ArgsParser.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/parsing/ArgsParser.kt index 68d6443..1dce34e 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/parsing/ArgsParser.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/parsing/ArgsParser.kt @@ -18,6 +18,8 @@ class ArgsParser { get() = argv[0] val orNull get() = if (isPresent) this else null + val asFile + get() = File(argv[0]) } private val longNameOpts = mutableMapOf() diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/DrawableResourceGenerator.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/DrawableResourceGenerator.kt index 530c538..8b07af0 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/DrawableResourceGenerator.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/DrawableResourceGenerator.kt @@ -19,12 +19,13 @@ package com.android.gradle.replicator.resgen import com.android.gradle.replicator.model.internal.filedata.AbstractAndroidResourceProperties import com.android.gradle.replicator.model.internal.filedata.DefaultAndroidResourceProperties import com.android.gradle.replicator.model.internal.filedata.ResourcePropertyType -import com.android.gradle.replicator.resgen.resourceModel.ResourceData +import com.android.gradle.replicator.resourceModel.ResourceData import com.android.gradle.replicator.resgen.util.FileTypes import com.android.gradle.replicator.resgen.util.VectorDrawableGenerator import com.android.gradle.replicator.resgen.util.copyResourceFile import com.android.gradle.replicator.resgen.util.getFileType import com.android.gradle.replicator.resgen.util.getResourceClosestToSize +import com.android.gradle.replicator.resourceModel.ResourceTypes import com.google.common.annotations.VisibleForTesting import java.io.File @@ -60,7 +61,7 @@ class DrawableResourceGenerator (params: ResourceGenerationParams): ResourceGene params.resourceModel.resourceList.add(ResourceData( pkg = "", name = fileName, - type = "drawable", + type = ResourceTypes.DRAWABLE, extension = properties.extension, qualifiers = properties.splitQualifiers)) } @@ -72,7 +73,7 @@ class DrawableResourceGenerator (params: ResourceGenerationParams): ResourceGene params.resourceModel.resourceList.add(ResourceData( pkg = "", name = fileName, - type = "drawable", + type = ResourceTypes.DRAWABLE, extension = properties.extension, qualifiers = properties.splitQualifiers)) } diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/FontResourceGenerator.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/FontResourceGenerator.kt index ca61fa9..fd6c3e6 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/FontResourceGenerator.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/FontResourceGenerator.kt @@ -3,10 +3,11 @@ package com.android.gradle.replicator.resgen import com.android.gradle.replicator.model.internal.filedata.AbstractAndroidResourceProperties import com.android.gradle.replicator.model.internal.filedata.DefaultAndroidResourceProperties import com.android.gradle.replicator.model.internal.filedata.ResourcePropertyType -import com.android.gradle.replicator.resgen.resourceModel.ResourceData +import com.android.gradle.replicator.resourceModel.ResourceData import com.android.gradle.replicator.resgen.util.copyResourceFile import com.android.gradle.replicator.resgen.util.getFileType import com.android.gradle.replicator.resgen.util.getResourceClosestToSize +import com.android.gradle.replicator.resourceModel.ResourceTypes import java.io.File class FontResourceGenerator(params: ResourceGenerationParams): ResourceGenerator(params) { @@ -40,7 +41,7 @@ class FontResourceGenerator(params: ResourceGenerationParams): ResourceGenerator ResourceData( pkg = "", name = fileName, - type = "font", + type = ResourceTypes.FONT, extension = properties.extension, qualifiers = properties.splitQualifiers) ) diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/GeneratorDriver.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/GeneratorDriver.kt index 2d160f0..fe53d39 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/GeneratorDriver.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/GeneratorDriver.kt @@ -1,7 +1,7 @@ package com.android.gradle.replicator.resgen import com.android.gradle.replicator.model.internal.filedata.AbstractAndroidResourceProperties -import com.android.gradle.replicator.resgen.resourceModel.ResourceModel +import com.android.gradle.replicator.resourceModel.ResourceModel import com.android.gradle.replicator.resgen.util.ResgenConstants import com.android.gradle.replicator.resgen.util.UniqueIdGenerator import java.io.File diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/Main.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/Main.kt index c51a959..a982cf5 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/Main.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/Main.kt @@ -22,12 +22,15 @@ import com.android.gradle.replicator.model.internal.* import com.android.gradle.replicator.model.internal.filedata.AndroidResourceMap import com.android.gradle.replicator.model.internal.filedata.FilesWithSizeMap import com.android.gradle.replicator.parsing.ArgsParser -import com.android.gradle.replicator.resgen.resourceModel.ResourceModel +import com.android.gradle.replicator.resourceModel.ResourceModel import com.android.gradle.replicator.resgen.util.ResgenConstants import com.android.gradle.replicator.resgen.util.UniqueIdGenerator +import com.android.gradle.replicator.resourceModel.ResourceModelAdapter import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonWriter import java.io.File import java.io.FileNotFoundException +import java.io.FileWriter import java.nio.file.Files import kotlin.random.Random @@ -50,6 +53,7 @@ class Main { val parser = ArgsParser() val androidOutputFolderOption = parser.option(longName = "androidOutput", shortName = "ao", argc = 1) + val resourceModelFileOption = parser.option(longName = "resModel", shortName = "rm", argc = 1) val javaOutputFolderOption = parser.option(longName = "javaOutput", shortName = "jo", argc = 1) val assetOutputFolderOption = parser.option(longName = "assetOutput", shortName = "so", argc = 1) val resJsonOption = parser.option(longName = "resJson", shortName = "rj", argc = 1) @@ -75,17 +79,21 @@ class Main { argumentsBuilder.setSeed(it.toInt()) } - val androidOutputFolder = File(checkNotNull(androidOutputFolderOption.orNull?.first)) + val androidOutputFolder = androidOutputFolderOption.asFile androidOutputFolder.deleteRecursively() androidOutputFolder.mkdirs() println("Generating android resources in $androidOutputFolder") - val javaOutputFolder = File(checkNotNull(javaOutputFolderOption.orNull?.first)) + val resourceModelFile = resourceModelFileOption.asFile + androidOutputFolder.parentFile.mkdirs() + println("Writing res model to $resourceModelFile") + + val javaOutputFolder = javaOutputFolderOption.asFile javaOutputFolder.deleteRecursively() javaOutputFolder.mkdirs() println("Generating java resources in $javaOutputFolder") - val assetOutputFolder = File(checkNotNull(assetOutputFolderOption.orNull?.first)) + val assetOutputFolder = assetOutputFolderOption.asFile assetOutputFolder.deleteRecursively() assetOutputFolder.mkdirs() println("Generating java resources in $assetOutputFolder") @@ -99,6 +107,7 @@ class Main { arguments.androidResourcesMap, arguments, androidOutputFolder, + resourceModelFile, resgenConstants ) } @@ -121,6 +130,7 @@ class Main { resMap: AndroidResourceMap, parameters: ResourceGenerationParameters, outputFolder: File, + resourceModelFile: File, resgenConstants: ResgenConstants) { val random = Random(parameters.seed) val uniqueIdGenerator = UniqueIdGenerator() @@ -131,6 +141,7 @@ class Main { generator.generateResources(outputFolder, resourceType, resourceProperties, resgenConstants, resourceModel) } } + writeResourceModelFile(resourceModelFile, resourceModel) } private fun generateJavaResources( @@ -176,6 +187,14 @@ class Main { return ResourceMetadata(androidResources.resourceMap, javaResources.fileData, assets.fileData) } + private fun writeResourceModelFile(resourceModelFile: File, resourceModel: ResourceModel) { + with(JsonWriter(FileWriter(resourceModelFile))) { + this.setIndent(" ") + ResourceModelAdapter().write(this, resourceModel) + this.flush() + } + } + private fun countResources(res: AndroidResourceMap): Int { var count = 0 res.forEach { folder -> diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/RawResourceGenerator.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/RawResourceGenerator.kt index ac56e77..639543f 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/RawResourceGenerator.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/RawResourceGenerator.kt @@ -3,10 +3,11 @@ package com.android.gradle.replicator.resgen import com.android.gradle.replicator.model.internal.filedata.AbstractAndroidResourceProperties import com.android.gradle.replicator.model.internal.filedata.DefaultAndroidResourceProperties import com.android.gradle.replicator.model.internal.filedata.ResourcePropertyType -import com.android.gradle.replicator.resgen.resourceModel.ResourceData +import com.android.gradle.replicator.resourceModel.ResourceData import com.android.gradle.replicator.resgen.util.copyResourceFile import com.android.gradle.replicator.resgen.util.getFileType import com.android.gradle.replicator.resgen.util.getResourceClosestToSize +import com.android.gradle.replicator.resourceModel.ResourceTypes import java.io.File class RawResourceGenerator (params: ResourceGenerationParams): ResourceGenerator(params) { @@ -32,7 +33,7 @@ class RawResourceGenerator (params: ResourceGenerationParams): ResourceGenerator ResourceData( pkg = "", name = fileName, - type = "raw", + type = ResourceTypes.RAW, extension = properties.extension, qualifiers = properties.splitQualifiers) ) diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/ResourceGenerator.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/ResourceGenerator.kt index 1c5ca4c..1b04f4e 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/ResourceGenerator.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/ResourceGenerator.kt @@ -17,7 +17,7 @@ package com.android.gradle.replicator.resgen import com.android.gradle.replicator.model.internal.filedata.AbstractAndroidResourceProperties -import com.android.gradle.replicator.resgen.resourceModel.ResourceModel +import com.android.gradle.replicator.resourceModel.ResourceModel import com.android.gradle.replicator.resgen.util.ResgenConstants import com.android.gradle.replicator.resgen.util.UniqueIdGenerator import java.io.File diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/ValueResourceGenerator.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/ValueResourceGenerator.kt index 6f86765..bf17093 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/ValueResourceGenerator.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/ValueResourceGenerator.kt @@ -20,10 +20,15 @@ import com.android.gradle.replicator.model.internal.filedata.AbstractAndroidReso import com.android.gradle.replicator.model.internal.filedata.ResourcePropertyType import com.android.gradle.replicator.model.internal.filedata.ValuesAndroidResourceProperties import com.android.gradle.replicator.model.internal.filedata.ValuesMap -import com.android.gradle.replicator.resgen.resourceModel.ResourceData +import com.android.gradle.replicator.resgen.util.StyleItemGenerator +import com.android.gradle.replicator.resgen.util.genColor +import com.android.gradle.replicator.resgen.util.genDimen +import com.android.gradle.replicator.resourceModel.ResourceData import com.android.gradle.replicator.resgen.util.genHex +import com.android.gradle.replicator.resgen.util.genName import com.android.gradle.replicator.resgen.util.genString import com.android.gradle.replicator.resgen.util.genUniqueName +import com.android.gradle.replicator.resourceModel.ResourceTypes import com.google.common.annotations.VisibleForTesting import java.io.File @@ -41,20 +46,13 @@ class ValueResourceGenerator (params: ResourceGenerationParams): ResourceGenerat throw RuntimeException ("Unexpected property type. Got ${properties.propertyType} instead of ${ResourcePropertyType.VALUES}") } (properties as ValuesAndroidResourceProperties).valuesMapPerFile.forEach { - // TODO: Sanity check style count vs other types - if (it.styleCount.size > 0) { // Theme resource - val outputFile = File(outputFolder, "themes_${params.uniqueIdGenerator.genIdByCategory("values.fileName.theme")}.${properties.extension}") - println("Generating ${outputFile.absolutePath}") - generateThemeResource(outputFile, properties.splitQualifiers, it) - } else { // XML values resource - val outputFile = File(outputFolder, "values_${params.uniqueIdGenerator.genIdByCategory("values.fileName.values")}.${properties.extension}") - println("Generating ${outputFile.absolutePath}") - generateXmlValueResource(outputFile, properties.splitQualifiers, it) - } + val outputFile = File(outputFolder, "values_${params.uniqueIdGenerator.genIdByCategory("values.fileName")}.${properties.extension}") + println("Generating ${outputFile.absolutePath}") + generateValuesResource(outputFile, properties.splitQualifiers, it) } } - private fun generateXmlValueResource ( + private fun generateValuesResource ( outputFile: File, resourceQualifiers: List, valuesMap: ValuesMap @@ -90,11 +88,15 @@ class ValueResourceGenerator (params: ResourceGenerationParams): ResourceGenerat } valuesMap.integerArrayCount.forEach { - xmlLines.addAll(intArrayBlock(resourceQualifiers)) + xmlLines.addAll(intArrayBlock(resourceQualifiers, it)) } valuesMap.arrayCount.forEach { - xmlLines.addAll(typedArrayBlock(resourceQualifiers)) + xmlLines.addAll(typedArrayBlock(resourceQualifiers, it)) + } + + valuesMap.styleCount.forEach { + xmlLines.addAll(styleBlock(resourceQualifiers, it)) } xmlLines.add("") @@ -102,13 +104,34 @@ class ValueResourceGenerator (params: ResourceGenerationParams): ResourceGenerat outputFile.writeText(xmlLines.joinToString(System.lineSeparator())) } - private fun generateThemeResource ( - outputFile: File, - resourceQualifiers: List, - valuesMap: ValuesMap - ) { - // To be implemented - return + // TODO: Add style parents and special styles + private fun styleBlock (resourceQualifiers: List, size: Int? = null): List { + val actualSize = size ?: params.random.nextInt(params.constants.values.MAX_ARRAY_ELEMENTS) + val name = genUniqueName(params.random, "values.resName.style", params.uniqueIdGenerator) + val xmlLines = mutableListOf( + " ") + + params.resourceModel.resourceList.add( + ResourceData( + pkg = "", + name = name, + type = ResourceTypes.VALUES_STYLE, + extension = "xml", + qualifiers = resourceQualifiers) + ) + + return xmlLines } private fun stringBlock (resourceQualifiers: List): String { @@ -122,7 +145,7 @@ class ValueResourceGenerator (params: ResourceGenerationParams): ResourceGenerat ResourceData( pkg = "", name = name, - type = "values_string", + type = ResourceTypes.VALUES_STRING, extension = "xml", qualifiers = resourceQualifiers) ) @@ -138,7 +161,7 @@ class ValueResourceGenerator (params: ResourceGenerationParams): ResourceGenerat ResourceData( pkg = "", name = name, - type = "values_int", + type = ResourceTypes.VALUES_INT, extension = "xml", qualifiers = resourceQualifiers) ) @@ -154,7 +177,7 @@ class ValueResourceGenerator (params: ResourceGenerationParams): ResourceGenerat ResourceData( pkg = "", name = name, - type = "values_bool", + type = ResourceTypes.VALUES_BOOL, extension = "xml", qualifiers = resourceQualifiers) ) @@ -164,36 +187,29 @@ class ValueResourceGenerator (params: ResourceGenerationParams): ResourceGenerat private fun colorBlock (resourceQualifiers: List): String { val name = genUniqueName(params.random, "values.resName.color.${resourceQualifiers}", params.uniqueIdGenerator) - /* Digits can be: - * #RGB - * #ARGB - * #RRGGBB - * #AARRGGBB - */ - val numberOfDigits = params.constants.values.POSSIBLE_COLOR_DIGITS.random(params.random) - val value = genHex(numberOfDigits, params.random) + val value = genColor(params.constants, params.random) params.resourceModel.resourceList.add( ResourceData( pkg = "", name = name, - type = "values_color", + type = ResourceTypes.VALUES_COLOR, extension = "xml", qualifiers = resourceQualifiers) ) - return " #$value" + return " $value" } private fun dimenBlock (resourceQualifiers: List): String { val name = genUniqueName(params.random, "values.resName.dimen.${resourceQualifiers}", params.uniqueIdGenerator) - val value = "${params.random.nextInt(params.constants.values.MAX_DIMENSION)}${params.constants.values.DIMENSION_UNITS.random(params.random)}" + val value = genDimen(params.constants, params.random) params.resourceModel.resourceList.add( ResourceData( pkg = "", name = name, - type = "values_dimen", + type = ResourceTypes.VALUES_DIMEN, extension = "xml", qualifiers = resourceQualifiers) ) @@ -207,19 +223,19 @@ class ValueResourceGenerator (params: ResourceGenerationParams): ResourceGenerat ResourceData( pkg = "", name = name, - type = "values_id", + type = ResourceTypes.VALUES_ID, extension = "xml", qualifiers = resourceQualifiers) ) return " " } - private fun intArrayBlock (resourceQualifiers: List): List { + private fun intArrayBlock (resourceQualifiers: List, size: Int? = null): List { val name = genUniqueName(params.random, "values.resName.intArray.${resourceQualifiers}", params.uniqueIdGenerator) - val size = params.random.nextInt(params.constants.values.MAX_ARRAY_ELEMENTS) + val actualSize = size ?: params.random.nextInt(params.constants.values.MAX_ARRAY_ELEMENTS) val result = mutableListOf(" ") - repeat(size) { + repeat(actualSize) { val value = params.random.nextInt() result.add(" $value") } @@ -228,14 +244,14 @@ class ValueResourceGenerator (params: ResourceGenerationParams): ResourceGenerat ResourceData( pkg = "", name = name, - type = "values_int_array", + type = ResourceTypes.VALUES_INT_ARRAY, extension = "xml", qualifiers = resourceQualifiers) ) return result } - private fun typedArrayBlock (resourceQualifiers: List): List { + private fun typedArrayBlock (resourceQualifiers: List, size: Int? = null): List { // to be implemented return listOf() } diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/resourceModel/ResourceModel.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/resourceModel/ResourceModel.kt deleted file mode 100644 index a3725e6..0000000 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/resourceModel/ResourceModel.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.android.gradle.replicator.resgen.resourceModel - -data class ResourceData ( - val pkg: String, - val name: String, - val type: String, - val extension: String, - val qualifiers: List -) - -class ResourceModel { - val resourceList: MutableList = mutableListOf() -} \ No newline at end of file diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/util/GenerationUtil.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/util/GenerationUtil.kt index d0be4c3..cb72f1c 100644 --- a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/util/GenerationUtil.kt +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/util/GenerationUtil.kt @@ -16,6 +16,9 @@ */ package com.android.gradle.replicator.resgen.util +import com.android.gradle.replicator.resourceModel.ResourceData +import com.android.gradle.replicator.resourceModel.ResourceModel +import com.android.gradle.replicator.resourceModel.ResourceTypes import kotlin.math.abs import kotlin.math.ceil import kotlin.random.Random @@ -71,6 +74,25 @@ fun genHex(numberOfDigits: Int, random: Random): String { .substring(0, numberOfDigits) // Trim if odd number of hex requested } +fun genColor(constants: ResgenConstants, random: Random): String { + /* Digits can be: + * #RGB + * #ARGB + * #RRGGBB + * #AARRGGBB + */ + val numberOfDigits = constants.values.POSSIBLE_COLOR_DIGITS.random(random) + return "#${genHex(numberOfDigits, random)}" +} + +fun genDimen(constants: ResgenConstants, random: Random): String { + return "${random.nextInt(constants.values.MAX_DIMENSION)}${constants.values.DIMENSION_UNITS.random(random)}" +} + +fun genFloat(random: Random): String { + return "${random.nextFloat()}" +} + fun genIdCharacters(count: Int, minFileNameCharacters: Int = 3): String { var current = count var characters = "" @@ -81,6 +103,13 @@ fun genIdCharacters(count: Int, minFileNameCharacters: Int = 3): String { return characters } +fun genResourceOfType(random: Random, type: ResourceTypes, resourceModel: ResourceModel): ResourceData? { + val filtered = resourceModel.resourceList.filter { it.type == type } + if (filtered.isEmpty()) return null + + return filtered.random(random) +} + class UniqueIdGenerator { private val idCountByType = mutableMapOf() fun genIdByCategory(category: String): String { diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/util/StyleItemGenerator.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/util/StyleItemGenerator.kt new file mode 100644 index 0000000..1148084 --- /dev/null +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resgen/util/StyleItemGenerator.kt @@ -0,0 +1,135 @@ +package com.android.gradle.replicator.resgen.util + +import com.android.gradle.replicator.resourceModel.ResourceModel +import com.android.gradle.replicator.resourceModel.ResourceTypes +import kotlin.random.Random + +// Class for generating style items +class StyleItemGenerator(private val resourceModel: ResourceModel, private val constants: ResgenConstants) { + enum class StyleItemType { + COLOR, + DIMEN, + DRAWABLE, + TEXT_APPEARANCE, + SHAPE, + BUTTON, + FLOAT + } + + data class StyleItem (val name: String, val type: StyleItemType, var value: String = "") + + // Candidates for style items + private val styleList = mutableListOf( + StyleItem("colorPrimary", StyleItemType.COLOR), + StyleItem("colorSecondary", StyleItemType.COLOR), + StyleItem("colorOnPrimary", StyleItemType.COLOR), + StyleItem("colorOnSecondary", StyleItemType.COLOR), + StyleItem("colorOnSurface", StyleItemType.COLOR), + StyleItem("colorPrimaryVariant", StyleItemType.COLOR), + StyleItem("colorSecondaryVariant", StyleItemType.COLOR), + StyleItem("colorSurface", StyleItemType.COLOR), + StyleItem("android:colorBackground", StyleItemType.COLOR), + StyleItem("colorPrimarySurface", StyleItemType.COLOR), + StyleItem("colorError", StyleItemType.COLOR), + StyleItem("colorControlNormal", StyleItemType.COLOR), + StyleItem("colorControlActivated", StyleItemType.COLOR), + StyleItem("colorControlHighlight", StyleItemType.COLOR), + StyleItem("android:textColorPrimary", StyleItemType.COLOR), + StyleItem("android:textColorSecondary", StyleItemType.COLOR), + + StyleItem("listPreferredItemHeight", StyleItemType.DIMEN), + StyleItem("actionBarSize", StyleItemType.DIMEN), + + StyleItem("selectableItemBackground", StyleItemType.DRAWABLE), + StyleItem("selectableItemBackgroundBorderless", StyleItemType.DRAWABLE), + StyleItem("dividerVertical", StyleItemType.DRAWABLE), + StyleItem("dividerHorizontal", StyleItemType.DRAWABLE), + + /* not supported yet + StyleItem("textAppearanceHeadline1", StyleItemType.TEXT_APPEARANCE), + StyleItem("textAppearanceHeadline2", StyleItemType.TEXT_APPEARANCE), + StyleItem("textAppearanceHeadline3", StyleItemType.TEXT_APPEARANCE), + StyleItem("textAppearanceHeadline4", StyleItemType.TEXT_APPEARANCE), + StyleItem("textAppearanceHeadline5", StyleItemType.TEXT_APPEARANCE), + StyleItem("textAppearanceHeadline6", StyleItemType.TEXT_APPEARANCE), + StyleItem("textAppearanceSubtitle1", StyleItemType.TEXT_APPEARANCE), + StyleItem("textAppearanceSubtitle2", StyleItemType.TEXT_APPEARANCE), + StyleItem("textAppearanceBody1", StyleItemType.TEXT_APPEARANCE), + StyleItem("textAppearanceBody2", StyleItemType.TEXT_APPEARANCE), + StyleItem("textAppearanceCaption", StyleItemType.TEXT_APPEARANCE), + StyleItem("textAppearanceButton", StyleItemType.TEXT_APPEARANCE), + StyleItem("textAppearanceOverline", StyleItemType.TEXT_APPEARANCE), + + StyleItem("shapeAppearanceSmallComponent", StyleItemType.SHAPE), + StyleItem("shapeAppearanceMediumComponent", StyleItemType.SHAPE), + StyleItem("shapeAppearanceLargeComponent", StyleItemType.SHAPE), + + StyleItem("materialButtonStyle", StyleItemType.BUTTON), + StyleItem("borderlessButtonStyle", StyleItemType.BUTTON), + StyleItem("materialButtonOutlinedStyle", StyleItemType.BUTTON), + */ + + StyleItem("android:disabledAlpha", StyleItemType.FLOAT), + StyleItem("android:primaryContentAlpha", StyleItemType.FLOAT), + StyleItem("android:secondaryContentAlpha", StyleItemType.FLOAT) + ) + + fun generateStyleItem(random: Random): StyleItem? { + if (styleList.isEmpty()) return null // no more items to add + + // Choose item and remove it from candidates + val choice = random.nextInt(styleList.size) + val item = styleList[choice] + styleList.removeAt(choice) + + val isReference = random.nextInt(10) in 0..4 // 50% chance to be a reference to another resource + when (item.type) { + StyleItemType.COLOR -> + item.value = getReferenceOrGenerate( + random = random, + isReference = isReference, + resType = ResourceTypes.VALUES_COLOR, + generator = { genColor(constants, random) } + ) + StyleItemType.DIMEN -> + item.value = getReferenceOrGenerate( + random = random, + isReference = isReference, + resType = ResourceTypes.VALUES_DIMEN, + generator = { genDimen(constants, random) } + ) + StyleItemType.DRAWABLE -> + item.value = getReferenceOrGenerate( + random = random, + isReference = true, // always a reference + resType = ResourceTypes.VALUES_DIMEN, + generator = { "@android:drawable/btn_default" } // always a reference + ) + StyleItemType.TEXT_APPEARANCE -> + return null // not yet supported + StyleItemType.SHAPE -> + return null // not yet supported + StyleItemType.BUTTON -> + return null // not yet supported + StyleItemType.FLOAT -> + item.value = getReferenceOrGenerate( + random = random, + isReference = false, // never a reference + resType = ResourceTypes.VALUES_DIMEN, + generator = { genFloat(random) } + ) + } + return item + } + + // Either get a reference or fall back to the generator to create a raw value + private fun getReferenceOrGenerate(random: Random, isReference: Boolean, resType: ResourceTypes, generator: (Random) -> String): String { + return if (isReference) { + val res = genResourceOfType(random, resType, resourceModel) + // res = null means no valid references + res?.reference ?: generator(random) + } else { + generator(random) + } + } +} \ No newline at end of file diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resourceModel/ResourceModel.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resourceModel/ResourceModel.kt new file mode 100644 index 0000000..5e2e9a2 --- /dev/null +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resourceModel/ResourceModel.kt @@ -0,0 +1,78 @@ +package com.android.gradle.replicator.resourceModel + +enum class ResourceTypes { + // Values + VALUES_COLOR, + VALUES_INT, + VALUES_BOOL, + VALUES_ID, + VALUES_STRING, + VALUES_INT_ARRAY, + VALUES_TYPED_ARRAY, + VALUES_DIMEN, + VALUES_STYLE, + + FONT, + MIPMAP, + DRAWABLE, + RAW, + LAYOUT; + + fun referenceString(): String { + return when (this) { + VALUES_COLOR -> "color" + VALUES_INT -> "integer" + VALUES_BOOL -> "bool" + VALUES_ID -> "id" + VALUES_STRING -> "string" + VALUES_INT_ARRAY -> "array" + VALUES_TYPED_ARRAY -> "array" + VALUES_DIMEN -> "dimen" + VALUES_STYLE -> "style" + + FONT -> "font" + MIPMAP -> "mipmap" + DRAWABLE -> "drawable" + RAW -> "raw" + LAYOUT -> "layout" + } + } + + companion object { + fun fromString(s: String): ResourceTypes { + return when (s) { + "VALUES_COLOR" -> VALUES_COLOR + "VALUES_INT" -> VALUES_INT + "VALUES_BOOL" -> VALUES_BOOL + "VALUES_ID" -> VALUES_ID + "VALUES_STRING" -> VALUES_STRING + "VALUES_INT_ARRAY" -> VALUES_INT_ARRAY + "VALUES_TYPED_ARRAY" -> VALUES_TYPED_ARRAY + "VALUES_DIMEN" -> VALUES_DIMEN + "VALUES_STYLE" -> VALUES_STYLE + + "FONT" -> FONT + "MIPMAP" -> MIPMAP + "DRAWABLE" -> DRAWABLE + "RAW" -> RAW + "LAYOUT" -> LAYOUT + else -> throw RuntimeException("invalid resource type $s") + } + } + } +} + +data class ResourceData ( + val pkg: String, + val name: String, + val type: ResourceTypes, + val extension: String, + val qualifiers: List +) { + val reference: String + get() = "@${type.referenceString()}/${name}" +} + +class ResourceModel { + val resourceList: MutableList = mutableListOf() +} \ No newline at end of file diff --git a/code/codegen/src/main/kotlin/com/android/gradle/replicator/resourceModel/ResourceModelAdapter.kt b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resourceModel/ResourceModelAdapter.kt new file mode 100644 index 0000000..cc1929a --- /dev/null +++ b/code/codegen/src/main/kotlin/com/android/gradle/replicator/resourceModel/ResourceModelAdapter.kt @@ -0,0 +1,95 @@ +package com.android.gradle.replicator.resourceModel + +import com.google.gson.TypeAdapter +import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonWriter + +class ResourceModelAdapter: TypeAdapter() { + override fun write(output: JsonWriter, value: ResourceModel) { + output.beginObject() + + output.name("resourceList").beginArray() + value.resourceList.forEach { resource -> + output.beginObject() + + output.name("module").value(resource.pkg) + output.name("name").value(resource.name) + output.name("type").value(resource.type.toString()) + output.name("extension").value(resource.extension) + + output.name("qualifiers").beginArray() + resource.qualifiers.forEach { qualifier -> + output.value(qualifier) + } + output.endArray() + + output.endObject() + } + output.endArray() + + output.endObject() + } + + override fun read(input: JsonReader): ResourceModel { + val resourceModel = ResourceModel() + val readProperties = { reader: JsonReader, consumer: (String) -> Unit -> + reader.beginObject() + while (reader.hasNext()) { + consumer(reader.nextName()) + } + reader.endObject() + } + val readArray = { reader: JsonReader, consumer: () -> Unit -> + reader.beginArray() + while (reader.hasNext()) { + consumer() + } + reader.endArray() + } + + readProperties(input) { + if (it != "resourceList") { + throw RuntimeException("malformed resource model file") + } + readArray(input) { + lateinit var module: String + lateinit var name: String + lateinit var type: String + lateinit var extension: String + lateinit var qualifiers: MutableList + + readProperties(input) { property -> + when (property) { + "module" -> { + module = input.nextString() + } + "name" -> { + name = input.nextString() + } + "type" -> { + type = input.nextString() + } + "extension" -> { + extension = input.nextString() + } + "qualifiers" -> { + qualifiers = mutableListOf() + readArray(input) { + qualifiers.add(input.nextString()) + } + } + } + } + resourceModel.resourceList.add(ResourceData( + pkg = module, + name = name, + type = ResourceTypes.fromString(type), + extension = extension, + qualifiers = qualifiers + )) + } + } + + return resourceModel + } +} \ No newline at end of file diff --git a/code/codegen/src/main/resources/resgen/images/9png/hdpi_bootleg_android_icon.9.png b/code/codegen/src/main/resources/resgen/images/9png/hdpi_bootleg_android_icon.9.png new file mode 100644 index 0000000..36cb05b Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/9png/hdpi_bootleg_android_icon.9.png differ diff --git a/code/codegen/src/main/resources/resgen/images/9png/hdpi_pizza_icon.9.png b/code/codegen/src/main/resources/resgen/images/9png/hdpi_pizza_icon.9.png new file mode 100644 index 0000000..e68ed1b Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/9png/hdpi_pizza_icon.9.png differ diff --git a/code/codegen/src/main/resources/resgen/images/9png/ldpi_bootleg_android_icon.9.png b/code/codegen/src/main/resources/resgen/images/9png/ldpi_bootleg_android_icon.9.png new file mode 100644 index 0000000..f57de68 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/9png/ldpi_bootleg_android_icon.9.png differ diff --git a/code/codegen/src/main/resources/resgen/images/9png/ldpi_pizza_icon.9.png b/code/codegen/src/main/resources/resgen/images/9png/ldpi_pizza_icon.9.png new file mode 100644 index 0000000..f39e599 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/9png/ldpi_pizza_icon.9.png differ diff --git a/code/codegen/src/main/resources/resgen/images/9png/mdpi_bootleg_android_icon.9.png b/code/codegen/src/main/resources/resgen/images/9png/mdpi_bootleg_android_icon.9.png new file mode 100644 index 0000000..d592acf Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/9png/mdpi_bootleg_android_icon.9.png differ diff --git a/code/codegen/src/main/resources/resgen/images/9png/mdpi_pizza_icon.9.png b/code/codegen/src/main/resources/resgen/images/9png/mdpi_pizza_icon.9.png new file mode 100644 index 0000000..e6a8586 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/9png/mdpi_pizza_icon.9.png differ diff --git a/code/codegen/src/main/resources/resgen/images/9png/xhdpi_bootleg_android_icon.9.png b/code/codegen/src/main/resources/resgen/images/9png/xhdpi_bootleg_android_icon.9.png new file mode 100644 index 0000000..e7893db Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/9png/xhdpi_bootleg_android_icon.9.png differ diff --git a/code/codegen/src/main/resources/resgen/images/9png/xhdpi_pizza_icon.9.png b/code/codegen/src/main/resources/resgen/images/9png/xhdpi_pizza_icon.9.png new file mode 100644 index 0000000..904275e Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/9png/xhdpi_pizza_icon.9.png differ diff --git a/code/codegen/src/main/resources/resgen/images/9png/xxhdpi_bootleg_android_icon.9.png b/code/codegen/src/main/resources/resgen/images/9png/xxhdpi_bootleg_android_icon.9.png new file mode 100644 index 0000000..d89e81d Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/9png/xxhdpi_bootleg_android_icon.9.png differ diff --git a/code/codegen/src/main/resources/resgen/images/9png/xxhdpi_pizza_icon.9.png b/code/codegen/src/main/resources/resgen/images/9png/xxhdpi_pizza_icon.9.png new file mode 100644 index 0000000..564f01b Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/9png/xxhdpi_pizza_icon.9.png differ diff --git a/code/codegen/src/main/resources/resgen/images/9png/xxxhdpi_bootleg_android_icon.9.png b/code/codegen/src/main/resources/resgen/images/9png/xxxhdpi_bootleg_android_icon.9.png new file mode 100644 index 0000000..324bdd4 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/9png/xxxhdpi_bootleg_android_icon.9.png differ diff --git a/code/codegen/src/main/resources/resgen/images/9png/xxxhdpi_pizza_icon.9.png b/code/codegen/src/main/resources/resgen/images/9png/xxxhdpi_pizza_icon.9.png new file mode 100644 index 0000000..7f73cb9 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/9png/xxxhdpi_pizza_icon.9.png differ diff --git a/code/codegen/src/main/resources/resgen/images/gif/hdpi_bootleg_android_icon.gif b/code/codegen/src/main/resources/resgen/images/gif/hdpi_bootleg_android_icon.gif new file mode 100644 index 0000000..d145434 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/gif/hdpi_bootleg_android_icon.gif differ diff --git a/code/codegen/src/main/resources/resgen/images/gif/hdpi_pizza_icon.gif b/code/codegen/src/main/resources/resgen/images/gif/hdpi_pizza_icon.gif new file mode 100644 index 0000000..633672c Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/gif/hdpi_pizza_icon.gif differ diff --git a/code/codegen/src/main/resources/resgen/images/gif/ldpi_bootleg_android_icon.gif b/code/codegen/src/main/resources/resgen/images/gif/ldpi_bootleg_android_icon.gif new file mode 100644 index 0000000..5d61ab9 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/gif/ldpi_bootleg_android_icon.gif differ diff --git a/code/codegen/src/main/resources/resgen/images/gif/ldpi_pizza_icon.gif b/code/codegen/src/main/resources/resgen/images/gif/ldpi_pizza_icon.gif new file mode 100644 index 0000000..24e5226 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/gif/ldpi_pizza_icon.gif differ diff --git a/code/codegen/src/main/resources/resgen/images/gif/mdpi_bootleg_android_icon.gif b/code/codegen/src/main/resources/resgen/images/gif/mdpi_bootleg_android_icon.gif new file mode 100644 index 0000000..648a725 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/gif/mdpi_bootleg_android_icon.gif differ diff --git a/code/codegen/src/main/resources/resgen/images/gif/mdpi_pizza_icon.gif b/code/codegen/src/main/resources/resgen/images/gif/mdpi_pizza_icon.gif new file mode 100644 index 0000000..1494c87 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/gif/mdpi_pizza_icon.gif differ diff --git a/code/codegen/src/main/resources/resgen/images/gif/xhdpi_bootleg_android_icon.gif b/code/codegen/src/main/resources/resgen/images/gif/xhdpi_bootleg_android_icon.gif new file mode 100644 index 0000000..c094bb9 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/gif/xhdpi_bootleg_android_icon.gif differ diff --git a/code/codegen/src/main/resources/resgen/images/gif/xhdpi_pizza_icon.gif b/code/codegen/src/main/resources/resgen/images/gif/xhdpi_pizza_icon.gif new file mode 100644 index 0000000..7a1070e Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/gif/xhdpi_pizza_icon.gif differ diff --git a/code/codegen/src/main/resources/resgen/images/gif/xxhdpi_bootleg_android_icon.gif b/code/codegen/src/main/resources/resgen/images/gif/xxhdpi_bootleg_android_icon.gif new file mode 100644 index 0000000..69739b1 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/gif/xxhdpi_bootleg_android_icon.gif differ diff --git a/code/codegen/src/main/resources/resgen/images/gif/xxhdpi_pizza_icon.gif b/code/codegen/src/main/resources/resgen/images/gif/xxhdpi_pizza_icon.gif new file mode 100644 index 0000000..041812b Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/gif/xxhdpi_pizza_icon.gif differ diff --git a/code/codegen/src/main/resources/resgen/images/gif/xxxhdpi_bootleg_android_icon.gif b/code/codegen/src/main/resources/resgen/images/gif/xxxhdpi_bootleg_android_icon.gif new file mode 100644 index 0000000..6077915 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/gif/xxxhdpi_bootleg_android_icon.gif differ diff --git a/code/codegen/src/main/resources/resgen/images/gif/xxxhdpi_pizza_icon.gif b/code/codegen/src/main/resources/resgen/images/gif/xxxhdpi_pizza_icon.gif new file mode 100644 index 0000000..75b8e3d Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/gif/xxxhdpi_pizza_icon.gif differ diff --git a/code/codegen/src/main/resources/resgen/images/jpeg/hdpi_bootleg_android_icon.jpg b/code/codegen/src/main/resources/resgen/images/jpeg/hdpi_bootleg_android_icon.jpg new file mode 100644 index 0000000..f03ce12 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/jpeg/hdpi_bootleg_android_icon.jpg differ diff --git a/code/codegen/src/main/resources/resgen/images/jpeg/hdpi_pizza_icon.jpg b/code/codegen/src/main/resources/resgen/images/jpeg/hdpi_pizza_icon.jpg new file mode 100644 index 0000000..008251d Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/jpeg/hdpi_pizza_icon.jpg differ diff --git a/code/codegen/src/main/resources/resgen/images/jpeg/ldpi_bootleg_android_icon.jpg b/code/codegen/src/main/resources/resgen/images/jpeg/ldpi_bootleg_android_icon.jpg new file mode 100644 index 0000000..5fb0a0c Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/jpeg/ldpi_bootleg_android_icon.jpg differ diff --git a/code/codegen/src/main/resources/resgen/images/jpeg/ldpi_pizza_icon.jpg b/code/codegen/src/main/resources/resgen/images/jpeg/ldpi_pizza_icon.jpg new file mode 100644 index 0000000..55e8423 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/jpeg/ldpi_pizza_icon.jpg differ diff --git a/code/codegen/src/main/resources/resgen/images/jpeg/mdpi_bootleg_android_icon.jpg b/code/codegen/src/main/resources/resgen/images/jpeg/mdpi_bootleg_android_icon.jpg new file mode 100644 index 0000000..e0d29a2 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/jpeg/mdpi_bootleg_android_icon.jpg differ diff --git a/code/codegen/src/main/resources/resgen/images/jpeg/mdpi_pizza_icon.jpg b/code/codegen/src/main/resources/resgen/images/jpeg/mdpi_pizza_icon.jpg new file mode 100644 index 0000000..bf26892 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/jpeg/mdpi_pizza_icon.jpg differ diff --git a/code/codegen/src/main/resources/resgen/images/jpeg/xhdpi_bootleg_android_icon.jpg b/code/codegen/src/main/resources/resgen/images/jpeg/xhdpi_bootleg_android_icon.jpg new file mode 100644 index 0000000..64f0b53 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/jpeg/xhdpi_bootleg_android_icon.jpg differ diff --git a/code/codegen/src/main/resources/resgen/images/jpeg/xhdpi_pizza_icon.jpg b/code/codegen/src/main/resources/resgen/images/jpeg/xhdpi_pizza_icon.jpg new file mode 100644 index 0000000..4965430 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/jpeg/xhdpi_pizza_icon.jpg differ diff --git a/code/codegen/src/main/resources/resgen/images/jpeg/xxhdpi_bootleg_android_icon.jpg b/code/codegen/src/main/resources/resgen/images/jpeg/xxhdpi_bootleg_android_icon.jpg new file mode 100644 index 0000000..fe25e0e Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/jpeg/xxhdpi_bootleg_android_icon.jpg differ diff --git a/code/codegen/src/main/resources/resgen/images/jpeg/xxhdpi_pizza_icon.jpg b/code/codegen/src/main/resources/resgen/images/jpeg/xxhdpi_pizza_icon.jpg new file mode 100644 index 0000000..5c075ba Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/jpeg/xxhdpi_pizza_icon.jpg differ diff --git a/code/codegen/src/main/resources/resgen/images/jpeg/xxxhdpi_bootleg_android_icon.jpg b/code/codegen/src/main/resources/resgen/images/jpeg/xxxhdpi_bootleg_android_icon.jpg new file mode 100644 index 0000000..c5adf03 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/jpeg/xxxhdpi_bootleg_android_icon.jpg differ diff --git a/code/codegen/src/main/resources/resgen/images/jpeg/xxxhdpi_pizza_icon.jpg b/code/codegen/src/main/resources/resgen/images/jpeg/xxxhdpi_pizza_icon.jpg new file mode 100644 index 0000000..5822a03 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/jpeg/xxxhdpi_pizza_icon.jpg differ diff --git a/code/codegen/src/main/resources/resgen/images/png/hdpi_bootleg_android_icon.png b/code/codegen/src/main/resources/resgen/images/png/hdpi_bootleg_android_icon.png new file mode 100644 index 0000000..36cb05b Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/png/hdpi_bootleg_android_icon.png differ diff --git a/code/codegen/src/main/resources/resgen/images/png/hdpi_pizza_icon.png b/code/codegen/src/main/resources/resgen/images/png/hdpi_pizza_icon.png new file mode 100644 index 0000000..e68ed1b Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/png/hdpi_pizza_icon.png differ diff --git a/code/codegen/src/main/resources/resgen/images/png/ldpi_bootleg_android_icon.png b/code/codegen/src/main/resources/resgen/images/png/ldpi_bootleg_android_icon.png new file mode 100644 index 0000000..f57de68 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/png/ldpi_bootleg_android_icon.png differ diff --git a/code/codegen/src/main/resources/resgen/images/png/ldpi_pizza_icon.png b/code/codegen/src/main/resources/resgen/images/png/ldpi_pizza_icon.png new file mode 100644 index 0000000..f39e599 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/png/ldpi_pizza_icon.png differ diff --git a/code/codegen/src/main/resources/resgen/images/png/mdpi_bootleg_android_icon.png b/code/codegen/src/main/resources/resgen/images/png/mdpi_bootleg_android_icon.png new file mode 100644 index 0000000..d592acf Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/png/mdpi_bootleg_android_icon.png differ diff --git a/code/codegen/src/main/resources/resgen/images/png/mdpi_pizza_icon.png b/code/codegen/src/main/resources/resgen/images/png/mdpi_pizza_icon.png new file mode 100644 index 0000000..e6a8586 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/png/mdpi_pizza_icon.png differ diff --git a/code/codegen/src/main/resources/resgen/images/png/xhdpi_bootleg_android_icon.png b/code/codegen/src/main/resources/resgen/images/png/xhdpi_bootleg_android_icon.png new file mode 100644 index 0000000..e7893db Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/png/xhdpi_bootleg_android_icon.png differ diff --git a/code/codegen/src/main/resources/resgen/images/png/xhdpi_pizza_icon.png b/code/codegen/src/main/resources/resgen/images/png/xhdpi_pizza_icon.png new file mode 100644 index 0000000..904275e Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/png/xhdpi_pizza_icon.png differ diff --git a/code/codegen/src/main/resources/resgen/images/png/xxhdpi_bootleg_android_icon.png b/code/codegen/src/main/resources/resgen/images/png/xxhdpi_bootleg_android_icon.png new file mode 100644 index 0000000..d89e81d Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/png/xxhdpi_bootleg_android_icon.png differ diff --git a/code/codegen/src/main/resources/resgen/images/png/xxhdpi_pizza_icon.png b/code/codegen/src/main/resources/resgen/images/png/xxhdpi_pizza_icon.png new file mode 100644 index 0000000..564f01b Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/png/xxhdpi_pizza_icon.png differ diff --git a/code/codegen/src/main/resources/resgen/images/png/xxxhdpi_bootleg_android_icon.png b/code/codegen/src/main/resources/resgen/images/png/xxxhdpi_bootleg_android_icon.png new file mode 100644 index 0000000..324bdd4 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/png/xxxhdpi_bootleg_android_icon.png differ diff --git a/code/codegen/src/main/resources/resgen/images/png/xxxhdpi_pizza_icon.png b/code/codegen/src/main/resources/resgen/images/png/xxxhdpi_pizza_icon.png new file mode 100644 index 0000000..7f73cb9 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/png/xxxhdpi_pizza_icon.png differ diff --git a/code/codegen/src/main/resources/resgen/images/webp/hdpi_bootleg_android_icon.webp b/code/codegen/src/main/resources/resgen/images/webp/hdpi_bootleg_android_icon.webp new file mode 100644 index 0000000..ec73ca6 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/webp/hdpi_bootleg_android_icon.webp differ diff --git a/code/codegen/src/main/resources/resgen/images/webp/hdpi_pizza_icon.webp b/code/codegen/src/main/resources/resgen/images/webp/hdpi_pizza_icon.webp new file mode 100644 index 0000000..fc36154 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/webp/hdpi_pizza_icon.webp differ diff --git a/code/codegen/src/main/resources/resgen/images/webp/ldpi_bootleg_android_icon.webp b/code/codegen/src/main/resources/resgen/images/webp/ldpi_bootleg_android_icon.webp new file mode 100644 index 0000000..da183ec Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/webp/ldpi_bootleg_android_icon.webp differ diff --git a/code/codegen/src/main/resources/resgen/images/webp/ldpi_pizza_icon.webp b/code/codegen/src/main/resources/resgen/images/webp/ldpi_pizza_icon.webp new file mode 100644 index 0000000..393ee5b Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/webp/ldpi_pizza_icon.webp differ diff --git a/code/codegen/src/main/resources/resgen/images/webp/mdpi_bootleg_android_icon.webp b/code/codegen/src/main/resources/resgen/images/webp/mdpi_bootleg_android_icon.webp new file mode 100644 index 0000000..f159c2e Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/webp/mdpi_bootleg_android_icon.webp differ diff --git a/code/codegen/src/main/resources/resgen/images/webp/mdpi_pizza_icon.webp b/code/codegen/src/main/resources/resgen/images/webp/mdpi_pizza_icon.webp new file mode 100644 index 0000000..eb3dcf3 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/webp/mdpi_pizza_icon.webp differ diff --git a/code/codegen/src/main/resources/resgen/images/webp/xhdpi_bootleg_android_icon.webp b/code/codegen/src/main/resources/resgen/images/webp/xhdpi_bootleg_android_icon.webp new file mode 100644 index 0000000..13fcdde Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/webp/xhdpi_bootleg_android_icon.webp differ diff --git a/code/codegen/src/main/resources/resgen/images/webp/xhdpi_pizza_icon.webp b/code/codegen/src/main/resources/resgen/images/webp/xhdpi_pizza_icon.webp new file mode 100644 index 0000000..5c5b157 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/webp/xhdpi_pizza_icon.webp differ diff --git a/code/codegen/src/main/resources/resgen/images/webp/xxhdpi_bootleg_android_icon.webp b/code/codegen/src/main/resources/resgen/images/webp/xxhdpi_bootleg_android_icon.webp new file mode 100644 index 0000000..e10cba5 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/webp/xxhdpi_bootleg_android_icon.webp differ diff --git a/code/codegen/src/main/resources/resgen/images/webp/xxhdpi_pizza_icon.webp b/code/codegen/src/main/resources/resgen/images/webp/xxhdpi_pizza_icon.webp new file mode 100644 index 0000000..7afd936 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/webp/xxhdpi_pizza_icon.webp differ diff --git a/code/codegen/src/main/resources/resgen/images/webp/xxxhdpi_bootleg_android_icon.webp b/code/codegen/src/main/resources/resgen/images/webp/xxxhdpi_bootleg_android_icon.webp new file mode 100644 index 0000000..f43c619 Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/webp/xxxhdpi_bootleg_android_icon.webp differ diff --git a/code/codegen/src/main/resources/resgen/images/webp/xxxhdpi_pizza_icon.webp b/code/codegen/src/main/resources/resgen/images/webp/xxxhdpi_pizza_icon.webp new file mode 100644 index 0000000..8ed3f8f Binary files /dev/null and b/code/codegen/src/main/resources/resgen/images/webp/xxxhdpi_pizza_icon.webp differ diff --git a/code/codegen/src/test/kotlin/com/android/gradle/replicator/codegen/CodeGenerationListenerTest.kt b/code/codegen/src/test/kotlin/com/android/gradle/replicator/codegen/CodeGenerationListenerTest.kt index 9a03ee7..575f77c 100644 --- a/code/codegen/src/test/kotlin/com/android/gradle/replicator/codegen/CodeGenerationListenerTest.kt +++ b/code/codegen/src/test/kotlin/com/android/gradle/replicator/codegen/CodeGenerationListenerTest.kt @@ -17,6 +17,7 @@ package com.android.gradle.replicator.codegen import com.android.gradle.replicator.codegen.kotlin.KotlinClassGenerator +import com.android.gradle.replicator.resourceModel.ResourceModel import com.google.common.truth.Truth import org.junit.Before import org.junit.Test @@ -78,10 +79,12 @@ class CodeGenerationListenerTest { SingleClassGenerator( generator = KotlinClassGenerator(PrettyPrintStream(PrintStream(outputStream)), listOf(listener)), params = params, + moduleName = "foo", packageName = "foo.package", className = "FooClass", apiClassPicker = importClassPicker, implClassPicker = importClassPicker, + resourceModel = ResourceModel(), random = random).generate() Mockito.`when`(random.nextInt(1)).thenReturn(0) // use first import in list. diff --git a/code/codegen/src/test/kotlin/com/android/gradle/replicator/resgen/AbstractResourceGenerationTest.kt b/code/codegen/src/test/kotlin/com/android/gradle/replicator/resgen/AbstractResourceGenerationTest.kt index 1f77bf5..da285bc 100644 --- a/code/codegen/src/test/kotlin/com/android/gradle/replicator/resgen/AbstractResourceGenerationTest.kt +++ b/code/codegen/src/test/kotlin/com/android/gradle/replicator/resgen/AbstractResourceGenerationTest.kt @@ -17,7 +17,7 @@ package com.android.gradle.replicator.resgen -import com.android.gradle.replicator.resgen.resourceModel.ResourceModel +import com.android.gradle.replicator.resourceModel.ResourceModel import com.android.gradle.replicator.resgen.util.ResgenConstants import com.android.gradle.replicator.resgen.util.UniqueIdGenerator import org.junit.After diff --git a/code/codegen/src/test/kotlin/com/android/gradle/replicator/resgen/ResourceGenerationIntegrationTest.kt b/code/codegen/src/test/kotlin/com/android/gradle/replicator/resgen/ResourceGenerationIntegrationTest.kt index 7b0c2d1..df21bb7 100644 --- a/code/codegen/src/test/kotlin/com/android/gradle/replicator/resgen/ResourceGenerationIntegrationTest.kt +++ b/code/codegen/src/test/kotlin/com/android/gradle/replicator/resgen/ResourceGenerationIntegrationTest.kt @@ -6,20 +6,22 @@ import org.junit.Test class ResourceGenerationIntegrationTest: AbstractResourceGenerationTest() { @Test fun testFullResourceGeneration() { - val modelFile = testFolder.newFile("resource-metadata.json") + val metadataFile = testFolder.newFile("resource-metadata.json") + val resModelFile = testFolder.newFile("resource-model.json") val propertiesFile = testFolder.newFile("generation.properties") val androidOutputFolder = testFolder.newFolder("res") val javaOutputFolder = testFolder.newFolder("resources") val assetOutputFolder = testFolder.newFolder("assets") - modelFile.writeText(MODEL_FILE) + metadataFile.writeText(MODEL_FILE) propertiesFile.writeText(PROPERTIES_FILE) Main().process(arrayOf( - "--resJson", modelFile.absolutePath, + "--resJson", metadataFile.absolutePath, "--androidOutput", androidOutputFolder.absolutePath, "--javaOutput", javaOutputFolder.absolutePath, "--assetOutput", assetOutputFolder.absolutePath, + "--resModel", resModelFile.absolutePath, "--generationProperties", propertiesFile.absolutePath // Use default seed )) @@ -53,13 +55,14 @@ class ResourceGenerationIntegrationTest: AbstractResourceGenerationTest() { "mipmap-xxhdpi/image_aaaa.webp", "mipmap-xxhdpi/image_aaab.webp", "values-night", - "values-night/values_aaae.xml", + "values-night/values_aaag.xml", + "values-night/values_aaaf.xml", "values", "values/values_aaaa.xml", "values/values_aaab.xml", "values/values_aaac.xml", "values/values_aaad.xml", - //"values/values_aaae.xml", themes still not supported + "values/values_aaae.xml", "menu", "mipmap-xhdpi", "mipmap-xhdpi/image_aaaa.webp", diff --git a/code/codegen/src/test/kotlin/com/android/gradle/replicator/resgen/ValueGenerationUnitTest.kt b/code/codegen/src/test/kotlin/com/android/gradle/replicator/resgen/ValueGenerationUnitTest.kt index a597bbd..3c614dd 100644 --- a/code/codegen/src/test/kotlin/com/android/gradle/replicator/resgen/ValueGenerationUnitTest.kt +++ b/code/codegen/src/test/kotlin/com/android/gradle/replicator/resgen/ValueGenerationUnitTest.kt @@ -60,6 +60,7 @@ class ValueGenerationUnitTest: AbstractResourceGenerationTest() { val generatedValues1 = File(testFolder.root, "values_aaaa.xml").readText() val generatedValues2 = File(testFolder.root, "values_aaab.xml").readText() + val generatedValues3 = File(testFolder.root, "values_aaac.xml").readText() @Language("xml") val expectedValues1 = """ @@ -92,8 +93,11 @@ class ValueGenerationUnitTest: AbstractResourceGenerationTest() { + 105 + 106 + 107 - + 110 111 112 @@ -132,49 +136,49 @@ class ValueGenerationUnitTest: AbstractResourceGenerationTest() { + 291 292 293 294 295 - 296 - 297 - 298 - 299 + + 300 301 302 303 304 305 - 306 - 307 - 308 - 309 - - - 314 - 315 - 316 - 317 - 318 - 319 - 320 - 321 - 322 - 323 - 324 - 325 - 326 - 327 - 328 - 329 - 330 - 331 - 332 """.trimIndent() + @Language("xml") + val expectedValues3 = """ + + + + + """.trimIndent() Truth.assertThat(generatedValues1).isEqualTo(expectedValues1) Truth.assertThat(generatedValues2).isEqualTo(expectedValues2) + Truth.assertThat(generatedValues3).isEqualTo(expectedValues3) } } \ No newline at end of file diff --git a/code/plugin/src/main/kotlin/com/android/gradle/replicator/codegen/plugin/CodegenPlugin.kt b/code/plugin/src/main/kotlin/com/android/gradle/replicator/codegen/plugin/CodegenPlugin.kt index 0d7d090..ef15909 100644 --- a/code/plugin/src/main/kotlin/com/android/gradle/replicator/codegen/plugin/CodegenPlugin.kt +++ b/code/plugin/src/main/kotlin/com/android/gradle/replicator/codegen/plugin/CodegenPlugin.kt @@ -38,6 +38,8 @@ class CodegenPlugin: AbstractCodeGenPlugin() { current.name } + val resourceModelFile = project.layout.projectDirectory.file("generated-resource-model.json") + val generateResourcesTask = project.tasks.register( "generateResources", GenerateResources::class.java) { task -> @@ -47,6 +49,7 @@ class CodegenPlugin: AbstractCodeGenPlugin() { task.androidOutputDirectory.set(project.layout.projectDirectory.dir("src/main/res")) task.javaOutputDirectory.set(project.layout.projectDirectory.dir("src/main/resources")) task.assetOutputDirectory.set(project.layout.projectDirectory.dir("src/main/assets")) + task.resourceModelFile.set(resourceModelFile) task.generationProperties.set(project.rootProject.layout.projectDirectory.file("generation.properties")) } @@ -178,6 +181,7 @@ class CodegenPlugin: AbstractCodeGenPlugin() { GenerateCode::class.java) { task -> task.parameters.set(generateTask.flatMap(GenerateCodegenParamsTask::paramsFile)) + task.resourceModelFile.set(resourceModelFile) task.outputDirectory.set( project.layout.projectDirectory.dir("src/main/java") ) diff --git a/code/plugin/src/main/kotlin/com/android/gradle/replicator/codegen/plugin/GenerateCode.kt b/code/plugin/src/main/kotlin/com/android/gradle/replicator/codegen/plugin/GenerateCode.kt index 73f89a8..29b6fc3 100644 --- a/code/plugin/src/main/kotlin/com/android/gradle/replicator/codegen/plugin/GenerateCode.kt +++ b/code/plugin/src/main/kotlin/com/android/gradle/replicator/codegen/plugin/GenerateCode.kt @@ -28,6 +28,9 @@ abstract class GenerateCode: DefaultTask() { @get:InputFile abstract val parameters: RegularFileProperty + @get:InputFile + abstract val resourceModelFile: RegularFileProperty + @get:OutputDirectory abstract val outputDirectory: DirectoryProperty @@ -37,6 +40,7 @@ abstract class GenerateCode: DefaultTask() { Main().process( arrayOf( "--module", path.removeSuffix(":$name").removePrefix(":").replace(':', '_'), + "--resModel", resourceModelFile.get().asFile.absolutePath, "-i", parameters.get().asFile.absolutePath, "-o", outputDirectory.get().asFile.absolutePath ) diff --git a/code/plugin/src/main/kotlin/com/android/gradle/replicator/codegen/plugin/GenerateResources.kt b/code/plugin/src/main/kotlin/com/android/gradle/replicator/codegen/plugin/GenerateResources.kt index 17cf94f..f488fa0 100644 --- a/code/plugin/src/main/kotlin/com/android/gradle/replicator/codegen/plugin/GenerateResources.kt +++ b/code/plugin/src/main/kotlin/com/android/gradle/replicator/codegen/plugin/GenerateResources.kt @@ -23,6 +23,7 @@ import org.gradle.api.provider.Property import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction import kotlin.random.Random @@ -40,6 +41,9 @@ abstract class GenerateResources: DefaultTask() { @get:OutputDirectory abstract val androidOutputDirectory: DirectoryProperty + @get:OutputFile + abstract val resourceModelFile: RegularFileProperty + @get:OutputDirectory abstract val javaOutputDirectory: DirectoryProperty @@ -56,6 +60,7 @@ abstract class GenerateResources: DefaultTask() { "--androidOutput", androidOutputDirectory.get().asFile.absolutePath, "--javaOutput", javaOutputDirectory.get().asFile.absolutePath, "--assetOutput", assetOutputDirectory.get().asFile.absolutePath, + "--resModel", resourceModelFile.get().asFile.absolutePath, "--generationProperties", generationProperties.get().asFile.absolutePath, "--seed", randomizer.nextInt().toString() )