From ddd60fc339079fc272b375804791a453faf5d72b Mon Sep 17 00:00:00 2001 From: Micah Jo Date: Tue, 19 Mar 2024 12:32:11 -0700 Subject: [PATCH] Update addCustomAsset and addCustomSourceFolders to highlight the usage of SourceDirectories.Layered and SourceDirectories.Flat and update their names to be addGeneratedSourceFolder and addCustomSourceType. Bug: n/a Test: this is a test Change-Id: Ie35723e6b4d6306fd205c579001c6c7e03ab0b31 --- BUILD | 4 +- .../README.md | 12 ++++ .../app/build.gradle.kts | 4 +- .../app/src/main/AndroidManifest.xml | 0 .../build-logic/gradle.properties | 0 .../build-logic/gradle/libs.versions.toml | 0 .../build-logic/plugins/build.gradle.kts | 0 .../src/main/kotlin/AddCustomSources.kt | 0 .../plugins/src/main/kotlin/CustomPlugin.kt | 10 +++- .../src/main/kotlin/DisplayAllSources.kt | 6 ++ .../build-logic/settings.gradle.kts | 0 .../build.gradle.kts | 0 .../gradle.properties | 0 .../gradle/libs.versions.toml | 0 .../recipe_metadata.toml | 2 + .../settings.gradle.kts | 2 +- .../README.md | 29 +++++----- .../app/build.gradle.kts | 0 .../app/src/main/AndroidManifest.xml | 0 .../build-logic/gradle.properties | 0 .../build-logic/gradle/libs.versions.toml | 0 .../build-logic/plugins/build.gradle.kts | 4 +- .../plugins/src/main/kotlin/CustomPlugin.kt | 56 +++++++++++-------- .../build-logic/settings.gradle.kts | 0 .../build.gradle.kts | 0 .../gradle.properties | 0 .../gradle/libs.versions.toml | 0 .../recipe_metadata.toml | 6 +- .../settings.gradle.kts | 2 +- recipes/legacyTaskBridging/README.md | 5 -- .../plugins/src/main/kotlin/CustomPlugin.kt | 10 +--- 31 files changed, 92 insertions(+), 60 deletions(-) rename recipes/{addCustomSourceFolders => addCustomSourceType}/README.md (75%) rename recipes/{addCustomSourceFolders => addCustomSourceType}/app/build.gradle.kts (89%) rename recipes/{addCustomAsset => addCustomSourceType}/app/src/main/AndroidManifest.xml (100%) rename recipes/{addCustomAsset => addCustomSourceType}/build-logic/gradle.properties (100%) rename recipes/{addCustomAsset => addCustomSourceType}/build-logic/gradle/libs.versions.toml (100%) rename recipes/{addCustomAsset => addCustomSourceType}/build-logic/plugins/build.gradle.kts (100%) rename recipes/{addCustomSourceFolders => addCustomSourceType}/build-logic/plugins/src/main/kotlin/AddCustomSources.kt (100%) rename recipes/{addCustomSourceFolders => addCustomSourceType}/build-logic/plugins/src/main/kotlin/CustomPlugin.kt (81%) rename recipes/{addCustomSourceFolders => addCustomSourceType}/build-logic/plugins/src/main/kotlin/DisplayAllSources.kt (82%) rename recipes/{addCustomAsset => addCustomSourceType}/build-logic/settings.gradle.kts (100%) rename recipes/{addCustomAsset => addCustomSourceType}/build.gradle.kts (100%) rename recipes/{addCustomAsset => addCustomSourceType}/gradle.properties (100%) rename recipes/{addCustomAsset => addCustomSourceType}/gradle/libs.versions.toml (100%) rename recipes/{addCustomSourceFolders => addCustomSourceType}/recipe_metadata.toml (93%) rename recipes/{addCustomAsset => addCustomSourceType}/settings.gradle.kts (95%) rename recipes/{addCustomAsset => addGeneratedSourceFolder}/README.md (56%) rename recipes/{addCustomAsset => addGeneratedSourceFolder}/app/build.gradle.kts (100%) rename recipes/{addCustomSourceFolders => addGeneratedSourceFolder}/app/src/main/AndroidManifest.xml (100%) rename recipes/{addCustomSourceFolders => addGeneratedSourceFolder}/build-logic/gradle.properties (100%) rename recipes/{addCustomSourceFolders => addGeneratedSourceFolder}/build-logic/gradle/libs.versions.toml (100%) rename recipes/{addCustomSourceFolders => addGeneratedSourceFolder}/build-logic/plugins/build.gradle.kts (90%) rename recipes/{addCustomAsset => addGeneratedSourceFolder}/build-logic/plugins/src/main/kotlin/CustomPlugin.kt (66%) rename recipes/{addCustomSourceFolders => addGeneratedSourceFolder}/build-logic/settings.gradle.kts (100%) rename recipes/{addCustomSourceFolders => addGeneratedSourceFolder}/build.gradle.kts (100%) rename recipes/{addCustomSourceFolders => addGeneratedSourceFolder}/gradle.properties (100%) rename recipes/{addCustomSourceFolders => addGeneratedSourceFolder}/gradle/libs.versions.toml (100%) rename recipes/{addCustomAsset => addGeneratedSourceFolder}/recipe_metadata.toml (85%) rename recipes/{addCustomSourceFolders => addGeneratedSourceFolder}/settings.gradle.kts (95%) diff --git a/BUILD b/BUILD index 1d78d1d5..202555f4 100644 --- a/BUILD +++ b/BUILD @@ -63,7 +63,7 @@ recipe_test( ) recipe_test( - name = "addCustomAsset", + name = "addGeneratedSourceFolder", ) recipe_test( @@ -115,7 +115,7 @@ recipe_test( ) recipe_test( - name = "addCustomSourceFolders", + name = "addCustomSourceType", ) recipe_test( diff --git a/recipes/addCustomSourceFolders/README.md b/recipes/addCustomSourceType/README.md similarity index 75% rename from recipes/addCustomSourceFolders/README.md rename to recipes/addCustomSourceType/README.md index 96a4d697..0cbb7c38 100644 --- a/recipes/addCustomSourceFolders/README.md +++ b/recipes/addCustomSourceType/README.md @@ -4,10 +4,22 @@ This sample shows how to add a new custom source folders to the Variant for newl The source folder will not be used by any AGP tasks (since we do not know about it), however, it can be used by plugins and tasks participating into the Variant API callbacks. +In this recipe, a custom source type is registered in the app's [build.gradle.kts](app/build.gradle.kts): + +``` +androidComponents { + registerSourceType("toml") +} +``` + To access the custom sources, you just need to use `sourceFolders.set(variant.sources.getByName("toml").getAll())` which can be used as [Task] input directly. +There are two types of [`SourceDirectories`](https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/variant/SourceDirectories): +[`Flat`](https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/variant/SourceDirectories.Flat) and [`Layered`](https://developer.android.com/reference/tools/gradle-api/8.0/com/android/build/api/variant/SourceDirectories.Layered). +Custom sources are always of type `Flat`, meaning the directories are stored in type `Provider>`. + To add a folder which content will be generated during execution time by [Task], you need to use [SourceDirectories.addGeneratedSourceDirectory] and the pointer to the output folder where source files will be generated. diff --git a/recipes/addCustomSourceFolders/app/build.gradle.kts b/recipes/addCustomSourceType/app/build.gradle.kts similarity index 89% rename from recipes/addCustomSourceFolders/app/build.gradle.kts rename to recipes/addCustomSourceType/app/build.gradle.kts index db2e6797..08be2c7b 100644 --- a/recipes/addCustomSourceFolders/app/build.gradle.kts +++ b/recipes/addCustomSourceType/app/build.gradle.kts @@ -17,11 +17,11 @@ plugins { alias(libs.plugins.android.application) alias(libs.plugins.kotlin.android) - id("android.recipes.customSourceFolders") + id("android.recipes.custom_plugin") } android { - namespace = "com.example.android.recipes.customSourceFolders" + namespace = "com.example.android.recipes.recipe" compileSdk = $COMPILE_SDK defaultConfig { minSdk = $MINIMUM_SDK diff --git a/recipes/addCustomAsset/app/src/main/AndroidManifest.xml b/recipes/addCustomSourceType/app/src/main/AndroidManifest.xml similarity index 100% rename from recipes/addCustomAsset/app/src/main/AndroidManifest.xml rename to recipes/addCustomSourceType/app/src/main/AndroidManifest.xml diff --git a/recipes/addCustomAsset/build-logic/gradle.properties b/recipes/addCustomSourceType/build-logic/gradle.properties similarity index 100% rename from recipes/addCustomAsset/build-logic/gradle.properties rename to recipes/addCustomSourceType/build-logic/gradle.properties diff --git a/recipes/addCustomAsset/build-logic/gradle/libs.versions.toml b/recipes/addCustomSourceType/build-logic/gradle/libs.versions.toml similarity index 100% rename from recipes/addCustomAsset/build-logic/gradle/libs.versions.toml rename to recipes/addCustomSourceType/build-logic/gradle/libs.versions.toml diff --git a/recipes/addCustomAsset/build-logic/plugins/build.gradle.kts b/recipes/addCustomSourceType/build-logic/plugins/build.gradle.kts similarity index 100% rename from recipes/addCustomAsset/build-logic/plugins/build.gradle.kts rename to recipes/addCustomSourceType/build-logic/plugins/build.gradle.kts diff --git a/recipes/addCustomSourceFolders/build-logic/plugins/src/main/kotlin/AddCustomSources.kt b/recipes/addCustomSourceType/build-logic/plugins/src/main/kotlin/AddCustomSources.kt similarity index 100% rename from recipes/addCustomSourceFolders/build-logic/plugins/src/main/kotlin/AddCustomSources.kt rename to recipes/addCustomSourceType/build-logic/plugins/src/main/kotlin/AddCustomSources.kt diff --git a/recipes/addCustomSourceFolders/build-logic/plugins/src/main/kotlin/CustomPlugin.kt b/recipes/addCustomSourceType/build-logic/plugins/src/main/kotlin/CustomPlugin.kt similarity index 81% rename from recipes/addCustomSourceFolders/build-logic/plugins/src/main/kotlin/CustomPlugin.kt rename to recipes/addCustomSourceType/build-logic/plugins/src/main/kotlin/CustomPlugin.kt index 425e94d5..ffde1c21 100644 --- a/recipes/addCustomSourceFolders/build-logic/plugins/src/main/kotlin/CustomPlugin.kt +++ b/recipes/addCustomSourceType/build-logic/plugins/src/main/kotlin/CustomPlugin.kt @@ -54,9 +54,15 @@ class CustomPlugin : Plugin { it.addGeneratedSourceDirectory(addSourceTaskProvider, AddCustomSources::outputFolder) } - project.tasks.register("${variant.name}DisplayAllSources") { - //to print all directories that are part of `toml` source type + // -- Verification -- + // the following is just to validate the recipe and is not actually part of the recipe itself + val taskName = "${variant.name}DisplayAllSources" + project.tasks.register(taskName) { + // to print all directories that are part of `toml` source type + // `variant.sources.getByName("toml")` here and any other custom source is of type + // SourceDirectories.Flat sourceFolders.set(variant.sources.getByName("toml").all) + output.set(project.layout.buildDirectory.dir("intermediates/$taskName")) } } } diff --git a/recipes/addCustomSourceFolders/build-logic/plugins/src/main/kotlin/DisplayAllSources.kt b/recipes/addCustomSourceType/build-logic/plugins/src/main/kotlin/DisplayAllSources.kt similarity index 82% rename from recipes/addCustomSourceFolders/build-logic/plugins/src/main/kotlin/DisplayAllSources.kt rename to recipes/addCustomSourceType/build-logic/plugins/src/main/kotlin/DisplayAllSources.kt index b4bae912..7e192ce3 100644 --- a/recipes/addCustomSourceFolders/build-logic/plugins/src/main/kotlin/DisplayAllSources.kt +++ b/recipes/addCustomSourceType/build-logic/plugins/src/main/kotlin/DisplayAllSources.kt @@ -26,6 +26,12 @@ import java.nio.file.Path abstract class DisplayAllSources: DefaultTask() { + // In order for the task to be up-to-date when the inputs have not changed, + // the task must declare an output, even if it's not used. Tasks with no + // output are always run regardless of whether the inputs changed + @get:OutputDirectory + abstract val output: DirectoryProperty + @get:InputFiles abstract val sourceFolders: ListProperty diff --git a/recipes/addCustomAsset/build-logic/settings.gradle.kts b/recipes/addCustomSourceType/build-logic/settings.gradle.kts similarity index 100% rename from recipes/addCustomAsset/build-logic/settings.gradle.kts rename to recipes/addCustomSourceType/build-logic/settings.gradle.kts diff --git a/recipes/addCustomAsset/build.gradle.kts b/recipes/addCustomSourceType/build.gradle.kts similarity index 100% rename from recipes/addCustomAsset/build.gradle.kts rename to recipes/addCustomSourceType/build.gradle.kts diff --git a/recipes/addCustomAsset/gradle.properties b/recipes/addCustomSourceType/gradle.properties similarity index 100% rename from recipes/addCustomAsset/gradle.properties rename to recipes/addCustomSourceType/gradle.properties diff --git a/recipes/addCustomAsset/gradle/libs.versions.toml b/recipes/addCustomSourceType/gradle/libs.versions.toml similarity index 100% rename from recipes/addCustomAsset/gradle/libs.versions.toml rename to recipes/addCustomSourceType/gradle/libs.versions.toml diff --git a/recipes/addCustomSourceFolders/recipe_metadata.toml b/recipes/addCustomSourceType/recipe_metadata.toml similarity index 93% rename from recipes/addCustomSourceFolders/recipe_metadata.toml rename to recipes/addCustomSourceType/recipe_metadata.toml index 03a0eeec..4196beb3 100644 --- a/recipes/addCustomSourceFolders/recipe_metadata.toml +++ b/recipes/addCustomSourceType/recipe_metadata.toml @@ -26,9 +26,11 @@ index = [ "Call chains/androidComponents.onVariants {}", "Call chains/variant.sources.*.addGeneratedSourceDirectory()", "Call chains/variant.sources.*.addStaticSourceDirectory()", + "Call chains/variant.sources.*.all", "APIs/SourceDirectories.addGeneratedSourceDirectory()", "APIs/SourceDirectories.addStaticSourceDirectory()", "APIs/Component.sources", "registerSourceType", "SourceDirectories.add", + "SourceDirectories.Flat" ] diff --git a/recipes/addCustomAsset/settings.gradle.kts b/recipes/addCustomSourceType/settings.gradle.kts similarity index 95% rename from recipes/addCustomAsset/settings.gradle.kts rename to recipes/addCustomSourceType/settings.gradle.kts index 16e1ab50..44227979 100644 --- a/recipes/addCustomAsset/settings.gradle.kts +++ b/recipes/addCustomSourceType/settings.gradle.kts @@ -14,7 +14,7 @@ * limitations under the License. */ -rootProject.name = "addCustomAsset" +rootProject.name = "addCustomSourceType" pluginManagement { includeBuild("build-logic") diff --git a/recipes/addCustomAsset/README.md b/recipes/addGeneratedSourceFolder/README.md similarity index 56% rename from recipes/addCustomAsset/README.md rename to recipes/addGeneratedSourceFolder/README.md index 56f21fe1..f2d80c96 100644 --- a/recipes/addCustomAsset/README.md +++ b/recipes/addGeneratedSourceFolder/README.md @@ -1,6 +1,6 @@ -# Adding source folder with dynamic content. +# Adding source folder with dynamic content -This recipe show how you can add a source folder to the set of source folders for a specific type of +This recipe shows how you can add a source folder to the set of source folders for a specific type of android source files. In this example, we add a source folder to Android's `assets`. The source folder content is provided by a Task and it is therefore dynamic. @@ -8,10 +8,15 @@ In the Variant API, the source folders are accessible through the `Component.sou will provide access to all the variant's source folders for each source type. Therefore, other types of android source files can be extended in a similar way like java, kotlin, java resources, -android resources, shaders, etc... See `Component.sources` for the complete list. +android resources, shaders, etc... See [`Component.sources`](https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/variant/Sources) for the complete list. -In this recipe, we use the `SourceDirectories.addGeneratedSourceDirectory` to add a new folder for `assets` -processing. You can extrapolate the same mechanism for other types of source files. +There are two types of [`SourceDirectories`](https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/variant/SourceDirectories): +[`Flat`](https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/variant/SourceDirectories.Flat) and [`Layered`](https://developer.android.com/reference/tools/gradle-api/8.0/com/android/build/api/variant/SourceDirectories.Layered). +In this recipe, we use `assets`, which are of type `Layered`, meaning the directories are stored in type +`Provider>>`. + +We use `SourceDirectories.addGeneratedSourceDirectory` to add a new folder for `assets` processing. You can extrapolate +the same mechanism for other types of source files. | Module | Content | |----------------------------|------------------------------------------------------------------------------| @@ -20,7 +25,7 @@ processing. You can extrapolate the same mechanism for other types of source fil ## Details -### Dynamically generated sources. +### Dynamically generated sources When you need to generate source files dynamically (based on other source files for instance), you should do so in a Task with proper Input and Output declarations so you get correct up-to-date checks and caching. @@ -31,18 +36,14 @@ Once the `TaskProvider` is created, you need to use `SourceDirectories.addGenera output as a new source folder. ``` variant.sources.assets?.addGeneratedSourceDirectory( - assetCreationTask, - AssetCreatorTask::outputDirectory) + assetCreationTask, + AssetCreatorTask::outputDirectory) ``` ### Run the example To run the examples, you can just do: + ``` -./gradlew debugVerifyAsset -``` -and the output should be: +./gradlew :app:verifyDebugAsset ``` -> Task :app:debugVerifyAsset -Success: Found asset in resulting APK ! -``` \ No newline at end of file diff --git a/recipes/addCustomAsset/app/build.gradle.kts b/recipes/addGeneratedSourceFolder/app/build.gradle.kts similarity index 100% rename from recipes/addCustomAsset/app/build.gradle.kts rename to recipes/addGeneratedSourceFolder/app/build.gradle.kts diff --git a/recipes/addCustomSourceFolders/app/src/main/AndroidManifest.xml b/recipes/addGeneratedSourceFolder/app/src/main/AndroidManifest.xml similarity index 100% rename from recipes/addCustomSourceFolders/app/src/main/AndroidManifest.xml rename to recipes/addGeneratedSourceFolder/app/src/main/AndroidManifest.xml diff --git a/recipes/addCustomSourceFolders/build-logic/gradle.properties b/recipes/addGeneratedSourceFolder/build-logic/gradle.properties similarity index 100% rename from recipes/addCustomSourceFolders/build-logic/gradle.properties rename to recipes/addGeneratedSourceFolder/build-logic/gradle.properties diff --git a/recipes/addCustomSourceFolders/build-logic/gradle/libs.versions.toml b/recipes/addGeneratedSourceFolder/build-logic/gradle/libs.versions.toml similarity index 100% rename from recipes/addCustomSourceFolders/build-logic/gradle/libs.versions.toml rename to recipes/addGeneratedSourceFolder/build-logic/gradle/libs.versions.toml diff --git a/recipes/addCustomSourceFolders/build-logic/plugins/build.gradle.kts b/recipes/addGeneratedSourceFolder/build-logic/plugins/build.gradle.kts similarity index 90% rename from recipes/addCustomSourceFolders/build-logic/plugins/build.gradle.kts rename to recipes/addGeneratedSourceFolder/build-logic/plugins/build.gradle.kts index 4cea7e70..0608834d 100644 --- a/recipes/addCustomSourceFolders/build-logic/plugins/build.gradle.kts +++ b/recipes/addGeneratedSourceFolder/build-logic/plugins/build.gradle.kts @@ -32,8 +32,8 @@ dependencies { gradlePlugin { plugins { - create("customSourceFoldersPlugin") { - id = "android.recipes.customSourceFolders" + create("customPlugin") { + id = "android.recipes.custom_plugin" implementationClass = "CustomPlugin" } } diff --git a/recipes/addCustomAsset/build-logic/plugins/src/main/kotlin/CustomPlugin.kt b/recipes/addGeneratedSourceFolder/build-logic/plugins/src/main/kotlin/CustomPlugin.kt similarity index 66% rename from recipes/addCustomAsset/build-logic/plugins/src/main/kotlin/CustomPlugin.kt rename to recipes/addGeneratedSourceFolder/build-logic/plugins/src/main/kotlin/CustomPlugin.kt index f3e178c2..cee3e260 100644 --- a/recipes/addCustomAsset/build-logic/plugins/src/main/kotlin/CustomPlugin.kt +++ b/recipes/addGeneratedSourceFolder/build-logic/plugins/src/main/kotlin/CustomPlugin.kt @@ -15,23 +15,25 @@ */ import com.android.build.api.variant.ApplicationAndroidComponentsExtension -import com.android.build.api.variant.BuiltArtifactsLoader -import com.android.build.api.artifact.MultipleArtifact import com.android.build.api.artifact.SingleArtifact import com.android.build.gradle.AppPlugin import java.io.File -import java.util.jar.JarFile import org.gradle.api.DefaultTask import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.file.Directory import org.gradle.api.file.DirectoryProperty +import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Property import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction +import org.gradle.configurationcache.extensions.capitalized import org.gradle.kotlin.dsl.register import java.lang.IllegalStateException +import java.lang.RuntimeException /** * This custom plugin will register a task output as a generated source folder for @@ -58,7 +60,7 @@ class CustomPlugin : Plugin { ?.let { // create the task that will add new source files to the asset source folder. val assetCreationTask = - project.tasks.register("create${variant.name}Asset") + project.tasks.register("create${variant.name.capitalized()}Asset") // registers the newly created Task as the provider for a new generated // source folder for the 'assets' type. @@ -70,14 +72,18 @@ class CustomPlugin : Plugin { ) } - // create the verification task - project.tasks.register("${variant.name}VerifyAsset") { - output.set( - project.layout.buildDirectory.dir("intermediates/recipe/$it.name") - ) + // -- Verification -- + // the following is just to validate the recipe and is not actually part of the recipe itself + val taskName = "verify${variant.name.capitalized()}Asset" + project.tasks.register(taskName) { // the verifying task will look at the merged assets folder and ensure // the file added by the assetCreationTask is present. - assets.set(variant.artifacts.get(SingleArtifact.ASSETS)) + mergedAssets.set(variant.artifacts.get(SingleArtifact.ASSETS)) + // also verify that the file exists in `variant.sources.assets.all` + // Note: this should not be done in practice- it is only to demonstrate that the assets are a + // layered source type (SourceDirectories.Layered) + variant.sources.assets?.let { assetsAllSources.set(it.all) } + output.set(project.layout.buildDirectory.dir("intermediates/$taskName")) } } } @@ -100,29 +106,35 @@ abstract class AssetCreatorTask: DefaultTask() { } /** - * This task here to verify that the API does what is says. + * This task here to verify that the API does what it says. */ abstract class VerifyAssetTask : DefaultTask() { - // In order of the task to be up-to-date when the input has not changed, + // In order for the task to be up-to-date when the inputs have not changed, // the task must declare an output, even if it's not used. Tasks with no - // output are always run regardless of whether the inputs changed or not + // output are always run regardless of whether the inputs changed @get:OutputDirectory abstract val output: DirectoryProperty @get:InputDirectory @get:Optional - abstract val assets: DirectoryProperty + abstract val mergedAssets: DirectoryProperty + + @get:InputFiles + abstract val assetsAllSources: ListProperty> @TaskAction fun taskAction() { - File(assets.get().asFile, "custom_asset.txt").let { - if (it.exists()) { - println("Found ${it} in merged assets folder") - } else { - throw IllegalStateException("custom_asset.txt file not " + - "present in merged asset folder : ${assets.get().asFile}") - } + // Validate the assets artifact contains the expected file + if (!File(mergedAssets.get().asFile, "custom_asset.txt").exists()) { + throw RuntimeException("custom_asset.txt file not present in merged asset folder: " + + "${mergedAssets.get().asFile}") + } + + // Validate that `variant.sources.assets.all` contains the expected file + val addedDirectory = assetsAllSources.get().flatten().first { it.asFile.name == "createDebugAsset" } + if (!File(addedDirectory.asFile, "custom_asset.txt").exists()) { + throw RuntimeException("custom_asset.txt not present in assets all sources") } } -} \ No newline at end of file +} diff --git a/recipes/addCustomSourceFolders/build-logic/settings.gradle.kts b/recipes/addGeneratedSourceFolder/build-logic/settings.gradle.kts similarity index 100% rename from recipes/addCustomSourceFolders/build-logic/settings.gradle.kts rename to recipes/addGeneratedSourceFolder/build-logic/settings.gradle.kts diff --git a/recipes/addCustomSourceFolders/build.gradle.kts b/recipes/addGeneratedSourceFolder/build.gradle.kts similarity index 100% rename from recipes/addCustomSourceFolders/build.gradle.kts rename to recipes/addGeneratedSourceFolder/build.gradle.kts diff --git a/recipes/addCustomSourceFolders/gradle.properties b/recipes/addGeneratedSourceFolder/gradle.properties similarity index 100% rename from recipes/addCustomSourceFolders/gradle.properties rename to recipes/addGeneratedSourceFolder/gradle.properties diff --git a/recipes/addCustomSourceFolders/gradle/libs.versions.toml b/recipes/addGeneratedSourceFolder/gradle/libs.versions.toml similarity index 100% rename from recipes/addCustomSourceFolders/gradle/libs.versions.toml rename to recipes/addGeneratedSourceFolder/gradle/libs.versions.toml diff --git a/recipes/addCustomAsset/recipe_metadata.toml b/recipes/addGeneratedSourceFolder/recipe_metadata.toml similarity index 85% rename from recipes/addCustomAsset/recipe_metadata.toml rename to recipes/addGeneratedSourceFolder/recipe_metadata.toml index dd1bc801..7797748c 100644 --- a/recipes/addCustomAsset/recipe_metadata.toml +++ b/recipes/addGeneratedSourceFolder/recipe_metadata.toml @@ -13,7 +13,7 @@ min = "8.1.0" # Relevant Gradle tasks to run per recipe [gradleTasks] tasks = [ - "debugVerifyAsset" + ":app:verifyDebugAsset" ] # All the relevant metadata fields to create an index based on language/API/etc' @@ -28,6 +28,8 @@ index = [ "APIs/Component.artifacts", "APIs/Component.sources", "Call chains/variant.sources.*.addGeneratedSourceDirectory()", + "Call chains/variant.sources.*.all", "Call chains/variant.artifacts.get()", - "Call chains/androidComponents.onVariants {}" + "Call chains/androidComponents.onVariants {}", + "SourceDirectories.Layered" ] diff --git a/recipes/addCustomSourceFolders/settings.gradle.kts b/recipes/addGeneratedSourceFolder/settings.gradle.kts similarity index 95% rename from recipes/addCustomSourceFolders/settings.gradle.kts rename to recipes/addGeneratedSourceFolder/settings.gradle.kts index 10135d5d..a4ee2f45 100644 --- a/recipes/addCustomSourceFolders/settings.gradle.kts +++ b/recipes/addGeneratedSourceFolder/settings.gradle.kts @@ -14,7 +14,7 @@ * limitations under the License. */ -rootProject.name = "addCustomDourceFolders" +rootProject.name = "addGeneratedSourceFolder" pluginManagement { includeBuild("build-logic") diff --git a/recipes/legacyTaskBridging/README.md b/recipes/legacyTaskBridging/README.md index 323d9092..6e7b2673 100644 --- a/recipes/legacyTaskBridging/README.md +++ b/recipes/legacyTaskBridging/README.md @@ -68,8 +68,3 @@ To run the examples, you can just do: ``` ./gradlew debugVerifyAsset ``` -and the output should be: -``` -> Task :app:debugVerifyAsset -Success: Found asset in resulting APK ! -``` \ No newline at end of file diff --git a/recipes/legacyTaskBridging/build-logic/plugins/src/main/kotlin/CustomPlugin.kt b/recipes/legacyTaskBridging/build-logic/plugins/src/main/kotlin/CustomPlugin.kt index cf913677..4f10a7b8 100644 --- a/recipes/legacyTaskBridging/build-logic/plugins/src/main/kotlin/CustomPlugin.kt +++ b/recipes/legacyTaskBridging/build-logic/plugins/src/main/kotlin/CustomPlugin.kt @@ -123,13 +123,9 @@ abstract class VerifyAssetTask : DefaultTask() { @TaskAction fun taskAction() { - File(assets.get().asFile, "custom_asset.txt").let { - if (it.exists()) { - println("Found ${it} in merged assets folder") - } else { - throw IllegalStateException("custom_asset.txt file not " + - "present in merged asset folder : ${assets.get().asFile}") - } + if (!File(assets.get().asFile, "custom_asset.txt").exists()) { + throw RuntimeException("custom_asset.txt file not present in merged asset folder: " + + "${assets.get().asFile}") } } } \ No newline at end of file