Skip to content

Commit d15ad4b

Browse files
committed
Keep api backwards compatible
1 parent 67e6a33 commit d15ad4b

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

projectguard/api/projectguard.api

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ public final class com/rubensousa/projectguard/plugin/GuardRule {
1414

1515
public abstract interface class com/rubensousa/projectguard/plugin/GuardScope {
1616
public abstract fun applyRule (Lcom/rubensousa/projectguard/plugin/GuardRule;)V
17+
public fun deny (Ljava/lang/String;)V
1718
public fun deny (Ljava/lang/String;Lgroovy/lang/Closure;)V
1819
public abstract fun deny (Ljava/lang/String;Lorg/gradle/api/Action;)V
20+
public fun deny (Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;)V
21+
public fun deny (Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;Lgroovy/lang/Closure;)V
1922
public fun deny (Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;Lorg/gradle/api/Action;)V
23+
public fun deny (Lorg/gradle/api/provider/Provider;)V
2024
public fun deny (Lorg/gradle/api/provider/Provider;Lgroovy/lang/Closure;)V
2125
public abstract fun deny (Lorg/gradle/api/provider/Provider;Lorg/gradle/api/Action;)V
22-
public static synthetic fun deny$default (Lcom/rubensousa/projectguard/plugin/GuardScope;Ljava/lang/String;Lorg/gradle/api/Action;ILjava/lang/Object;)V
23-
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
24-
public static synthetic fun deny$default (Lcom/rubensousa/projectguard/plugin/GuardScope;Lorg/gradle/api/provider/Provider;Lorg/gradle/api/Action;ILjava/lang/Object;)V
2526
}
2627

2728
public abstract interface class com/rubensousa/projectguard/plugin/ModuleRestrictionScope {

projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/GuardScope.kt

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,63 @@ import org.gradle.api.internal.catalog.DelegatingProjectDependency
2323
import org.gradle.api.provider.Provider
2424
import org.gradle.util.internal.ConfigureUtil
2525

26+
private val emptyDenyScope = Action<DenyScope> { }
27+
2628
interface GuardScope {
2729

2830
fun deny(
2931
dependencyPath: String,
30-
action: Action<DenyScope> = Action<DenyScope> { },
32+
action: Action<DenyScope>,
3133
)
3234

35+
fun deny(
36+
provider: Provider<MinimalExternalModuleDependency>,
37+
action: Action<DenyScope>,
38+
)
39+
40+
fun applyRule(rule: GuardRule)
41+
3342
fun deny(
3443
dependencyDelegation: DelegatingProjectDependency,
35-
action: Action<DenyScope> = Action<DenyScope> { },
36-
) = deny(dependencyPath = dependencyDelegation.path, action = action)
44+
action: Action<DenyScope>,
45+
) {
46+
deny(dependencyPath = dependencyDelegation.path, action = action)
47+
}
48+
49+
// Required for groovy compatibility
50+
fun deny(dependencyPath: String) {
51+
deny(dependencyPath, emptyDenyScope)
52+
}
53+
54+
fun deny(dependencyDelegation: DelegatingProjectDependency) {
55+
deny(dependencyDelegation.path, emptyDenyScope)
56+
}
3757

3858
fun deny(
3959
provider: Provider<MinimalExternalModuleDependency>,
40-
action: Action<DenyScope> = Action<DenyScope> { },
41-
)
60+
) {
61+
deny(provider, emptyDenyScope)
62+
}
63+
64+
fun deny(
65+
dependencyDelegation: DelegatingProjectDependency,
66+
closure: Closure<DenyScope>,
67+
) {
68+
deny(dependencyDelegation.path, ConfigureUtil.configureUsing(closure))
69+
}
4270

43-
// Required for groovy compatibility
4471
fun deny(
4572
dependencyPath: String,
46-
closure: Closure<DenyScope>
73+
closure: Closure<DenyScope>,
4774
) {
4875
deny(dependencyPath, ConfigureUtil.configureUsing(closure))
4976
}
5077

51-
// Required for groovy compatibility
5278
fun deny(
5379
provider: Provider<MinimalExternalModuleDependency>,
54-
closure: Closure<DenyScope>
80+
closure: Closure<DenyScope>,
5581
) {
5682
deny(provider, ConfigureUtil.configureUsing(closure))
5783
}
5884

59-
fun applyRule(rule: GuardRule)
6085
}

projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/GroovyIntegrationTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ class GroovyIntegrationTest {
7171
pluginRunner.addDependency(from = module, to = dependency)
7272

7373
// then
74-
pluginRunner.assertCheckFailureContains(module, reason)
74+
pluginRunner.assertCheckFails(module)
75+
pluginRunner.assertTaskOutputContains(reason)
7576
}
7677

7778
@Test
@@ -96,6 +97,7 @@ class GroovyIntegrationTest {
9697

9798
// then
9899
pluginRunner.assertCheckSucceeds(module)
100+
pluginRunner.assertTaskOutputContains("No fatal matches found")
99101
}
100102

101103
}

projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/PluginRunner.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,17 @@ class PluginRunner(
4848
lastResult = result
4949
}
5050

51-
fun assertCheckFailureContains(module: String, message: String) {
52-
assertCheckFails(module)
53-
assertThat(lastResult!!.output).contains(message)
54-
}
55-
5651
fun assertCheckSucceeds(module: String) {
5752
val task = createCheckTask(module)
5853
val result = gradleRunner.withArguments(task).build()
5954
assertThat(result.task(task)!!.outcome).isEqualTo(TaskOutcome.SUCCESS)
6055
lastResult = result
6156
}
6257

58+
fun assertTaskOutputContains(message: String){
59+
assertThat(lastResult!!.output).contains(message)
60+
}
61+
6362
fun addDependency(from: String, to: String, configuration: String = "implementation") {
6463
temporaryFolder.getRoot().resolve("$from/build.gradle.kts").appendText(
6564
"""

0 commit comments

Comments
 (0)