Skip to content

Commit

Permalink
refactoring package dependency rules
Browse files Browse the repository at this point in the history
  • Loading branch information
dkandalov committed Oct 15, 2022
1 parent 7770e2a commit 1c97997
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions .live-plugins/dependency-rules/plugin.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ import org.jetbrains.kotlin.psi.KtFile

// depends-on-plugin org.jetbrains.kotlin

val livePlugin = createScope("liveplugin") { it.startsWith("liveplugin.implementation") }
// Use "Validate Dependencies" action to check the dependencies below.

val all = createScope("liveplugin") { it.startsWith("liveplugin.implementation") }
val core = createScope("core") { it.startsWith("liveplugin.implementation.LivePlugin.kt") }
val common = createScope("common") { it.startsWith("liveplugin.implementation.common") }
val actions = createScope("actions") { it.startsWith("liveplugin.implementation.actions") }
val pluginRunner = createScope("pluginrunner") { it.startsWith("liveplugin.implementation.pluginrunner") }

val validationManager = DependencyValidationManager.getInstance(project!!)
fun NamedScope.nothingDependsOnIt() = validationManager.denyUsages(of = this, `in` = all - this)
fun NamedScope.doesNotDependOnAnything() = validationManager.denyUsages(of = all - this, `in` = this)
fun NamedScope.dependsOnlyOn(vararg scopes: NamedScope) = validationManager.denyUsages(of = all - this - scopes.union(), `in` = scopes.union())

validationManager.removeAllRules()
validationManager.denyUsages(of = livePlugin - pluginRunner - common - core, `in` = pluginRunner) // "pluginRunner" can only depend on "core" and "common"
validationManager.denyUsages(of = livePlugin - common, `in` = common) // "common" doesn't depend on anything else
validationManager.denyUsages(of = actions, `in` = livePlugin - actions) // nothing depends on "actions"
actions.nothingDependsOnIt()
pluginRunner.dependsOnlyOn(core, common)
common.doesNotDependOnAnything()


fun DependencyValidationManager.denyUsages(of: NamedScope, `in`: NamedScope) = addRule(DependencyRule(`in`, of, true))
Expand All @@ -42,3 +48,5 @@ fun NamedScope.inverted() =

fun NamedScope.intersect(that: NamedScope) =
NamedScope("$scopeId && ${that.scopeId}", icon, IntersectionPackageSet.create(value!!, that.value!!))

fun Array<out NamedScope>.union() = reduce { a, b -> a + b }

0 comments on commit 1c97997

Please sign in to comment.