diff --git a/config/ktlint/baseline.xml b/config/ktlint/baseline.xml
new file mode 100644
index 0000000..9814207
--- /dev/null
+++ b/config/ktlint/baseline.xml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/plugin/config/ktlint/baseline.xml b/plugin/config/ktlint/baseline.xml
new file mode 100644
index 0000000..70acc0f
--- /dev/null
+++ b/plugin/config/ktlint/baseline.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/plugin/detekt-baseline.xml b/plugin/detekt-baseline.xml
new file mode 100644
index 0000000..41da1be
--- /dev/null
+++ b/plugin/detekt-baseline.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ LongMethod:DependencyGraphTest.kt$DependencyGraphTest$@Test fun countsStatisticsWell()
+ MaxLineLength:ModuleTreeHeightAssert.kt$ModuleTreeHeightAssert$"Module $moduleName is allowed to have maximum height of $maxHeight, but has $height, problematic dependencies: ${longestPath.pathString()}"
+ MaxLineLength:ModuleTreeHeightAssert.kt$ModuleTreeHeightAssert$"Module Graph is allowed to have maximum height of $maxHeight, but has $height, problematic dependencies: ${longestPath.pathString()}"
+ MaxLineLength:OnAnyBuildAssertTest.kt$OnAnyBuildAssertTest$"""["App"(':app') -> "Implementation"(':core'), "App"(':app') -> "Implementation"(':feature')] not allowed by any of ['Implementation -> Api', 'App -> Api']"""
+ MaxLineLength:OnAnyBuildAssertTest.kt$OnAnyBuildAssertTest$"Module :app is allowed to have maximum height of 1, but has 2, problematic dependencies: :app -> :core -> :core-api"
+ ReturnCount:GradleDependencyGraphFactory.kt$GradleDependencyGraphFactory$fun create( project: Project, configurationsToLook: Set<String>, ): DependencyGraph
+ SerialVersionUIDInSerializableClass:DependencyGraph.kt$DependencyGraph$SerializableGraph : Serializable
+ SerialVersionUIDInSerializableClass:ModuleTreeHeightAssert.kt$ModuleTreeHeightAssert : GraphAssertSerializable
+ SwallowedException:ModuleGraphAssertionsPlugin.kt$ModuleGraphAssertionsPlugin$checkNotFound: UnknownTaskException
+ TooManyFunctions:DependencyGraph.kt$DependencyGraph
+ TooManyFunctions:ModuleGraphAssertionsPlugin.kt$ModuleGraphAssertionsPlugin : Plugin
+
+
diff --git a/plugin/src/main/kotlin/com/jraska/module/graph/DependencyGraph.kt b/plugin/src/main/kotlin/com/jraska/module/graph/DependencyGraph.kt
index 3a6275b..77f45bd 100644
--- a/plugin/src/main/kotlin/com/jraska/module/graph/DependencyGraph.kt
+++ b/plugin/src/main/kotlin/com/jraska/module/graph/DependencyGraph.kt
@@ -32,9 +32,10 @@ class DependencyGraph private constructor() {
}
fun longestPath(key: String): LongestPath {
- val nodeNames = nodes.getValue(key)
- .longestPath()
- .map { it.key }
+ val nodeNames =
+ nodes.getValue(key)
+ .longestPath()
+ .map { it.key }
return LongestPath(nodeNames)
}
@@ -54,7 +55,7 @@ class DependencyGraph private constructor() {
modulesCount = nodes.size,
edgesCount = edgesCount,
height = height,
- longestPath = longestPath()
+ longestPath = longestPath(),
)
}
@@ -74,11 +75,14 @@ class DependencyGraph private constructor() {
fun serializableGraph(): SerializableGraph {
return SerializableGraph(
ArrayList(dependencyPairs()),
- nodes.keys.first()
+ nodes.keys.first(),
)
}
- private fun addConnections(node: Node, into: MutableList>) {
+ private fun addConnections(
+ node: Node,
+ into: MutableList>,
+ ) {
node.dependsOn.forEach {
into.add(node.key to it.key)
addConnections(it, into)
@@ -91,7 +95,7 @@ class DependencyGraph private constructor() {
class SerializableGraph(
val dependencyPairs: ArrayList>,
- val firstModule: String
+ val firstModule: String,
) : Serializable
class Node(val key: String) {
@@ -135,9 +139,7 @@ class DependencyGraph private constructor() {
}
fun create(dependencies: List>): DependencyGraph {
- if (dependencies.isEmpty()) {
- throw IllegalArgumentException("Graph cannot be empty. Use createSingular for cases with no dependencies")
- }
+ require(dependencies.isNotEmpty()) { "Graph cannot be empty. Use createSingular for cases with no dependencies" }
val graph = DependencyGraph()
dependencies.forEach { graph.addEdge(it.first, it.second) }
@@ -156,7 +158,10 @@ class DependencyGraph private constructor() {
}
}
- private fun DependencyGraph.addEdge(from: String, to: String) {
+ private fun DependencyGraph.addEdge(
+ from: String,
+ to: String,
+ ) {
getOrCreate(from).dependsOn.add(getOrCreate(to))
}
diff --git a/plugin/src/main/kotlin/com/jraska/module/graph/GraphStatistics.kt b/plugin/src/main/kotlin/com/jraska/module/graph/GraphStatistics.kt
index 8a081e7..7046529 100644
--- a/plugin/src/main/kotlin/com/jraska/module/graph/GraphStatistics.kt
+++ b/plugin/src/main/kotlin/com/jraska/module/graph/GraphStatistics.kt
@@ -4,5 +4,5 @@ data class GraphStatistics(
val modulesCount: Int,
val edgesCount: Int,
val height: Int,
- val longestPath: LongestPath
+ val longestPath: LongestPath,
)
diff --git a/plugin/src/main/kotlin/com/jraska/module/graph/LongestPath.kt b/plugin/src/main/kotlin/com/jraska/module/graph/LongestPath.kt
index 9d7b09b..800771f 100644
--- a/plugin/src/main/kotlin/com/jraska/module/graph/LongestPath.kt
+++ b/plugin/src/main/kotlin/com/jraska/module/graph/LongestPath.kt
@@ -1,7 +1,7 @@
package com.jraska.module.graph
data class LongestPath(
- val nodeNames: List
+ val nodeNames: List,
) {
fun pathString(): String {
return nodeNames.joinToString(" -> ")
diff --git a/plugin/src/main/kotlin/com/jraska/module/graph/Parse.kt b/plugin/src/main/kotlin/com/jraska/module/graph/Parse.kt
index fa1e9e6..b5306f9 100644
--- a/plugin/src/main/kotlin/com/jraska/module/graph/Parse.kt
+++ b/plugin/src/main/kotlin/com/jraska/module/graph/Parse.kt
@@ -12,9 +12,12 @@ object Parse {
return matcher(matcherText, NO_DEPENDENCY_SIGN_DIVIDER)
}
- private fun matcher(matcherText: String, divider: String): RegexpDependencyMatcher {
- if (!matcherText.contains(divider)) {
- throw IllegalArgumentException("Incorrect format. Expected: 'regexp${divider}regexp', found $matcherText")
+ private fun matcher(
+ matcherText: String,
+ divider: String,
+ ): RegexpDependencyMatcher {
+ require(matcherText.contains(divider)) {
+ "Incorrect format. Expected: 'regexp${divider}regexp', found $matcherText"
}
return RegexpDependencyMatcher(matcherText.toRegex(), divider)
diff --git a/plugin/src/main/kotlin/com/jraska/module/graph/RegexpDependencyMatcher.kt b/plugin/src/main/kotlin/com/jraska/module/graph/RegexpDependencyMatcher.kt
index 71f71fc..0d9e633 100644
--- a/plugin/src/main/kotlin/com/jraska/module/graph/RegexpDependencyMatcher.kt
+++ b/plugin/src/main/kotlin/com/jraska/module/graph/RegexpDependencyMatcher.kt
@@ -2,9 +2,8 @@ package com.jraska.module.graph
class RegexpDependencyMatcher(
private val matchingRegex: Regex,
- private val divider: String
+ private val divider: String,
) : DependencyMatcher {
-
override fun matches(dependency: Pair): Boolean {
val dependencyToMatch = "${dependency.first}$divider${dependency.second}"
return matchingRegex.matches(dependencyToMatch)
diff --git a/plugin/src/main/kotlin/com/jraska/module/graph/assertion/GradleDependencyGraphFactory.kt b/plugin/src/main/kotlin/com/jraska/module/graph/assertion/GradleDependencyGraphFactory.kt
index 8437ff3..f89abe0 100644
--- a/plugin/src/main/kotlin/com/jraska/module/graph/assertion/GradleDependencyGraphFactory.kt
+++ b/plugin/src/main/kotlin/com/jraska/module/graph/assertion/GradleDependencyGraphFactory.kt
@@ -1,19 +1,22 @@
package com.jraska.module.graph.assertion
import com.jraska.module.graph.DependencyGraph
-import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.Project
+import org.gradle.api.artifacts.ProjectDependency
object GradleDependencyGraphFactory {
-
- fun create(project: Project, configurationsToLook: Set): DependencyGraph {
+ fun create(
+ project: Project,
+ configurationsToLook: Set,
+ ): DependencyGraph {
val modulesWithDependencies = project.listAllDependencies(configurationsToLook)
- val dependencies = modulesWithDependencies.flatMap { module ->
- module.second.map { module.first to it }
- }
+ val dependencies =
+ modulesWithDependencies.flatMap { module ->
+ module.second.map { module.first to it }
+ }
val moduleDisplayName = project.moduleDisplayName()
- if(dependencies.isEmpty()) {
+ if (dependencies.isEmpty()) {
return DependencyGraph.createSingular(moduleDisplayName)
}
@@ -32,13 +35,14 @@ object GradleDependencyGraphFactory {
private fun Project.listAllDependencies(configurationsToLook: Set): List>> {
return (rootProject.subprojects + rootProject)
.map { project ->
- project.moduleDisplayName() to project.configurations
- .filter { configurationsToLook.contains(it.name) }
- .flatMap { configuration ->
- configuration.dependencies.filterIsInstance(ProjectDependency::class.java)
- .map { it.dependencyProject }
- }
- .map { it.moduleDisplayName() }
+ project.moduleDisplayName() to
+ project.configurations
+ .filter { configurationsToLook.contains(it.name) }
+ .flatMap { configuration ->
+ configuration.dependencies.filterIsInstance(ProjectDependency::class.java)
+ .map { it.dependencyProject }
+ }
+ .map { it.moduleDisplayName() }
}
}
}
diff --git a/plugin/src/main/kotlin/com/jraska/module/graph/assertion/ModuleGraphAssertionsPlugin.kt b/plugin/src/main/kotlin/com/jraska/module/graph/assertion/ModuleGraphAssertionsPlugin.kt
index bdb274f..799ed02 100644
--- a/plugin/src/main/kotlin/com/jraska/module/graph/assertion/ModuleGraphAssertionsPlugin.kt
+++ b/plugin/src/main/kotlin/com/jraska/module/graph/assertion/ModuleGraphAssertionsPlugin.kt
@@ -28,7 +28,12 @@ class ModuleGraphAssertionsPlugin : Plugin {
private var outputFilePath: String? = null
override fun apply(project: Project) {
- val graphRules = project.extensions.create(GraphRulesExtension::class.java, Api.EXTENSION_ROOT, GraphRulesExtension::class.java)
+ val graphRules =
+ project.extensions.create(
+ GraphRulesExtension::class.java,
+ Api.EXTENSION_ROOT,
+ GraphRulesExtension::class.java,
+ )
project.afterEvaluate {
addModulesAssertions(project, graphRules)
@@ -169,7 +174,11 @@ class ModuleGraphAssertionsPlugin : Plugin {
}
}
- private fun restrictedDependenciesAssert(graphRules: GraphRulesExtension) = RestrictedDependenciesAssert(graphRules.restricted, aliases)
+ private fun restrictedDependenciesAssert(graphRules: GraphRulesExtension) =
+ RestrictedDependenciesAssert(
+ graphRules.restricted,
+ aliases,
+ )
private fun Project.addModuleAllowedRulesTask(graphRules: GraphRulesExtension): TaskProvider? {
if (graphRules.shouldAssertAllowed()) {
diff --git a/plugin/src/main/kotlin/com/jraska/module/graph/assertion/ModuleTreeHeightAssert.kt b/plugin/src/main/kotlin/com/jraska/module/graph/assertion/ModuleTreeHeightAssert.kt
index b5ab093..eaea742 100644
--- a/plugin/src/main/kotlin/com/jraska/module/graph/assertion/ModuleTreeHeightAssert.kt
+++ b/plugin/src/main/kotlin/com/jraska/module/graph/assertion/ModuleTreeHeightAssert.kt
@@ -6,7 +6,7 @@ import java.io.Serializable
class ModuleTreeHeightAssert(
private val moduleName: String?,
- private val maxHeight: Int
+ private val maxHeight: Int,
) : GraphAssert, Serializable {
override fun assert(dependencyGraph: DependencyGraph) {
if (moduleName == null) {
@@ -16,11 +16,16 @@ class ModuleTreeHeightAssert(
}
}
- private fun assertModuleHeight(dependencyGraph: DependencyGraph, moduleName: String) {
+ private fun assertModuleHeight(
+ dependencyGraph: DependencyGraph,
+ moduleName: String,
+ ) {
val height = dependencyGraph.heightOf(moduleName)
if (height > maxHeight) {
val longestPath = dependencyGraph.longestPath(moduleName)
- throw GradleException("Module $moduleName is allowed to have maximum height of $maxHeight, but has $height, problematic dependencies: ${longestPath.pathString()}")
+ throw GradleException(
+ "Module $moduleName is allowed to have maximum height of $maxHeight, but has $height, problematic dependencies: ${longestPath.pathString()}",
+ )
}
}
@@ -28,7 +33,9 @@ class ModuleTreeHeightAssert(
val height = dependencyGraph.height()
if (height > maxHeight) {
val longestPath = dependencyGraph.longestPath()
- throw GradleException("Module Graph is allowed to have maximum height of $maxHeight, but has $height, problematic dependencies: ${longestPath.pathString()}")
+ throw GradleException(
+ "Module Graph is allowed to have maximum height of $maxHeight, but has $height, problematic dependencies: ${longestPath.pathString()}",
+ )
}
}
}
diff --git a/plugin/src/main/kotlin/com/jraska/module/graph/assertion/tasks/AssertGraphTask.kt b/plugin/src/main/kotlin/com/jraska/module/graph/assertion/tasks/AssertGraphTask.kt
index 0dd9d7d..5b8e4a8 100644
--- a/plugin/src/main/kotlin/com/jraska/module/graph/assertion/tasks/AssertGraphTask.kt
+++ b/plugin/src/main/kotlin/com/jraska/module/graph/assertion/tasks/AssertGraphTask.kt
@@ -7,7 +7,6 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
open class AssertGraphTask : DefaultTask() {
-
@Input
lateinit var assertion: GraphAssert
diff --git a/plugin/src/main/kotlin/com/jraska/module/graph/assertion/tasks/GenerateModulesGraphStatisticsTask.kt b/plugin/src/main/kotlin/com/jraska/module/graph/assertion/tasks/GenerateModulesGraphStatisticsTask.kt
index ef37249..ea06b49 100644
--- a/plugin/src/main/kotlin/com/jraska/module/graph/assertion/tasks/GenerateModulesGraphStatisticsTask.kt
+++ b/plugin/src/main/kotlin/com/jraska/module/graph/assertion/tasks/GenerateModulesGraphStatisticsTask.kt
@@ -7,7 +7,6 @@ import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
open class GenerateModulesGraphStatisticsTask : DefaultTask() {
-
@Optional
@Input
var onlyModuleStatistics: String? = null
diff --git a/plugin/src/test/kotlin/com/jraska/module/graph/DependencyGraphPerformanceTest.kt b/plugin/src/test/kotlin/com/jraska/module/graph/DependencyGraphPerformanceTest.kt
index 356c15d..7d2d2ca 100644
--- a/plugin/src/test/kotlin/com/jraska/module/graph/DependencyGraphPerformanceTest.kt
+++ b/plugin/src/test/kotlin/com/jraska/module/graph/DependencyGraphPerformanceTest.kt
@@ -11,10 +11,11 @@ class DependencyGraphPerformanceTest {
fun setUp() {
val uri = javaClass.classLoader.getResource("graph/large-graph.txt")
val file = File(uri?.path!!)
- val dependencyPairs = file.readLines().map {
- val parts = it.split(" -> ")
- parts[0] to parts[1]
- }
+ val dependencyPairs =
+ file.readLines().map {
+ val parts = it.split(" -> ")
+ parts[0] to parts[1]
+ }
dependencyGraph = DependencyGraph.create(dependencyPairs)
}
diff --git a/plugin/src/test/kotlin/com/jraska/module/graph/DependencyGraphSerializationTest.kt b/plugin/src/test/kotlin/com/jraska/module/graph/DependencyGraphSerializationTest.kt
index db2edcb..108eb83 100644
--- a/plugin/src/test/kotlin/com/jraska/module/graph/DependencyGraphSerializationTest.kt
+++ b/plugin/src/test/kotlin/com/jraska/module/graph/DependencyGraphSerializationTest.kt
@@ -17,13 +17,14 @@ class DependencyGraphSerializationTest {
@Test
fun graphIsSerializable() {
- val originalGraph = DependencyGraph.create(
- "feature" to "lib",
- "lib" to "core",
- "app" to "feature",
- "feature" to "core",
- "app" to "core"
- )
+ val originalGraph =
+ DependencyGraph.create(
+ "feature" to "lib",
+ "lib" to "core",
+ "app" to "feature",
+ "feature" to "core",
+ "app" to "core",
+ )
val deserializedGraph = serializeAndDeserializeGraph(originalGraph)
diff --git a/plugin/src/test/kotlin/com/jraska/module/graph/DependencyGraphTest.kt b/plugin/src/test/kotlin/com/jraska/module/graph/DependencyGraphTest.kt
index 6bc8cea..7b017ca 100644
--- a/plugin/src/test/kotlin/com/jraska/module/graph/DependencyGraphTest.kt
+++ b/plugin/src/test/kotlin/com/jraska/module/graph/DependencyGraphTest.kt
@@ -5,54 +5,55 @@ import org.junit.Test
class DependencyGraphTest {
@Test
fun correctHeightIsMaintained() {
- val dependencyTree = DependencyGraph.create(
- "app" to "feature",
- "app" to "lib",
- "feature" to "lib",
- "lib" to "core"
- )
+ val dependencyTree =
+ DependencyGraph.create(
+ "app" to "feature",
+ "app" to "lib",
+ "feature" to "lib",
+ "lib" to "core",
+ )
assert(dependencyTree.heightOf("app") == 3)
}
@Test
fun findsProperLongestPath() {
- val dependencyTree = DependencyGraph.create(
-
- "app" to "feature",
- "app" to "lib",
- "app" to "core",
- "feature" to "lib",
- "lib" to "core"
-
- )
+ val dependencyTree =
+ DependencyGraph.create(
+ "app" to "feature",
+ "app" to "lib",
+ "app" to "core",
+ "feature" to "lib",
+ "lib" to "core",
+ )
assert(dependencyTree.longestPath("app").nodeNames == listOf("app", "feature", "lib", "core"))
}
@Test
fun findsProperRoot() {
- val dependencyTree = DependencyGraph.create(
- "feature" to "lib",
- "lib" to "core",
- "app" to "feature",
- "app" to "lib",
- "app" to "core"
-
- )
+ val dependencyTree =
+ DependencyGraph.create(
+ "feature" to "lib",
+ "lib" to "core",
+ "app" to "feature",
+ "app" to "lib",
+ "app" to "core",
+ )
assert(dependencyTree.findRoot().key == "app")
}
@Test
fun createsSubtreeProperly() {
- val dependencyTree = DependencyGraph.create(
- "feature" to "lib",
- "lib" to "core",
- "app" to "feature",
- "feature" to "core",
- "app" to "core"
- )
+ val dependencyTree =
+ DependencyGraph.create(
+ "feature" to "lib",
+ "lib" to "core",
+ "app" to "feature",
+ "feature" to "core",
+ "app" to "core",
+ )
val subTree = dependencyTree.subTree("feature")
@@ -63,13 +64,14 @@ class DependencyGraphTest {
@Test
fun subtreeOfLeafModuleIsNotEmpty() {
- val dependencyTree = DependencyGraph.create(
- "feature" to "lib",
- "lib" to "core",
- "app" to "feature",
- "feature" to "core",
- "app" to "core"
- )
+ val dependencyTree =
+ DependencyGraph.create(
+ "feature" to "lib",
+ "lib" to "core",
+ "app" to "feature",
+ "feature" to "core",
+ "app" to "core",
+ )
assert(dependencyTree.subTree("core").findRoot().key == "core")
}
@@ -97,65 +99,70 @@ class DependencyGraphTest {
@Test
fun countsStatisticsWell() {
- val dependencyTree = DependencyGraph.create(
- ":app" to ":core",
- ":app" to ":core-android",
- ":app" to ":navigation",
- ":app" to ":lib:navigation-deeplink",
- ":app" to ":lib:identity",
- ":app" to ":lib:dynamic-features",
- ":app" to ":lib:network-status",
- ":app" to ":feature:push",
- ":app" to ":feature:users",
- ":app" to ":feature:settings_entrance",
- ":app" to ":feature:about_entrance",
- ":app" to ":feature:shortcuts",
- ":core-android" to ":core",
- ":lib:navigation-deeplink" to ":navigation",
- ":lib:navigation-deeplink" to ":core",
- ":lib:identity" to ":core",
- ":lib:dynamic-features" to ":core",
- ":lib:dynamic-features" to ":core-android",
- ":lib:network-status" to ":core",
- ":lib:network-status" to ":core-android",
- ":feature:push" to ":core",
- ":feature:push" to ":core-android",
- ":feature:push" to ":lib:identity",
- ":feature:users" to ":core",
- ":feature:users" to ":core-android",
- ":feature:users" to ":navigation",
- ":feature:settings_entrance" to ":core",
- ":feature:settings_entrance" to ":core-android",
- ":feature:settings_entrance" to ":lib:dynamic-features",
- ":feature:about_entrance" to ":core",
- ":feature:about_entrance" to ":core-android",
- ":feature:about_entrance" to ":lib:dynamic-features",
- ":feature:shortcuts" to ":core",
- ":feature:shortcuts" to ":core-android",
- ":core-testing" to ":core",
- ":feature:about" to ":app",
- ":feature:about" to ":core",
- ":feature:about" to ":core-android",
- ":feature:about" to ":navigation",
- ":feature:about" to ":lib:identity",
- ":feature:about" to ":lib:dynamic-features",
- ":feature:settings" to ":core",
- ":feature:settings" to ":core-android",
- ":feature:settings" to ":lib:dynamic-features",
- ":feature:settings" to ":app"
- )
+ val dependencyTree =
+ DependencyGraph.create(
+ ":app" to ":core",
+ ":app" to ":core-android",
+ ":app" to ":navigation",
+ ":app" to ":lib:navigation-deeplink",
+ ":app" to ":lib:identity",
+ ":app" to ":lib:dynamic-features",
+ ":app" to ":lib:network-status",
+ ":app" to ":feature:push",
+ ":app" to ":feature:users",
+ ":app" to ":feature:settings_entrance",
+ ":app" to ":feature:about_entrance",
+ ":app" to ":feature:shortcuts",
+ ":core-android" to ":core",
+ ":lib:navigation-deeplink" to ":navigation",
+ ":lib:navigation-deeplink" to ":core",
+ ":lib:identity" to ":core",
+ ":lib:dynamic-features" to ":core",
+ ":lib:dynamic-features" to ":core-android",
+ ":lib:network-status" to ":core",
+ ":lib:network-status" to ":core-android",
+ ":feature:push" to ":core",
+ ":feature:push" to ":core-android",
+ ":feature:push" to ":lib:identity",
+ ":feature:users" to ":core",
+ ":feature:users" to ":core-android",
+ ":feature:users" to ":navigation",
+ ":feature:settings_entrance" to ":core",
+ ":feature:settings_entrance" to ":core-android",
+ ":feature:settings_entrance" to ":lib:dynamic-features",
+ ":feature:about_entrance" to ":core",
+ ":feature:about_entrance" to ":core-android",
+ ":feature:about_entrance" to ":lib:dynamic-features",
+ ":feature:shortcuts" to ":core",
+ ":feature:shortcuts" to ":core-android",
+ ":core-testing" to ":core",
+ ":feature:about" to ":app",
+ ":feature:about" to ":core",
+ ":feature:about" to ":core-android",
+ ":feature:about" to ":navigation",
+ ":feature:about" to ":lib:identity",
+ ":feature:about" to ":lib:dynamic-features",
+ ":feature:settings" to ":core",
+ ":feature:settings" to ":core-android",
+ ":feature:settings" to ":lib:dynamic-features",
+ ":feature:settings" to ":app",
+ )
val statistics = dependencyTree.statistics()
assert(statistics.height == 5)
assert(statistics.modulesCount == 16)
assert(statistics.edgesCount == 45)
- assert(statistics.longestPath.nodeNames == listOf(
- ":feature:settings",
- ":app",
- ":feature:settings_entrance",
- ":lib:dynamic-features",
- ":core-android",
- ":core"))
+ assert(
+ statistics.longestPath.nodeNames ==
+ listOf(
+ ":feature:settings",
+ ":app",
+ ":feature:settings_entrance",
+ ":lib:dynamic-features",
+ ":core-android",
+ ":core",
+ ),
+ )
}
}
diff --git a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/ConfigurationAvoidanceTest.kt b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/ConfigurationAvoidanceTest.kt
index b312717..4044a61 100644
--- a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/ConfigurationAvoidanceTest.kt
+++ b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/ConfigurationAvoidanceTest.kt
@@ -27,7 +27,7 @@ class ConfigurationAvoidanceTest {
}
ext.moduleNameAssertAlias = "Alias"
- """
+ """,
)
}
@@ -41,7 +41,10 @@ class ConfigurationAvoidanceTest {
}
}
-fun runGradleAssertModuleGraph(dir: File, vararg arguments: String = arrayOf("--configuration-cache", "assertModuleGraph")): BuildResult {
+fun runGradleAssertModuleGraph(
+ dir: File,
+ vararg arguments: String = arrayOf("--configuration-cache", "assertModuleGraph"),
+): BuildResult {
return GradleRunner.create()
.withProjectDir(dir)
.withPluginClasspath()
diff --git a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/FullProjectGradleTest.kt b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/FullProjectGradleTest.kt
index dfff771..926f55d 100644
--- a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/FullProjectGradleTest.kt
+++ b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/FullProjectGradleTest.kt
@@ -86,7 +86,12 @@ class FullProjectGradleTest {
@Test
fun statisticsSupportConfigurationCache() {
runGradleAssertModuleGraph(testProjectDir.root, "--configuration-cache", "generateModulesGraphStatistics")
- val secondRunResult = runGradleAssertModuleGraph(testProjectDir.root, "--configuration-cache", "generateModulesGraphStatistics")
+ val secondRunResult =
+ runGradleAssertModuleGraph(
+ testProjectDir.root,
+ "--configuration-cache",
+ "generateModulesGraphStatistics",
+ )
assert(secondRunResult.output.contains("Reusing configuration cache."))
}
@@ -94,7 +99,12 @@ class FullProjectGradleTest {
@Test
fun moduleGraphSupportConfigurationCache() {
runGradleAssertModuleGraph(testProjectDir.root, "--configuration-cache", "generateModulesGraphvizText")
- val secondRunResult = runGradleAssertModuleGraph(testProjectDir.root, "--configuration-cache", "generateModulesGraphvizText")
+ val secondRunResult =
+ runGradleAssertModuleGraph(
+ testProjectDir.root,
+ "--configuration-cache",
+ "generateModulesGraphvizText",
+ )
assert(secondRunResult.output.contains("Reusing configuration cache."))
}
@@ -103,12 +113,21 @@ class FullProjectGradleTest {
fun printsCorrectStatistics() {
val output = runGradleAssertModuleGraph(testProjectDir.root, "generateModulesGraphStatistics").output
- assert(output.contains("GraphStatistics(modulesCount=4, edgesCount=5, height=2, longestPath=':app -> :core -> :core-api')"))
+ assert(
+ output.contains(
+ "GraphStatistics(modulesCount=4, edgesCount=5, height=2, longestPath=':app -> :core -> :core-api')",
+ ),
+ )
}
@Test
fun printsOnlyModule() {
- val output = runGradleAssertModuleGraph(testProjectDir.root, "generateModulesGraphvizText", "-Pmodules.graph.of.module=:feature").output
+ val output =
+ runGradleAssertModuleGraph(
+ testProjectDir.root,
+ "generateModulesGraphvizText",
+ "-Pmodules.graph.of.module=:feature",
+ ).output
MatcherAssert.assertThat(
output,
@@ -131,7 +150,9 @@ class FullProjectGradleTest {
MatcherAssert.assertThat(
output,
- CoreMatchers.containsString("GraphStatistics(modulesCount=2, edgesCount=1, height=1, longestPath=':feature -> :core-api')"),
+ CoreMatchers.containsString(
+ "GraphStatistics(modulesCount=2, edgesCount=1, height=1, longestPath=':feature -> :core-api')",
+ ),
)
}
diff --git a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/FullProjectRootGradleTest.kt b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/FullProjectRootGradleTest.kt
index b5e2325..eb80d80 100644
--- a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/FullProjectRootGradleTest.kt
+++ b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/FullProjectRootGradleTest.kt
@@ -14,31 +14,41 @@ class FullProjectRootGradleTest {
testProjectDir.newFile("settings.gradle")
.writeText("include ':core'")
- createRoot(content = """
- plugins {
- id 'com.jraska.module.graph.assertion'
- }
- apply plugin: 'java-library'
-
- moduleGraphAssert {
- maxHeight = 1
- }
- dependencies {
- implementation project(":core")
- }
- """.trimIndent())
+ createRoot(
+ content =
+ """
+ plugins {
+ id 'com.jraska.module.graph.assertion'
+ }
+ apply plugin: 'java-library'
+
+ moduleGraphAssert {
+ maxHeight = 1
+ }
+ dependencies {
+ implementation project(":core")
+ }
+ """.trimIndent(),
+ )
createModule(
- "core", content = """
+ "core",
+ content = """
apply plugin: 'java-library'
- """
+ """,
)
val output =
runGradleAssertModuleGraph(testProjectDir.root, "generateModulesGraphStatistics").output
- assert(output.contains(("> Task :generateModulesGraphStatistics\n.*" +
- "GraphStatistics\\(modulesCount=2, edgesCount=1, height=1, longestPath=\'root.* -> :core\'\\)").toRegex()))
+ assert(
+ output.contains(
+ (
+ "> Task :generateModulesGraphStatistics\n.*" +
+ "GraphStatistics\\(modulesCount=2, edgesCount=1, height=1, longestPath=\'root.* -> :core\'\\)"
+ ).toRegex(),
+ ),
+ )
}
@Test
@@ -46,19 +56,23 @@ class FullProjectRootGradleTest {
testProjectDir.newFile("settings.gradle")
.writeText("include ':app'")
- createRoot(content = """
- plugins {
- id 'com.jraska.module.graph.assertion'
- }
- apply plugin: 'java-library'
-
- moduleGraphAssert {
- maxHeight = 0
- }
- """.trimIndent())
+ createRoot(
+ content =
+ """
+ plugins {
+ id 'com.jraska.module.graph.assertion'
+ }
+ apply plugin: 'java-library'
+
+ moduleGraphAssert {
+ maxHeight = 0
+ }
+ """.trimIndent(),
+ )
createModule(
- "app", content = """
+ "app",
+ content = """
plugins {
id 'com.jraska.module.graph.assertion'
}
@@ -66,23 +80,32 @@ class FullProjectRootGradleTest {
moduleGraphAssert {
maxHeight = 0
}
- """
+ """,
)
val output =
runGradleAssertModuleGraph(testProjectDir.root, "generateModulesGraphStatistics").output
- assert(output.contains(("> Task :generateModulesGraphStatistics\n.*" +
- "GraphStatistics\\(modulesCount=1, edgesCount=0, height=0, longestPath=\'root.*\'\\)\n\n" +
- "> Task :app:generateModulesGraphStatistics\n+" +
- "GraphStatistics\\(modulesCount=1, edgesCount=0, height=0, longestPath=\':app\'\\)").toRegex()))
+ assert(
+ output.contains(
+ (
+ "> Task :generateModulesGraphStatistics\n.*" +
+ "GraphStatistics\\(modulesCount=1, edgesCount=0, height=0, longestPath=\'root.*\'\\)\n\n" +
+ "> Task :app:generateModulesGraphStatistics\n+" +
+ "GraphStatistics\\(modulesCount=1, edgesCount=0, height=0, longestPath=\':app\'\\)"
+ ).toRegex(),
+ ),
+ )
}
private fun createRoot(content: String) {
File(testProjectDir.root, "build.gradle").writeText(content)
}
- private fun createModule(dir: String, content: String) {
+ private fun createModule(
+ dir: String,
+ content: String,
+ ) {
val newFolder = testProjectDir.newFolder(dir)
File(newFolder, "build.gradle").writeText(content)
}
diff --git a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/GradleDependencyGraphFactorySingleModuleProjectTest.kt b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/GradleDependencyGraphFactorySingleModuleProjectTest.kt
index e3a6cf8..8a907a6 100644
--- a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/GradleDependencyGraphFactorySingleModuleProjectTest.kt
+++ b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/GradleDependencyGraphFactorySingleModuleProjectTest.kt
@@ -8,13 +8,15 @@ import org.junit.Before
import org.junit.Test
class GradleDependencyGraphFactorySingleModuleProjectTest {
- private val EXPECTED_SINGLE_MODULE = """digraph G {
+ companion object {
+ private const val EXPECTED_SINGLE_MODULE = """digraph G {
":app"
}"""
- private val EXPECTED_ROOT_MODULE = """digraph G {
+ private const val EXPECTED_ROOT_MODULE = """digraph G {
"root some-root"
}"""
+ }
private lateinit var singleModule: DefaultProject
private var rootProject: DefaultProject? = null
diff --git a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/GradleDependencyGraphFactoryTest.kt b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/GradleDependencyGraphFactoryTest.kt
index 27d8e6a..883892c 100644
--- a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/GradleDependencyGraphFactoryTest.kt
+++ b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/GradleDependencyGraphFactoryTest.kt
@@ -8,11 +8,12 @@ import org.junit.Before
import org.junit.Test
class GradleDependencyGraphFactoryTest {
- private val EXPECTED_SINGLE_MODULE = """digraph G {
+ companion object {
+ private const val EXPECTED_SINGLE_MODULE = """digraph G {
":core"
}"""
- private val EXPECTED_GRAPHVIZ = """digraph G {
+ private const val EXPECTED_GRAPHVIZ = """digraph G {
":app" -> ":lib"
":app" -> ":feature" [color=red style=bold]
":lib" -> ":core" [color=red style=bold]
@@ -20,13 +21,14 @@ class GradleDependencyGraphFactoryTest {
":feature" -> ":lib" [color=red style=bold]
}"""
- private val EXPECTED_TEST_IMPLEMENTATION = """digraph G {
+ private const val EXPECTED_TEST_IMPLEMENTATION = """digraph G {
":app" -> ":feature" [color=red style=bold]
":feature" -> ":lib" [color=red style=bold]
":feature" -> ":core-testing"
":lib" -> ":core" [color=red style=bold]
":core-testing" -> ":core"
}"""
+ }
private lateinit var appProject: DefaultProject
private lateinit var coreProject: DefaultProject
diff --git a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/ModuleTreeHeightAssertTest.kt b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/ModuleTreeHeightAssertTest.kt
index 79116fa..f980dd1 100644
--- a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/ModuleTreeHeightAssertTest.kt
+++ b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/ModuleTreeHeightAssertTest.kt
@@ -45,7 +45,7 @@ class ModuleTreeHeightAssertTest {
"app" to "feature",
"app" to "lib",
"feature" to "lib",
- "lib" to "core"
+ "lib" to "core",
)
}
}
diff --git a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/OnAnyBuildAssertTest.kt b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/OnAnyBuildAssertTest.kt
index 75fc02c..52b2e82 100644
--- a/plugin/src/test/kotlin/com/jraska/module/graph/assertion/OnAnyBuildAssertTest.kt
+++ b/plugin/src/test/kotlin/com/jraska/module/graph/assertion/OnAnyBuildAssertTest.kt
@@ -17,26 +17,29 @@ class OnAnyBuildAssertTest {
.writeText("include ':app', ':core', ':feature', 'core-api'")
createModule(
- "core-api", content = """
+ "core-api",
+ content = """
apply plugin: 'java-library'
ext.moduleNameAssertAlias = "Api"
- """
+ """,
)
createModule(
- "core", content = """
+ "core",
+ content = """
apply plugin: 'java-library'
dependencies {
implementation project(":core-api")
}
ext.moduleNameAssertAlias = "Implementation"
- """
+ """,
)
createModule(
- "feature", content = """
+ "feature",
+ content = """
apply plugin: 'java-library'
dependencies {
@@ -44,13 +47,14 @@ class OnAnyBuildAssertTest {
}
ext.moduleNameAssertAlias = "Implementation"
- """
+ """,
)
}
private fun createAppModule(moduleGraphAssertConfiguration: String) {
createModule(
- "app", content = """
+ "app",
+ content = """
plugins {
id 'com.jraska.module.graph.assertion'
}
@@ -65,7 +69,7 @@ class OnAnyBuildAssertTest {
}
ext.moduleNameAssertAlias = "App"
- """
+ """,
)
}
@@ -77,12 +81,16 @@ class OnAnyBuildAssertTest {
maxHeight = 1
assertOnAnyBuild = true
}
- """
+ """,
)
val output = setupGradle(testProjectDir.root, "help").buildAndFail().output
- assert(output.contains("Module :app is allowed to have maximum height of 1, but has 2, problematic dependencies: :app -> :core -> :core-api"))
+ assert(
+ output.contains(
+ "Module :app is allowed to have maximum height of 1, but has 2, problematic dependencies: :app -> :core -> :core-api",
+ ),
+ )
}
@Test
@@ -93,7 +101,7 @@ class OnAnyBuildAssertTest {
maxHeight = 1
assertOnAnyBuild = false
}
- """
+ """,
)
val output = setupGradle(testProjectDir.root, "help").build().output
@@ -110,12 +118,16 @@ class OnAnyBuildAssertTest {
allowed = ['Implementation -> Api', 'App -> Api']
assertOnAnyBuild = true
}
- """
+ """,
)
val output = setupGradle(testProjectDir.root, "help").buildAndFail().output
- assert(output.contains("""["App"(':app') -> "Implementation"(':core'), "App"(':app') -> "Implementation"(':feature')] not allowed by any of ['Implementation -> Api', 'App -> Api']"""))
+ assert(
+ output.contains(
+ """["App"(':app') -> "Implementation"(':core'), "App"(':app') -> "Implementation"(':feature')] not allowed by any of ['Implementation -> Api', 'App -> Api']""",
+ ),
+ )
}
@Test
@@ -125,7 +137,7 @@ class OnAnyBuildAssertTest {
moduleGraphAssert {
allowed = ['Implementation -> Api', 'App -> Api']
}
- """
+ """,
)
val output = setupGradle(testProjectDir.root, "help").build().output
@@ -142,7 +154,7 @@ class OnAnyBuildAssertTest {
restricted = ['App -X> Api', 'Implementation -X> Implementation']
assertOnAnyBuild = true
}
- """
+ """,
)
val output = setupGradle(testProjectDir.root, "help").buildAndFail().output
@@ -150,14 +162,17 @@ class OnAnyBuildAssertTest {
assert(output.contains("""Dependency '"App"(':app') -> "Api"(':core-api') violates: 'App -X> Api'"""))
}
- private fun createModule(dir: String, content: String) {
+ private fun createModule(
+ dir: String,
+ content: String,
+ ) {
val newFolder = testProjectDir.newFolder(dir)
File(newFolder, "build.gradle").writeText(content)
}
private fun setupGradle(
dir: File,
- vararg arguments: String
+ vararg arguments: String,
): GradleRunner {
return GradleRunner.create()
.withProjectDir(dir)