diff --git a/README.md b/README.md index f7584cb..d6f5098 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Compositor -Compositor is an experimental Gradle plugin which exists to simplify the process of defining composite builds in gradle. +Compositor is a Gradle plugin which exists to simplify the process of defining composite builds in gradle. The primary goal of this plugin is to function as a development aid. ## Primary Purpose @@ -149,9 +149,9 @@ composites: In the configuration above, this replaces `some.external.complex:dependency` with the subproject `example` located in the `../some/local/project` directory. If no project specifier is provided, it will default to the root project. -**Note:** Due to limitations with Gradle, you can only reference one subproject at a time. I've attempted to find ways around -this but have so far not had much success. This will likely be a rare edge-case for most, but if you run into this scenario, you -may need to find a way to test each substitution independently. +**Note:** Due to limitations with Gradle, you may only be able to substitute one submodule from a multi-module project +at a time. I've attempted to find ways around this but have so far not had much success. This will likely be a rare +edge-case for most, but if you run into this scenario, you may need to find a way to test each substitution independently. ### Managing Composites diff --git a/src/main/kotlin/io/github/atriusx/Compositor.kt b/src/main/kotlin/io/github/atriusx/Compositor.kt index 4a462e1..90f7820 100644 --- a/src/main/kotlin/io/github/atriusx/Compositor.kt +++ b/src/main/kotlin/io/github/atriusx/Compositor.kt @@ -50,6 +50,8 @@ class Compositor : Plugin { logger.debug("Swapped out dependency '$dependency' for project: $path") } } + + logger.debug("Compositor plugin applied!") } private fun DependencySubstitutions.swap(dependency: String, path: String) { diff --git a/src/main/kotlin/io/github/atriusx/CompositorProjectAuto.kt b/src/main/kotlin/io/github/atriusx/CompositorProjectAuto.kt index 924ae32..5b4a9b0 100644 --- a/src/main/kotlin/io/github/atriusx/CompositorProjectAuto.kt +++ b/src/main/kotlin/io/github/atriusx/CompositorProjectAuto.kt @@ -49,6 +49,8 @@ class CompositorProjectAuto : Plugin { setEnabled(file, false) logger.debug("Disabled ${file.name} configuration.") } + + logger.debug("Automatically applied CompositorProjectAuto plugin to project '${target.name}'") } private fun Project.compositorTask(taskName: String, action: () -> Unit) { diff --git a/src/main/kotlin/io/github/atriusx/config/CompositesConfig.kt b/src/main/kotlin/io/github/atriusx/config/CompositesConfig.kt index 919b385..b04e904 100644 --- a/src/main/kotlin/io/github/atriusx/config/CompositesConfig.kt +++ b/src/main/kotlin/io/github/atriusx/config/CompositesConfig.kt @@ -1,5 +1,6 @@ package io.github.atriusx.config +import org.slf4j.LoggerFactory import kotlin.collections.iterator /** @@ -35,20 +36,36 @@ data class CompositesConfig( path.addAll(next) // Apply value if (value is String) { - history[path.formatQualifier()] = value + val qualifier = path.formatQualifier() + history[qualifier] = value + logger.debug("Found substituted dependency '$qualifier' with '$value'") path.removeLast(next.size) + continue } + val ymlPath = path.joinToString(".") // Recursively check next layer if (value is Map<*, *>) { + logger.debug("Found nested scope: $ymlPath") flattenPaths(value as? Map, path, history) // Remove all recently added scopes path.removeLast(next.size) + continue } + + logger.warn("Invalid value provided for '$ymlPath', expected path or nested scope, but found: $value") + } + + logger.info("Finished processing composites configuration, found ${history.size} total substitutions.") + + for ((dependency, path) in history) { + logger.debug("Mapped dependency '$dependency' to substitute at location: '$path'") } return history } + // Kotlin doesn't have a built-in way to remove multiple elements from the end of a list in-place, so we can just + // repeat this operation until we've removed the desired number of elements private fun MutableList.removeLast(count: Int) = this.apply { repeat(count) { removeLast() } } @@ -57,4 +74,10 @@ data class CompositesConfig( 0, 1 -> firstOrNull() ?: "" else -> dropLast(1).joinToString(".") + ":" + last() } + + companion object { + + private val logger = LoggerFactory + .getLogger(CompositesConfig::class.java) + } } \ No newline at end of file diff --git a/src/main/kotlin/io/github/atriusx/util/YamlUtil.kt b/src/main/kotlin/io/github/atriusx/util/YamlUtil.kt index d3ec54f..8cbecd9 100644 --- a/src/main/kotlin/io/github/atriusx/util/YamlUtil.kt +++ b/src/main/kotlin/io/github/atriusx/util/YamlUtil.kt @@ -1,5 +1,6 @@ package io.github.atriusx.util +import com.fasterxml.jackson.core.JacksonException import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator import com.fasterxml.jackson.dataformat.yaml.YAMLMapper import org.slf4j.LoggerFactory @@ -20,13 +21,15 @@ object YamlUtil { logger.debug("Attempting to parse ${file.name} content as YAML...") yaml.readValue(file, type.java) } catch (e: IOException) { - logger.error("Failed to parse file '${file.path}', error: ${e.message}") + logger.error("Failed to parse file '${file.path}', received error: ${e.message}") null } - fun write(file: File, value: Any) { + fun write(file: File, value: Any) = try { logger.debug("Writing provided content to ${file.name}...") yaml.writeValue(file, value) + } catch (e: IOException) { + logger.error("Failed to write content to file '${file.path}', received error: ${e.message}") } private val logger = LoggerFactory