Skip to content

Commit e7f59d0

Browse files
committed
fix configuration cache compatibility in scm info plugin
add archrules to track deprecation usage
1 parent 1643afa commit e7f59d0

25 files changed

+856
-464
lines changed

build.gradle.kts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.gradle.plugin.compatibility.compatibility
2+
13
/*
24
* Copyright 2014-2019 Netflix, Inc.
35
*
@@ -15,8 +17,9 @@
1517
*/
1618

1719
plugins {
18-
id("com.netflix.nebula.plugin-plugin") version ("25.+")
20+
id("com.netflix.nebula.plugin-plugin")
1921
`kotlin-dsl`
22+
id("com.netflix.nebula.archrules.library")
2023
}
2124

2225
description = "Gradle plugin collect and provide information about the environment"
@@ -41,6 +44,8 @@ dependencies {
4144
testImplementation("org.spockframework:spock-junit4:2.4-groovy-4.0")
4245
testImplementation("org.eclipse.jgit:org.eclipse.jgit:7.+")
4346
testImplementation(libs.assertj)
47+
48+
archRulesImplementation("com.netflix.nebula:archrules-common:0.+")
4449
}
4550

4651
testing {
@@ -87,6 +92,11 @@ gradlePlugin {
8792
description = project.description
8893
implementationClass = "nebula.plugin.info.ci.ContinuousIntegrationInfoPlugin"
8994
tags.set(listOf("nebula", "info"))
95+
compatibility {
96+
features {
97+
configurationCache = true
98+
}
99+
}
90100
}
91101
create("infoJAR") {
92102
id = "com.netflix.nebula.info-jar"
@@ -129,6 +139,11 @@ gradlePlugin {
129139
description = project.description
130140
implementationClass = "nebula.plugin.info.scm.ScmInfoPlugin"
131141
tags.set(listOf("nebula", "info"))
142+
compatibility {
143+
features {
144+
configurationCache = true
145+
}
146+
}
132147
}
133148
}
134149
}

