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
11 changes: 5 additions & 6 deletions projectguard/api/projectguard.api
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ public abstract interface class com/rubensousa/projectguard/plugin/DenyScope {
}

public abstract interface class com/rubensousa/projectguard/plugin/DependencyRestrictionScope {
public abstract fun allow (Ljava/lang/String;)V
public abstract fun allow (Ljava/util/List;)V
public abstract fun allow ([Ljava/lang/String;)V
public abstract fun allow ([Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;)V
public abstract fun applyRule (Lcom/rubensousa/projectguard/plugin/RestrictDependencyRule;)V
public abstract fun reason (Ljava/lang/String;)V
}
Expand All @@ -25,10 +25,9 @@ public final class com/rubensousa/projectguard/plugin/GuardScope$Companion {
}

public abstract interface class com/rubensousa/projectguard/plugin/ModuleRestrictionScope {
public abstract fun allow (Ljava/lang/String;)V
public abstract fun allow (Lorg/gradle/api/provider/Provider;)V
public abstract fun allowLibs (Ljava/util/List;)V
public abstract fun allowModules (Ljava/util/List;)V
public abstract fun allow ([Ljava/lang/String;)V
public abstract fun allow ([Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;)V
public abstract fun allow ([Lorg/gradle/api/provider/Provider;)V
public abstract fun applyRule (Lcom/rubensousa/projectguard/plugin/RestrictModuleRule;)V
public abstract fun reason (Ljava/lang/String;)V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@

package com.rubensousa.projectguard.plugin

import org.gradle.api.internal.catalog.DelegatingProjectDependency


interface DependencyRestrictionScope {

fun reason(reason: String)

fun allow(modulePath: String)
fun allow(vararg modulePath: String)

fun allow(modulePaths: List<String>)
fun allow(vararg moduleDelegation: DelegatingProjectDependency)

fun applyRule(rule: RestrictDependencyRule)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@
package com.rubensousa.projectguard.plugin

import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.internal.catalog.DelegatingProjectDependency
import org.gradle.api.provider.Provider

interface ModuleRestrictionScope {

fun reason(reason: String)

fun allow(modulePath: String)
fun allow(vararg modulePath: String)

fun allow(library: Provider<MinimalExternalModuleDependency>)
fun allow(vararg moduleDelegation: DelegatingProjectDependency)

fun allowModules(modulePaths: List<String>)

fun allowLibs(libraries: List<Provider<MinimalExternalModuleDependency>>)
fun allow(vararg library: Provider<MinimalExternalModuleDependency>)

fun applyRule(rule: RestrictModuleRule)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.rubensousa.projectguard.plugin.internal

import com.rubensousa.projectguard.plugin.DependencyRestrictionScope
import com.rubensousa.projectguard.plugin.RestrictDependencyRule
import org.gradle.api.internal.catalog.DelegatingProjectDependency

internal class DependencyRestrictionScopeImpl : DependencyRestrictionScope {

Expand All @@ -28,18 +29,14 @@ internal class DependencyRestrictionScopeImpl : DependencyRestrictionScope {
restrictionReason = reason
}

override fun allow(modulePath: String) {
allowed.add(
ModuleAllowSpec(
modulePath = modulePath,
)
)
override fun allow(vararg modulePath: String) {
allowed.addAll(modulePath.map { path ->
ModuleAllowSpec(modulePath = path)
})
}

override fun allow(modulePaths: List<String>) {
modulePaths.forEach { path ->
allow(path)
}
override fun allow(vararg moduleDelegation: DelegatingProjectDependency) {
allow(modulePath = moduleDelegation.map { module -> module.path }.toTypedArray())
}

override fun applyRule(rule: RestrictDependencyRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.rubensousa.projectguard.plugin.internal
import com.rubensousa.projectguard.plugin.ModuleRestrictionScope
import com.rubensousa.projectguard.plugin.RestrictModuleRule
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.internal.catalog.DelegatingProjectDependency
import org.gradle.api.provider.Provider

internal class ModuleRestrictionScopeImpl : ModuleRestrictionScope {
Expand All @@ -30,24 +31,20 @@ internal class ModuleRestrictionScopeImpl : ModuleRestrictionScope {
restrictionReason = reason
}

override fun allow(modulePath: String) {
allowed.add(
ModuleAllowSpec(
modulePath = modulePath,
)
)
override fun allow(vararg modulePath: String) {
allowed.addAll(modulePath.map { path ->
ModuleAllowSpec(modulePath = path)
})
}

override fun allowModules(modulePaths: List<String>) {
modulePaths.forEach { path -> allow(path) }
override fun allow(vararg moduleDelegation: DelegatingProjectDependency) {
allow(modulePath = moduleDelegation.map { module -> module.path }.toTypedArray())
}

override fun allow(library: Provider<MinimalExternalModuleDependency>) {
allow(library.getDependencyPath())
}

override fun allowLibs(libraries: List<Provider<MinimalExternalModuleDependency>>) {
libraries.forEach { library -> allow(library) }
override fun allow(vararg library: Provider<MinimalExternalModuleDependency>) {
allow(modulePath = library.map { lib ->
lib.getDependencyPath()
}.toTypedArray())
}

override fun applyRule(rule: RestrictModuleRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class DependencyRestrictionTest {
// given
val spec = projectGuard {
restrictDependency(":legacy") {
allow(listOf(":legacy:a", ":legacy:b"))
allow(":legacy:a", ":legacy:b")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class ModuleRestrictionTest {
// given
val spec = projectGuard {
restrictModule(":domain") {
allowModules(listOf(":domain:a", ":domain:b"))
allow(":domain:a", ":domain:b")
}
}

Expand Down
4 changes: 4 additions & 0 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ projectGuard {
// Test dependencies are fine
allow(libs.junit)
}
restrictModule(":feature") {
allow(":feature:a", ":feature:b")
allow(projects.feature.c, projects.feature.d)
}
restrictDependency(":legacy") {
reason("Legacy modules should no longer be used")

Expand Down
2 changes: 2 additions & 0 deletions sample/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ dependencyResolutionManagement {
}

rootProject.name = "ProjectGuardSample"
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

include(":data:a")
include(":data:b")
include(":data:c")
Expand Down