Skip to content

Commit af881e9

Browse files
committed
add API to ContactsExtension that can be used from kts buildscripts
fixes #12
1 parent e9a7ac5 commit af881e9

7 files changed

Lines changed: 90 additions & 54 deletions

File tree

.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: 12 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,10 @@ contacts {
2626
}
2727
}
2828

29+
dependencies {
30+
testImplementation("org.assertj:assertj-core:3.27.6")
31+
}
32+
2933
gradlePlugin {
3034
plugins {
3135
contacts {
@@ -45,3 +49,10 @@ gradlePlugin {
4549
}
4650
}
4751

52+
testing {
53+
suites {
54+
test {
55+
useJUnitJupiter()
56+
}
57+
}
58+
}

gradle.lockfile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
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
6-
junit:junit:4.13.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
7-
org.apache.groovy:groovy:4.0.4=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
5+
com.netflix.nebula:nebula-test:11.6.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
6+
net.bytebuddy:byte-buddy:1.17.7=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
87
org.apiguardian:apiguardian-api:1.1.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
9-
org.hamcrest:hamcrest-core:1.3=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
10-
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
8+
org.assertj:assertj-core:3.27.6=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
9+
org.jspecify:jspecify:1.0.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
10+
org.junit.jupiter:junit-jupiter-api:5.12.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
11+
org.junit.jupiter:junit-jupiter-engine:5.12.2=integTestRuntimeClasspath,testRuntimeClasspath
12+
org.junit.jupiter:junit-jupiter-params:5.12.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
13+
org.junit.jupiter:junit-jupiter:5.12.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
14+
org.junit.platform:junit-platform-commons:1.14.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
15+
org.junit.platform:junit-platform-engine:1.14.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
16+
org.junit.platform:junit-platform-launcher:1.14.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
1417
org.objenesis:objenesis:2.4=integTestRuntimeClasspath,testRuntimeClasspath
1518
org.opentest4j:opentest4j:1.3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
16-
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
1819
empty=annotationProcessor,compileClasspath,integTestAnnotationProcessor,runtimeClasspath,testAnnotationProcessor

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

Lines changed: 3 additions & 2 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
@@ -31,7 +31,8 @@ class Contact implements Named {
3131
String slack = ""
3232

3333
Set<String> roles = [] as Set
34-
34+
Contact() {
35+
}
3536
Contact(String email) {
3637
this.email = email
3738
}

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")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.io.TempDir;
8+
9+
import java.io.File;
10+
11+
import static nebula.test.dsl.TestKitAssertions.assertThat;
12+
13+
class ContactsPluginTest {
14+
@TempDir
15+
File projectDir;
16+
17+
@Test
18+
void test_kotlin() {
19+
final TestProjectBuilder builder = TestProjectBuilder.testProject(projectDir);
20+
builder.rootProject().plugins().id("com.netflix.nebula.contacts");
21+
builder.rootProject()
22+
.rawBuildScript(
23+
//language=kotlin
24+
"""
25+
contacts {
26+
addPerson("example@example.com") {
27+
moniker = "Nebula-Plugins maintainers"
28+
github = "nebula-plugins"
29+
}
30+
}
31+
""");
32+
final var runner = builder.build(BuildscriptLanguage.KOTLIN);
33+
34+
35+
BuildResult result = runner.run("build");
36+
assertThat(result)
37+
.hasNoDeprecationWarnings()
38+
.hasNoMutableStateWarnings();
39+
}
40+
41+
}

0 commit comments

Comments
 (0)