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
17 changes: 16 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.gradle.plugin.compatibility.compatibility

/*
* Copyright 2014-2019 Netflix, Inc.
*
Expand All @@ -15,8 +17,9 @@
*/

plugins {
id("com.netflix.nebula.plugin-plugin") version ("25.+")
id("com.netflix.nebula.plugin-plugin")
`kotlin-dsl`
id("com.netflix.nebula.archrules.library")
}

description = "Gradle plugin collect and provide information about the environment"
Expand All @@ -41,6 +44,8 @@ dependencies {
testImplementation("org.spockframework:spock-junit4:2.4-groovy-4.0")
testImplementation("org.eclipse.jgit:org.eclipse.jgit:7.+")
testImplementation(libs.assertj)

archRulesImplementation("com.netflix.nebula:archrules-common:0.+")
}

testing {
Expand Down Expand Up @@ -87,6 +92,11 @@ gradlePlugin {
description = project.description
implementationClass = "nebula.plugin.info.ci.ContinuousIntegrationInfoPlugin"
tags.set(listOf("nebula", "info"))
compatibility {
features {
configurationCache = true
}
}
}
create("infoJAR") {
id = "com.netflix.nebula.info-jar"
Expand Down Expand Up @@ -129,6 +139,11 @@ gradlePlugin {
description = project.description
implementationClass = "nebula.plugin.info.scm.ScmInfoPlugin"
tags.set(listOf("nebula", "info"))
compatibility {
features {
configurationCache = true
}
}
}
}
}
53 changes: 32 additions & 21 deletions gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
cglib:cglib-nodep:3.2.2=testRuntimeClasspath
com.github.stefanbirkner:system-rules:1.19.0=testCompileClasspath,testRuntimeClasspath
com.googlecode.javaewah:JavaEWAH:1.2.3=testCompileClasspath,testRuntimeClasspath
com.jcraft:jzlib:1.1.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:gradle-contacts-plugin:8.1.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-gradle-interop:3.1.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-test:11.11.3=testCompileClasspath,testRuntimeClasspath
com.perforce:p4java:2015.2.1365273=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.jcraft:jzlib:1.1.2=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:archrules-common:0.9.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
com.netflix.nebula:gradle-contacts-plugin:8.1.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-archrules-core:0.14.2=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
com.netflix.nebula:nebula-gradle-interop:3.1.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-test:11.12.0=testCompileClasspath,testRuntimeClasspath
com.perforce:p4java:2015.2.1365273=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.tngtech.archunit:archunit:1.4.1=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
commons-codec:commons-codec:1.20.0=testCompileClasspath,testRuntimeClasspath
io.leangen.geantyref:geantyref:1.3.16=testRuntimeClasspath
junit:junit-dep:4.11=testCompileClasspath,testRuntimeClasspath
junit:junit:4.13.2=testCompileClasspath,testRuntimeClasspath
net.bytebuddy:byte-buddy:1.18.3=testCompileClasspath,testRuntimeClasspath
net.java.dev.jna:jna-platform:5.16.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
net.java.dev.jna:jna:5.16.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
net.java.dev.jna:jna-platform:5.16.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
net.java.dev.jna:jna:5.16.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ajoberstar.grgit:grgit-core:4.1.1=testCompileClasspath,testRuntimeClasspath
org.apache.groovy:groovy-bom:4.0.29=testCompileClasspath,testRuntimeClasspath
org.apache.groovy:groovy:4.0.29=testCompileClasspath,testRuntimeClasspath
Expand All @@ -26,21 +29,29 @@ org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath
org.hamcrest:hamcrest:3.0=testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-reflect:2.2.20=compileClasspath,embeddedKotlin,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:2.2.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:2.2.20=compileClasspath,embeddedKotlin,testCompileClasspath,testRuntimeClasspath
org.jetbrains:annotations:13.0=compileClasspath,embeddedKotlin,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jspecify:jspecify:1.0.0=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.14.1=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.14.1=testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.14.1=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter:5.14.1=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.14.1=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.14.1=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.14.1=testCompileClasspath,testRuntimeClasspath
org.junit:junit-bom:5.14.1=testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:2.2.20=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,embeddedKotlin,testCompileClasspath,testRuntimeClasspath
org.jetbrains:annotations:13.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,compileClasspath,embeddedKotlin,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jspecify:jspecify:1.0.0=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.14.3=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.14.3=testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.14.3=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter:5.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
org.junit.jupiter:junit-jupiter:5.14.3=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
org.junit.platform:junit-platform-commons:1.14.3=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
org.junit.platform:junit-platform-engine:1.14.3=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.12.2=archRulesTestRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.14.3=testCompileClasspath,testRuntimeClasspath
org.junit:junit-bom:5.12.2=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
org.junit:junit-bom:5.14.3=testCompileClasspath,testRuntimeClasspath
org.objenesis:objenesis:2.4=testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testRuntimeClasspath
org.slf4j:slf4j-api:2.0.17=testCompileClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.slf4j:slf4j-api:2.0.17=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.spockframework:spock-bom:2.4-groovy-4.0=testCompileClasspath,testRuntimeClasspath
org.spockframework:spock-core:2.4-groovy-4.0=testCompileClasspath,testRuntimeClasspath
org.spockframework:spock-junit4:2.4-groovy-4.0=testCompileClasspath,testRuntimeClasspath
empty=annotationProcessor,testAnnotationProcessor
empty=annotationProcessor,archRulesAnnotationProcessor,archRulesTestAnnotationProcessor,testAnnotationProcessor
1 change: 1 addition & 0 deletions gradle/gradle-daemon-jvm.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
toolchainVersion=21
7 changes: 7 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
pluginManagement {
plugins {
id("com.netflix.nebula.plugin-plugin") version ("25.+")
id("com.netflix.nebula.archrules.library") version ("0.+")
}
}