gradle.lockfile

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
cglib:cglib-nodep:3.2.2=testRuntimeClasspath
55
com.github.stefanbirkner:system-rules:1.19.0=testCompileClasspath,testRuntimeClasspath
66
com.googlecode.javaewah:JavaEWAH:1.2.3=testCompileClasspath,testRuntimeClasspath
7-
com.jcraft:jzlib:1.1.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
8-
com.netflix.nebula:gradle-contacts-plugin:8.1.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
9-
com.netflix.nebula:nebula-gradle-interop:3.1.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
10-
com.netflix.nebula:nebula-test:11.11.3=testCompileClasspath,testRuntimeClasspath
11-
com.perforce:p4java:2015.2.1365273=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
7+
com.jcraft:jzlib:1.1.2=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
8+
com.netflix.nebula:archrules-common:0.9.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
9+
com.netflix.nebula:gradle-contacts-plugin:8.1.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
10+
com.netflix.nebula:nebula-archrules-core:0.14.2=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
11+
com.netflix.nebula:nebula-gradle-interop:3.1.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
12+
com.netflix.nebula:nebula-test:11.12.0=testCompileClasspath,testRuntimeClasspath
13+
com.perforce:p4java:2015.2.1365273=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
14+
com.tngtech.archunit:archunit:1.4.1=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
1215
commons-codec:commons-codec:1.20.0=testCompileClasspath,testRuntimeClasspath
1316
io.leangen.geantyref:geantyref:1.3.16=testRuntimeClasspath
1417
junit:junit-dep:4.11=testCompileClasspath,testRuntimeClasspath
1518
junit:junit:4.13.2=testCompileClasspath,testRuntimeClasspath
1619
net.bytebuddy:byte-buddy:1.18.3=testCompileClasspath,testRuntimeClasspath
17-
net.java.dev.jna:jna-platform:5.16.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
18-
net.java.dev.jna:jna:5.16.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
20+
net.java.dev.jna:jna-platform:5.16.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
21+
net.java.dev.jna:jna:5.16.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1922
org.ajoberstar.grgit:grgit-core:4.1.1=testCompileClasspath,testRuntimeClasspath
2023
org.apache.groovy:groovy-bom:4.0.29=testCompileClasspath,testRuntimeClasspath
2124
org.apache.groovy:groovy:4.0.29=testCompileClasspath,testRuntimeClasspath
@@ -26,21 +29,29 @@ org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath
2629
org.hamcrest:hamcrest:3.0=testCompileClasspath,testRuntimeClasspath
2730
org.jetbrains.kotlin:kotlin-reflect:2.2.20=compileClasspath,embeddedKotlin,testCompileClasspath,testRuntimeClasspath
2831
org.jetbrains.kotlin:kotlin-stdlib:2.2.0=runtimeClasspath
29-
org.jetbrains.kotlin:kotlin-stdlib:2.2.20=compileClasspath,embeddedKotlin,testCompileClasspath,testRuntimeClasspath
30-
org.jetbrains:annotations:13.0=compileClasspath,embeddedKotlin,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
31-
org.jspecify:jspecify:1.0.0=testCompileClasspath,testRuntimeClasspath
32-
org.junit.jupiter:junit-jupiter-api:5.14.1=testCompileClasspath,testRuntimeClasspath
33-
org.junit.jupiter:junit-jupiter-engine:5.14.1=testRuntimeClasspath
34-
org.junit.jupiter:junit-jupiter-params:5.14.1=testCompileClasspath,testRuntimeClasspath
35-
org.junit.jupiter:junit-jupiter:5.14.1=testCompileClasspath,testRuntimeClasspath
36-
org.junit.platform:junit-platform-commons:1.14.1=testCompileClasspath,testRuntimeClasspath
37-
org.junit.platform:junit-platform-engine:1.14.1=testCompileClasspath,testRuntimeClasspath
38-
org.junit.platform:junit-platform-launcher:1.14.1=testCompileClasspath,testRuntimeClasspath
39-
org.junit:junit-bom:5.14.1=testCompileClasspath,testRuntimeClasspath
32+
org.jetbrains.kotlin:kotlin-stdlib:2.2.20=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,embeddedKotlin,testCompileClasspath,testRuntimeClasspath
33+
org.jetbrains:annotations:13.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,embeddedKotlin,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
34+
org.jspecify:jspecify:1.0.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
35+
org.junit.jupiter:junit-jupiter-api:5.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
36+
org.junit.jupiter:junit-jupiter-api:5.14.3=testCompileClasspath,testRuntimeClasspath
37+
org.junit.jupiter:junit-jupiter-engine:5.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
38+
org.junit.jupiter:junit-jupiter-engine:5.14.3=testRuntimeClasspath
39+
org.junit.jupiter:junit-jupiter-params:5.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
40+
org.junit.jupiter:junit-jupiter-params:5.14.3=testCompileClasspath,testRuntimeClasspath
41+
org.junit.jupiter:junit-jupiter:5.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
42+
org.junit.jupiter:junit-jupiter:5.14.3=testCompileClasspath,testRuntimeClasspath
43+
org.junit.platform:junit-platform-commons:1.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
44+
org.junit.platform:junit-platform-commons:1.14.3=testCompileClasspath,testRuntimeClasspath
45+
org.junit.platform:junit-platform-engine:1.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
46+
org.junit.platform:junit-platform-engine:1.14.3=testCompileClasspath,testRuntimeClasspath
47+
org.junit.platform:junit-platform-launcher:1.12.2=archRulesTestRuntimeClasspath
48+
org.junit.platform:junit-platform-launcher:1.14.3=testCompileClasspath,testRuntimeClasspath
49+
org.junit:junit-bom:5.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
50+
org.junit:junit-bom:5.14.3=testCompileClasspath,testRuntimeClasspath
4051
org.objenesis:objenesis:2.4=testRuntimeClasspath
41-
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testRuntimeClasspath
42-
org.slf4j:slf4j-api:2.0.17=testCompileClasspath,testRuntimeClasspath
52+
org.opentest4j:opentest4j:1.3.0=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
53+
org.slf4j:slf4j-api:2.0.17=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
4354
org.spockframework:spock-bom:2.4-groovy-4.0=testCompileClasspath,testRuntimeClasspath
4455
org.spockframework:spock-core:2.4-groovy-4.0=testCompileClasspath,testRuntimeClasspath
4556
org.spockframework:spock-junit4:2.4-groovy-4.0=testCompileClasspath,testRuntimeClasspath
46-
empty=annotationProcessor,testAnnotationProcessor
57+
empty=annotationProcessor,archRulesAnnotationProcessor,archRulesTestAnnotationProcessor,testAnnotationProcessor
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
toolchainVersion=21

