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
30 changes: 17 additions & 13 deletions projectguard/api/projectguard.api
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public final class com/rubensousa/projectguard/plugin/GuardRule {
}

public abstract interface class com/rubensousa/projectguard/plugin/GuardScope {
public static final field Companion Lcom/rubensousa/projectguard/plugin/GuardScope$Companion;
public abstract fun applyRule (Lcom/rubensousa/projectguard/plugin/GuardRule;)V
public fun deny (Ljava/lang/String;)V
public fun deny (Ljava/lang/String;Lgroovy/lang/Closure;)V
public abstract fun deny (Ljava/lang/String;Lorg/gradle/api/Action;)V
public fun deny (Lorg/gradle/api/provider/Provider;)V
public fun deny (Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;Lorg/gradle/api/Action;)V
public fun deny (Lorg/gradle/api/provider/Provider;Lgroovy/lang/Closure;)V
public abstract fun deny (Lorg/gradle/api/provider/Provider;Lorg/gradle/api/Action;)V
}

public final class com/rubensousa/projectguard/plugin/GuardScope$Companion {
public static synthetic fun deny$default (Lcom/rubensousa/projectguard/plugin/GuardScope;Ljava/lang/String;Lorg/gradle/api/Action;ILjava/lang/Object;)V
public static synthetic fun deny$default (Lcom/rubensousa/projectguard/plugin/GuardScope;Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;Lorg/gradle/api/Action;ILjava/lang/Object;)V
public static synthetic fun deny$default (Lcom/rubensousa/projectguard/plugin/GuardScope;Lorg/gradle/api/provider/Provider;Lorg/gradle/api/Action;ILjava/lang/Object;)V
}

public abstract interface class com/rubensousa/projectguard/plugin/ModuleRestrictionScope {
Expand Down Expand Up @@ -51,22 +51,26 @@ public final class com/rubensousa/projectguard/plugin/ProjectGuardPlugin : org/g
}

public abstract interface class com/rubensousa/projectguard/plugin/ProjectGuardScope {
public static final field Companion Lcom/rubensousa/projectguard/plugin/ProjectGuardScope$Companion;
public abstract fun guard (Ljava/lang/String;Lorg/gradle/api/Action;)V
public fun guard (Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;Lorg/gradle/api/Action;)V
public abstract fun guardRule (Lorg/gradle/api/Action;)Lcom/rubensousa/projectguard/plugin/GuardRule;
public fun restrictDependency (Ljava/lang/String;)V
public fun restrictDependency (Ljava/lang/String;Lgroovy/lang/Closure;)V
public abstract fun restrictDependency (Ljava/lang/String;Lorg/gradle/api/Action;)V
public fun restrictDependency (Lorg/gradle/api/provider/Provider;)V
public fun restrictDependency (Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;Lorg/gradle/api/Action;)V
public fun restrictDependency (Lorg/gradle/api/provider/Provider;Lgroovy/lang/Closure;)V
public abstract fun restrictDependency (Lorg/gradle/api/provider/Provider;Lorg/gradle/api/Action;)V
public static synthetic fun restrictDependency$default (Lcom/rubensousa/projectguard/plugin/ProjectGuardScope;Ljava/lang/String;Lorg/gradle/api/Action;ILjava/lang/Object;)V
public static synthetic fun restrictDependency$default (Lcom/rubensousa/projectguard/plugin/ProjectGuardScope;Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;Lorg/gradle/api/Action;ILjava/lang/Object;)V
public static synthetic fun restrictDependency$default (Lcom/rubensousa/projectguard/plugin/ProjectGuardScope;Lorg/gradle/api/provider/Provider;Lorg/gradle/api/Action;ILjava/lang/Object;)V
public abstract fun restrictDependencyRule (Lorg/gradle/api/Action;)Lcom/rubensousa/projectguard/plugin/RestrictDependencyRule;
public fun restrictModule (Ljava/lang/String;)V
public fun restrictModule (Ljava/lang/String;Lgroovy/lang/Closure;)V
public abstract fun restrictModule (Ljava/lang/String;Lorg/gradle/api/Action;)V
public fun restrictModule (Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;Lorg/gradle/api/Action;)V
public static synthetic fun restrictModule$default (Lcom/rubensousa/projectguard/plugin/ProjectGuardScope;Ljava/lang/String;Lorg/gradle/api/Action;ILjava/lang/Object;)V
public static synthetic fun restrictModule$default (Lcom/rubensousa/projectguard/plugin/ProjectGuardScope;Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;Lorg/gradle/api/Action;ILjava/lang/Object;)V
public abstract fun restrictModuleRule (Lorg/gradle/api/Action;)Lcom/rubensousa/projectguard/plugin/RestrictModuleRule;
}

public final class com/rubensousa/projectguard/plugin/ProjectGuardScope$Companion {
}