plugins {
id "com.gradle.develocity" version "4.2"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package nebula.plugin.info.archrules;

import com.netflix.nebula.archrules.core.ArchRulesService;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.Priority;
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition;
import org.jspecify.annotations.NullMarked;

import java.util.HashMap;
import java.util.Map;

import static com.netflix.nebula.archrules.common.CanBeAnnotated.Predicates.deprecated;
import static com.netflix.nebula.archrules.common.CanBeAnnotated.Predicates.deprecatedForRemoval;
import static com.tngtech.archunit.core.domain.JavaAccess.Predicates.target;
import static com.tngtech.archunit.core.domain.JavaAccess.Predicates.targetOwner;
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.resideInAPackage;
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.resideOutsideOfPackages;
import static com.tngtech.archunit.lang.conditions.ArchPredicates.are;
import static com.tngtech.archunit.lang.conditions.ArchPredicates.is;

@NullMarked
public class NebulaGradleInfoPluginArchRules implements ArchRulesService {
private static final String thisPackage = "nebula.plugin.info..";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to have two .s here? "nebula.plugin.info.."

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is an archunit thing that allows you to match package and all subpackages

static final ArchRule DEPRECATED = ArchRuleDefinition.priority(Priority.MEDIUM)
.noClasses().that(resideOutsideOfPackages(thisPackage))
.should().dependOnClassesThat(resideInAPackage(thisPackage)
.and(are(deprecated())))
.orShould().accessTargetWhere(targetOwner(resideInAPackage(thisPackage))
.and(target(is(deprecated()))))
.allowEmptyShould(true)
.because("deprecated APIs will be removed in a future version of nebula-gradle-info");

static final ArchRule DEPRECATED_FOR_REMOVAL = ArchRuleDefinition.priority(Priority.HIGH)
.noClasses().that(resideOutsideOfPackages(thisPackage))
.should().dependOnClassesThat(resideInAPackage(thisPackage)
.and(are(deprecatedForRemoval())))
.orShould().accessTargetWhere(targetOwner(resideInAPackage(thisPackage))
.and(target(is(deprecatedForRemoval()))))
.allowEmptyShould(true)
.because("deprecated for removal APIs will be removed in the next major version of nebula-gradle-info");

@Override
public Map<String, ArchRule> getRules() {
Map<String, ArchRule> rules = new HashMap<>();
rules.put("nebula-gradle-info deprecated", DEPRECATED);
rules.put("nebula-gradle-info deprecated for removal", DEPRECATED_FOR_REMOVAL);
return rules;
}
}
92 changes: 52 additions & 40 deletions src/main/groovy/nebula/plugin/info/scm/AbstractScmProvider.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@
package nebula.plugin.info.scm

import org.gradle.api.Project
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.ProviderFactory
import org.jspecify.annotations.NullMarked
import org.jspecify.annotations.Nullable


@NullMarked
abstract class AbstractScmProvider implements ScmInfoProvider {
abstract calculateModuleSource(File projectDir)
/**
* @deprecated Use {@link #source()} instead
*/
@Deprecated
@Nullable
String calculateModuleSource(File projectDir) {
source().getOrNull()
}

private final ProviderFactory providerFactory

Expand All @@ -33,53 +43,55 @@ abstract class AbstractScmProvider implements ScmInfoProvider {
return this.providerFactory
}

@Override
String calculateSource(Project project) {
return calculateModuleSource(project.projectDir)
}

protected File findFile(File starting, String filename) {
// TODO Stop looking when we get to the home directory, to avoid paths which we know aren't a SCM root
if (!filename) {
return null
/**
* when we convert to kotlin, make sure to optimise with tailrec
*/
@Nullable
protected RegularFile findFile(Project starting, String filename) {
RegularFile file = starting.layout.projectDirectory.file(filename)
if (file.asFile.exists()) {
println("found" +filename + " at " + file.asFile.absolutePath)
return file
}

File dirToLookIn = starting
while(dirToLookIn) {
File p4configFile = new File(dirToLookIn, filename)
if (p4configFile.exists()) {
return p4configFile
}
dirToLookIn = dirToLookIn?.getParentFile()
if (starting.parent == null) {
return null
}
return null
return findFile(starting.parent, filename)
}

@Override
String calculateOrigin(Project project) {
return calculateModuleOrigin(project.projectDir)
/**
* @deprecated Use {@link #origin()} instead
*/
@Deprecated
@Nullable
String calculateModuleOrigin(File projectDir) {
return origin().getOrNull()
}

abstract calculateModuleOrigin(File projectDir)

@Override
String calculateChange(Project project) {
return calculateChange(project.projectDir)
/**
* @deprecated Use {@link #change()} instead
*/
@Nullable
@Deprecated
String calculateChange(File projectDir) {
change().getOrNull()
}

abstract calculateChange(File projectDir)

@Override
String calculateFullChange(Project project) {
return calculateFullChange(project.projectDir)
/**
* @deprecated Use {@link #fullChange()} instead
*/
@Nullable
@Deprecated
String calculateFullChange(File projectDir) {
return fullChange().getOrNull()
}

abstract calculateFullChange(File projectDir)

@Override
String calculateBranch(Project project) {
return calculateBranch(project.projectDir)
/**
* @deprecated Use {@link #branch()} instead
*/
@Nullable
@Deprecated
String calculateBranch(File projectDir) {
return branch().getOrNull()
}

abstract calculateBranch(File projectDir)
}
Loading