settings.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
pluginManagement {
2+
plugins {
3+
id("com.netflix.nebula.plugin-plugin") version ("25.+")
4+
id("com.netflix.nebula.archrules.library") version ("0.+")
5+
}
6+
}
7+
18
plugins {
29
id "com.gradle.develocity" version "4.2"
310
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package nebula.plugin.info.archrules;
2+
3+
import com.netflix.nebula.archrules.core.ArchRulesService;
4+
import com.tngtech.archunit.lang.ArchRule;
5+
import com.tngtech.archunit.lang.Priority;
6+
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition;
7+
import org.jspecify.annotations.NullMarked;
8+
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
import static com.netflix.nebula.archrules.common.CanBeAnnotated.Predicates.deprecated;
13+
import static com.netflix.nebula.archrules.common.CanBeAnnotated.Predicates.deprecatedForRemoval;
14+
import static com.tngtech.archunit.core.domain.JavaAccess.Predicates.target;
15+
import static com.tngtech.archunit.core.domain.JavaAccess.Predicates.targetOwner;
16+
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.resideInAPackage;
17+
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.resideOutsideOfPackages;
18+
import static com.tngtech.archunit.lang.conditions.ArchPredicates.are;
19+
import static com.tngtech.archunit.lang.conditions.ArchPredicates.is;
20+
21+
@NullMarked
22+
public class NebulaGradleInfoPluginArchRules implements ArchRulesService {
23+
private static final String thisPackage = "nebula.plugin.info..";
24+
static final ArchRule DEPRECATED = ArchRuleDefinition.priority(Priority.MEDIUM)
25+
.noClasses().that(resideOutsideOfPackages(thisPackage))
26+
.should().dependOnClassesThat(resideInAPackage(thisPackage)
27+
.and(are(deprecated())))
28+
.orShould().accessTargetWhere(targetOwner(resideInAPackage(thisPackage))
29+
.and(target(is(deprecated()))))
30+
.allowEmptyShould(true)
31+
.because("deprecated APIs will be removed in a future version of nebula-gradle-info");
32+
33+
static final ArchRule DEPRECATED_FOR_REMOVAL = ArchRuleDefinition.priority(Priority.HIGH)
34+
.noClasses().that(resideOutsideOfPackages(thisPackage))
35+
.should().dependOnClassesThat(resideInAPackage(thisPackage)
36+
.and(are(deprecatedForRemoval())))
37+
.orShould().accessTargetWhere(targetOwner(resideInAPackage(thisPackage))
38+
.and(target(is(deprecatedForRemoval()))))
39+
.allowEmptyShould(true)
40+
.because("deprecated for removal APIs will be removed in the next major version of nebula-gradle-info");
41+
42+
@Override
43+
public Map<String, ArchRule> getRules() {
44+
Map<String, ArchRule> rules = new HashMap<>();
45+
rules.put("nebula-gradle-info deprecated", DEPRECATED);
46+
rules.put("nebula-gradle-info deprecated for removal", DEPRECATED_FOR_REMOVAL);
47+
return rules;
48+
}
49+
}

src/main/groovy/nebula/plugin/info/scm/AbstractScmProvider.groovy

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@
1717
package nebula.plugin.info.scm
1818

1919
import org.gradle.api.Project
20+
import org.gradle.api.file.RegularFile
2021
import org.gradle.api.provider.ProviderFactory
22+
import org.jspecify.annotations.NullMarked
23+
import org.jspecify.annotations.Nullable
2124

22-
25+
@NullMarked
2326
abstract class AbstractScmProvider implements ScmInfoProvider {
24-
abstract calculateModuleSource(File projectDir)
27+
/**
28+
* @deprecated Use {@link #source()} instead
29+
*/
30+
@Deprecated
31+
@Nullable
32+
String calculateModuleSource(File projectDir) {
33+
source().getOrNull()
34+
}
2535

2636
private final ProviderFactory providerFactory
2737

@@ -33,53 +43,55 @@ abstract class AbstractScmProvider implements ScmInfoProvider {
3343
return this.providerFactory
3444
}
3545

36-
@Override
37-
String calculateSource(Project project) {
38-
return calculateModuleSource(project.projectDir)
39-
}
40-
41-
protected File findFile(File starting, String filename) {
42-
// TODO Stop looking when we get to the home directory, to avoid paths which we know aren't a SCM root
43-
if (!filename) {
44-
return null
46+
/**
47+
* when we convert to kotlin, make sure to optimise with tailrec
48+
*/
49+
@Nullable
50+
protected RegularFile findFile(Project starting, String filename) {
51+
RegularFile file = starting.layout.projectDirectory.file(filename)
52+
if (file.asFile.exists()) {
53+
println("found" +filename + " at " + file.asFile.absolutePath)
54+
return file
4555
}
46-
47-
File dirToLookIn = starting
48-
while(dirToLookIn) {
49-
File p4configFile = new File(dirToLookIn, filename)
50-
if (p4configFile.exists()) {
51-
return p4configFile
52-
}
53-
dirToLookIn = dirToLookIn?.getParentFile()
56+
if (starting.parent == null) {
57+
return null
5458
}
55-
return null
59+
return findFile(starting.parent, filename)
5660
}
5761

58-
@Override
59-
String calculateOrigin(Project project) {
60-
return calculateModuleOrigin(project.projectDir)
62+
/**
63+
* @deprecated Use {@link #origin()} instead
64+
*/
65+
@Deprecated
66+
@Nullable
67+
String calculateModuleOrigin(File projectDir) {
68+
return origin().getOrNull()
6169
}
6270

63-
abstract calculateModuleOrigin(File projectDir)
64-
65-
@Override
66-
String calculateChange(Project project) {
67-
return calculateChange(project.projectDir)
71+
/**
72+
* @deprecated Use {@link #change()} instead
73+
*/
74+
@Nullable
75+
@Deprecated
76+
String calculateChange(File projectDir) {
77+
change().getOrNull()
6878
}
6979

70-
abstract calculateChange(File projectDir)
71-
72-
@Override
73-
String calculateFullChange(Project project) {
74-
return calculateFullChange(project.projectDir)
80+
/**
81+
* @deprecated Use {@link #fullChange()} instead
82+
*/
83+
@Nullable
84+
@Deprecated
85+
String calculateFullChange(File projectDir) {
86+
return fullChange().getOrNull()
7587
}
7688

77-
abstract calculateFullChange(File projectDir)
78-
79-
@Override
80-
String calculateBranch(Project project) {
81-
return calculateBranch(project.projectDir)
89+
/**
90+
* @deprecated Use {@link #branch()} instead
91+
*/
92+
@Nullable
93+
@Deprecated
94+
String calculateBranch(File projectDir) {
95+
return branch().getOrNull()
8296
}
83-
84-
abstract calculateBranch(File projectDir)
8597
}

0 commit comments

Comments
 (0)