Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/io/github/atriusx/Compositor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Compositor : Plugin<Settings> {
logger.debug("Swapped out dependency '$dependency' for project: $path")
}
}

logger.debug("Compositor plugin applied!")
}

private fun DependencySubstitutions.swap(dependency: String, path: String) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/io/github/atriusx/CompositorProjectAuto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class CompositorProjectAuto : Plugin<Project> {
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) {
Expand Down
25 changes: 24 additions & 1 deletion src/main/kotlin/io/github/atriusx/config/CompositesConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.atriusx.config

import org.slf4j.LoggerFactory
import kotlin.collections.iterator

/**
Expand Down Expand Up @@ -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<String, Any>, 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 <T> MutableList<T>.removeLast(count: Int) = this.apply {
repeat(count) { removeLast() }
}
Expand All @@ -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)
}
}
7 changes: 5 additions & 2 deletions src/main/kotlin/io/github/atriusx/util/YamlUtil.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down