Skip to content

Commit 629ec22

Browse files
authored
Merge pull request #30 from nebula-plugins/kts-support
add API to ContactsExtension that can be used from kts buildscripts
2 parents e9a7ac5 + 87ec131 commit 629ec22

File tree

10 files changed

+147
-81
lines changed

10 files changed

+147
-81
lines changed

.github/workflows/nebula.yml

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Nebula Build
22
on:
33
push:
44
branches:
5-
- '*'
5+
- 'main'
66
tags:
77
- v*.*.*
88
- v*.*.*-rc.*
@@ -38,20 +38,10 @@ jobs:
3838
17
3939
${{ matrix.java }}
4040
java-package: jdk
41-
- uses: actions/cache@v4
42-
id: gradle-cache
41+
- name: Setup Gradle
42+
uses: gradle/actions/setup-gradle@v5
4343
with:
44-
path: ~/.gradle/caches
45-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle/dependency-locks/*.lockfile') }}
46-
restore-keys: |
47-
- ${{ runner.os }}-gradle-
48-
- uses: actions/cache@v4
49-
id: gradle-wrapper-cache
50-
with:
51-
path: ~/.gradle/wrapper
52-
key: ${{ runner.os }}-gradlewrapper-${{ hashFiles('gradle/wrapper/*') }}
53-
restore-keys: |
54-
- ${{ runner.os }}-gradlewrapper-
44+
cache-overwrite-existing: true
5545
- name: Gradle build
5646
run: ./gradlew --info --stacktrace build
5747
env:
@@ -78,20 +68,10 @@ jobs:
7868
17
7969
21
8070
java-package: jdk
81-
- uses: actions/cache@v4
82-
id: gradle-cache
83-
with:
84-
path: ~/.gradle/caches
85-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle/dependency-locks/*.lockfile') }}
86-
restore-keys: |
87-
- ${{ runner.os }}-gradle-
88-
- uses: actions/cache@v4
89-
id: gradle-wrapper-cache
71+
- name: Setup Gradle
72+
uses: gradle/actions/setup-gradle@v5
9073
with:
91-
path: ~/.gradle/wrapper
92-
key: ${{ runner.os }}-gradlewrapper-${{ hashFiles('gradle/wrapper/*') }}
93-
restore-keys: |
94-
- ${{ runner.os }}-gradlewrapper-
74+
cache-overwrite-existing: true
9575
- name: Verify plugin publication
9676
if: |
9777
startsWith(github.ref, 'refs/tags/v') &&
@@ -123,20 +103,10 @@ jobs:
123103
17
124104
21
125105
java-package: jdk
126-
- uses: actions/cache@v4
127-
id: gradle-cache
128-
with:
129-
path: ~/.gradle/caches
130-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle/dependency-locks/*.lockfile') }}
131-
restore-keys: |
132-
- ${{ runner.os }}-gradle-
133-
- uses: actions/cache@v4
134-
id: gradle-wrapper-cache
106+
- name: Setup Gradle
107+
uses: gradle/actions/setup-gradle@v5
135108
with:
136-
path: ~/.gradle/wrapper
137-
key: ${{ runner.os }}-gradlewrapper-${{ hashFiles('gradle/wrapper/*') }}
138-
restore-keys: |
139-
- ${{ runner.os }}-gradlewrapper-
109+
cache-overwrite-existing: true
140110
- name: Publish candidate
141111
if: |
142112
startsWith(github.ref, 'refs/tags/v') &&

.java-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

build.gradle

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
plugins {
17-
id 'com.netflix.nebula.plugin-plugin' version '22.0.2'
17+
id("com.netflix.nebula.plugin-plugin") version ("23.+")
1818
}
1919

2020
description 'Plugin to specify and publish who the owner of a project is'
@@ -26,6 +26,12 @@ contacts {
2626
}
2727
}
2828

29+
dependencies {
30+
testImplementation("org.assertj:assertj-core:3.27.6")
31+
testImplementation("org.spockframework:spock-core:2.3-groovy-4.0")
32+
testImplementation("org.junit.vintage:junit-vintage-engine:5.+")
33+
}
34+
2935
gradlePlugin {
3036
plugins {
3137
contacts {
@@ -45,3 +51,10 @@ gradlePlugin {
4551
}
4652
}
4753

54+
testing {
55+
suites {
56+
test {
57+
useJUnitJupiter()
58+
}
59+
}
60+
}

gradle.lockfile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@
22
# Manual edits can break the build and are not advised.
33
# This file is expected to be part of source control.
44
cglib:cglib-nodep:3.2.2=integTestRuntimeClasspath,testRuntimeClasspath
5-
com.netflix.nebula:nebula-test:11.0.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
5+
com.netflix.nebula:nebula-test:11.6.3=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
66
junit:junit:4.13.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
7+
net.bytebuddy:byte-buddy:1.17.7=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
78
org.apache.groovy:groovy:4.0.4=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
89
org.apiguardian:apiguardian-api:1.1.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
10+
org.assertj:assertj-core:3.27.6=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
911
org.hamcrest:hamcrest-core:1.3=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
1012
org.hamcrest:hamcrest:2.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
11-
org.junit.platform:junit-platform-commons:1.13.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
12-
org.junit.platform:junit-platform-engine:1.13.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
13-
org.junit.platform:junit-platform-launcher:1.13.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
13+
org.jspecify:jspecify:1.0.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
14+
org.junit.jupiter:junit-jupiter-api:5.12.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
15+
org.junit.jupiter:junit-jupiter-engine:5.12.2=integTestRuntimeClasspath,testRuntimeClasspath
16+
org.junit.jupiter:junit-jupiter-params:5.12.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
17+
org.junit.jupiter:junit-jupiter:5.12.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
18+
org.junit.platform:junit-platform-commons:1.14.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
19+
org.junit.platform:junit-platform-engine:1.14.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
20+
org.junit.platform:junit-platform-launcher:1.14.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
21+
org.junit.vintage:junit-vintage-engine:5.14.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
1422
org.objenesis:objenesis:2.4=integTestRuntimeClasspath,testRuntimeClasspath
1523
org.opentest4j:opentest4j:1.3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
1624
org.spockframework:spock-core:2.3-groovy-4.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
17-
org.spockframework:spock-junit4:2.3-groovy-4.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
1825
empty=annotationProcessor,compileClasspath,integTestAnnotationProcessor,runtimeClasspath,testAnnotationProcessor

src/main/groovy/nebula/plugin/contacts/Contact.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.gradle.api.Named
88
*/
99
@Canonical
1010
class Contact implements Named {
11-
final String email
11+
String email
1212

1313
/**
1414
* Aka name, but Named interface won't let us call it that
@@ -53,19 +53,19 @@ class Contact implements Named {
5353

5454
// Temporary until we can find a annotation to do this for us
5555
void moniker(String moniker) {
56-
if(!moniker)
56+
if (!moniker)
5757
return
5858
this.moniker = moniker
5959
}
6060

6161
void github(String github) {
62-
if(!github)
62+
if (!github)
6363
return
6464
this.github = github
6565
}
6666

6767
void twitter(String twitter) {
68-
if(!twitter)
68+
if (!twitter)
6969
return
7070
this.twitter = twitter
7171
}

src/main/groovy/nebula/plugin/contacts/ContactsExtension.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package nebula.plugin.contacts
22

3+
import org.gradle.api.Action
4+
import org.gradle.api.NamedDomainObjectContainer
5+
36
/**
47
* Holds Person for a project.
58
* TODO repeat a name and guarantee uniqueness
@@ -8,6 +11,7 @@ class ContactsExtension {
811

912
private final String emailPattern = /[_A-Za-z0-9-]+(.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(.[A-Za-z0-9]+)*(.[A-Za-z]{2,})/
1013

14+
NamedDomainObjectContainer<Contact> peopleContainer
1115
final LinkedHashMap<String, Contact> people
1216
boolean validateEmails
1317

@@ -65,6 +69,15 @@ class ContactsExtension {
6569
return person
6670
}
6771

72+
Contact addPerson(String email, Action<Contact> closure) {
73+
if(validateEmails)
74+
validateEmail(email)
75+
def person = people.containsKey(email) ? BaseContactsPlugin.cloneContact(people.get(email)) : new Contact(email)
76+
closure.execute(person)
77+
people.put(email, person)
78+
return person
79+
}
80+
6881
private validateEmail(String email) {
6982
if(!(email ==~ emailPattern)) {
7083
throw new ContactsPluginException("$email is not a valid email")

src/test/groovy/nebula/plugin/contacts/BaseContactsPluginSpec.groovy

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@
1515
*/
1616
package nebula.plugin.contacts
1717

18-
import nebula.test.PluginProjectSpec
18+
import org.gradle.api.Project
1919
import org.gradle.testfixtures.ProjectBuilder
20+
import org.junit.Before
2021

21-
class BaseContactsPluginSpec extends PluginProjectSpec {
22-
@Override
23-
String getPluginName() {
24-
'com.netflix.nebula.contacts'
22+
import spock.lang.Specification
23+
import spock.lang.TempDir
24+
25+
class BaseContactsPluginSpec extends Specification {
26+
27+
@TempDir
28+
File projectDir
29+
Project project
30+
31+
@Before
32+
void setup() {
33+
project = ProjectBuilder.builder().build()
2534
}
2635

2736
def 'extension accessible'() {

src/test/groovy/nebula/plugin/contacts/ContactsPluginSpec.groovy

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package nebula.plugin.contacts;
2+
3+
import nebula.test.dsl.BuildscriptLanguage;
4+
import nebula.test.dsl.TestProjectBuilder;
5+
import org.gradle.testkit.runner.BuildResult;
6+
import org.gradle.testkit.runner.GradleRunner;
7+
import org.junit.jupiter.api.io.TempDir;
8+
import org.junit.jupiter.params.ParameterizedTest;
9+
import org.junit.jupiter.params.provider.EnumSource;
10+
11+
import java.io.File;
12+
13+
import static nebula.test.dsl.TestKitAssertions.assertThat;
14+
15+
class ContactsPluginTest {
16+
@TempDir
17+
File projectDir;
18+
19+
@ParameterizedTest
20+
@EnumSource(SupportedGradleVersion.class)
21+
void test_kotlin(SupportedGradleVersion gradleVersion) {
22+
final TestProjectBuilder builder = TestProjectBuilder.testProject(projectDir);
23+
builder.rootProject().plugins().id("com.netflix.nebula.contacts");
24+
builder.rootProject()
25+
.rawBuildScript(
26+
//language=kotlin
27+
"""
28+
contacts {
29+
addPerson("example@example.com") {
30+
moniker = "Nebula-Plugins maintainers"
31+
github = "nebula-plugins"
32+
role("owner")
33+
}
34+
}
35+
""");
36+
final var runner = builder.build(BuildscriptLanguage.KOTLIN);
37+
38+
39+
BuildResult result = runner.run(GradleRunner.create().withGradleVersion(gradleVersion.version), "build");
40+
assertThat(result)
41+
.hasNoDeprecationWarnings()
42+
.hasNoMutableStateWarnings();
43+
}
44+
45+
@ParameterizedTest
46+
@EnumSource(SupportedGradleVersion.class)
47+
void test_groovy(SupportedGradleVersion gradleVersion) {
48+
final TestProjectBuilder builder = TestProjectBuilder.testProject(projectDir);
49+
builder.rootProject().plugins().id("com.netflix.nebula.contacts");
50+
builder.rootProject()
51+
.rawBuildScript(
52+
//language=groovy
53+
"""
54+
contacts {
55+
"example@example.com" {
56+
moniker = "Nebula-Plugins maintainers"
57+
github = "nebula-plugins"
58+
role("owner")
59+
}
60+
}
61+
""");
62+
final var runner = builder.build(BuildscriptLanguage.GROOVY);
63+
64+
65+
BuildResult result = runner.run(GradleRunner.create().withGradleVersion(gradleVersion.version), "build");
66+
assertThat(result)
67+
.hasNoDeprecationWarnings()
68+
.hasNoMutableStateWarnings();
69+
}
70+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package nebula.plugin.contacts;
2+
3+
enum SupportedGradleVersion {
4+
MIN("9.0.0"), MAX("9.1.0");
5+
public final String version;
6+
7+
SupportedGradleVersion(String version) {
8+
this.version = version;
9+
}
10+
}

0 commit comments

Comments
 (0)