public final class com/rubensousa/projectguard/plugin/RestrictDependencyRule {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,45 @@

package com.rubensousa.projectguard.plugin

import groovy.lang.Closure
import org.gradle.api.Action
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.internal.catalog.DelegatingProjectDependency
import org.gradle.api.provider.Provider
import org.gradle.util.internal.ConfigureUtil

interface GuardScope {

fun deny(
dependencyPath: String,
action: Action<DenyScope>,
action: Action<DenyScope> = Action<DenyScope> { },
)

fun deny(
dependencyDelegation: DelegatingProjectDependency,
action: Action<DenyScope> = Action<DenyScope> { },
) = deny(dependencyPath = dependencyDelegation.path, action = action)

fun deny(
provider: Provider<MinimalExternalModuleDependency>,
action: Action<DenyScope>,
action: Action<DenyScope> = Action<DenyScope> { },
)

// Required for groovy compatibility
fun deny(
dependencyPath: String,
closure: Closure<DenyScope>
) {
deny(dependencyPath, defaultDenyScope)
deny(dependencyPath, ConfigureUtil.configureUsing(closure))
}

// Required for groovy compatibility
fun deny(
provider: Provider<MinimalExternalModuleDependency>,
closure: Closure<DenyScope>
) {
deny(provider, defaultDenyScope)
deny(provider, ConfigureUtil.configureUsing(closure))
}

fun applyRule(rule: GuardRule)

companion object {
internal val defaultDenyScope = Action<DenyScope> { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.rubensousa.projectguard.plugin.internal.ProjectGuardSpec
import com.rubensousa.projectguard.plugin.internal.getDependencyPath
import org.gradle.api.Action
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.internal.catalog.DelegatingProjectDependency
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.listProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

package com.rubensousa.projectguard.plugin

import groovy.lang.Closure
import org.gradle.api.Action
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.internal.catalog.DelegatingProjectDependency
import org.gradle.api.provider.Provider
import org.gradle.util.internal.ConfigureUtil

interface ProjectGuardScope {

Expand Down Expand Up @@ -52,12 +55,29 @@ interface ProjectGuardScope {
*/
fun restrictModule(
modulePath: String,
action: Action<ModuleRestrictionScope>,
action: Action<ModuleRestrictionScope> = Action<ModuleRestrictionScope> { },
)

/**
* Example:
*
* Prevent a module from depending on all other dependencies
*
* ```
* restrictModule(projects.domain) {
* // Domain modules can only depend on another domain modules
* allow(":domain")
* }
* ```
*/
fun restrictModule(
moduleDelegation: DelegatingProjectDependency,
action: Action<ModuleRestrictionScope> = Action<ModuleRestrictionScope> { }
) = restrictModule(modulePath = moduleDelegation.path, action = action)

// Just here for groovy support
fun restrictModule(modulePath: String) {
restrictModule(modulePath, defaultModuleRestrictionScope)
fun restrictModule(modulePath: String, closure: Closure<ModuleRestrictionScope>) {
restrictModule(modulePath, ConfigureUtil.configureUsing(closure))
}

/**
Expand Down Expand Up @@ -90,6 +110,21 @@ interface ProjectGuardScope {
action: Action<GuardScope>,
)

/**
* Example:
*
* ```
* guard(projects.domain) {
* // Domain modules should not depend on UI modules
* deny(":ui")
* }
* ```
*/
fun guard(
moduleDelegation: DelegatingProjectDependency,
action: Action<GuardScope>
) = guard(modulePath = moduleDelegation.path, action = action)

/**
* Example:
*
Expand Down Expand Up @@ -117,9 +152,24 @@ interface ProjectGuardScope {
*/
fun restrictDependency(
dependencyPath: String,
action: Action<DependencyRestrictionScope>,
action: Action<DependencyRestrictionScope> = Action<DependencyRestrictionScope> { },
)

/**
* Example:
*
* ```
* restrictDependency(projects.legacy) {
* // Only legacy modules are allowed to depend on other legacy modules
* allow(":legacy")
* }
* ```
*/
fun restrictDependency(
dependencyDelegation: DelegatingProjectDependency,
action: Action<DependencyRestrictionScope> = Action<DependencyRestrictionScope> { }
) = restrictDependency(dependencyPath = dependencyDelegation.path, action = action)

/**
* Example:
*
Expand All @@ -132,22 +182,22 @@ interface ProjectGuardScope {
*/
fun restrictDependency(
provider: Provider<MinimalExternalModuleDependency>,
action: Action<DependencyRestrictionScope>,
action: Action<DependencyRestrictionScope> = Action<DependencyRestrictionScope> { },
)

// Just here for groovy support
fun restrictDependency(dependencyPath: String) {
restrictDependency(dependencyPath, defaultDependencyRestrictionScope)
fun restrictDependency(
dependencyPath: String,
closure: Closure<DependencyRestrictionScope>
) {
restrictDependency(dependencyPath, ConfigureUtil.configureUsing(closure))
}

// Just here for groovy support
fun restrictDependency(provider: Provider<MinimalExternalModuleDependency>) {
restrictDependency(provider, defaultDependencyRestrictionScope)
}

companion object {
private val defaultDependencyRestrictionScope = Action<DependencyRestrictionScope> {}
private val defaultModuleRestrictionScope = Action<ModuleRestrictionScope> {}

fun restrictDependency(
provider: Provider<MinimalExternalModuleDependency>,
closure: Closure<DependencyRestrictionScope>
) {
restrictDependency(provider, ConfigureUtil.configureUsing(closure))
}
}