@@ -4,10 +4,14 @@ import nebula.test.dsl.*
44import nebula.test.dsl.TestKitAssertions.assertThat
55import org.ajoberstar.grgit.Grgit
66import org.gradle.testkit.runner.TaskOutcome
7+ import org.junit.jupiter.api.AfterEach
78import org.junit.jupiter.api.BeforeEach
89import org.junit.jupiter.api.Test
910import org.junit.jupiter.api.io.TempDir
11+ import org.mockserver.configuration.ConfigurationProperties
12+ import org.mockserver.integration.ClientAndServer
1013import java.io.File
14+ import java.net.ServerSocket
1115
1216internal class NebulaLibraryPluginTest {
1317 @TempDir
@@ -16,55 +20,44 @@ internal class NebulaLibraryPluginTest {
1620 @TempDir
1721 lateinit var remoteGitDir: File
1822
19- lateinit var runner : TestProjectRunner
20- lateinit var localCopy : Grgit
23+ private lateinit var artifactory : ClientAndServer
24+ private var port : Int = 0
2125
2226 @BeforeEach
23- fun beforeEach () {
24- val remoteGit = Grgit .init {
25- this .dir = remoteGitDir
26- }
27- localCopy = Grgit .clone {
28- this .dir = projectDir
29- this .uri = remoteGitDir.toURI().toString()
30- }
31- projectDir.resolve(" .gitignore" ).writeText(
32- """
33- .gradle/
34- """
35- )
36- runner = testProject(projectDir) {
37- rootProject {
38- plugins {
39- id(" com.netflix.nebula.root" )
40- id(" com.netflix.nebula.library" )
41- }
42- rawBuildScript(
43- """
44- tasks.withType<AbstractPublishToMaven>() {
45- onlyIf { false }
46- }
47- """ .trimIndent()
48- )
49- src {
50- main {
51- java(" example/Main.java" , SAMPLE_JAVA_MAIN_CLASS )
52- }
53- }
27+ fun startArtifactory () {
28+ port = try {
29+ ServerSocket (0 ).use { socket ->
30+ socket.getLocalPort()
5431 }
32+ } catch (_: Exception ) {
33+ 8080
5534 }
56- localCopy.add {
57- this .patterns = setOf (" ." )
58- }
59- localCopy.commit {
60- message = " Initial"
61- }
35+ artifactory = ClientAndServer .startClientAndServer(port)
36+ ConfigurationProperties .logLevel(" ERROR" )
37+ }
38+
39+ @AfterEach
40+ fun stopArtifactory () {
41+ artifactory.stop()
6242 }
6343
6444 @Test
6545 fun `test candidate` () {
66- localCopy.tag.add {
67- name = " v0.0.1-rc.1"
46+ val runner = withGitTag(projectDir, remoteGitDir, " v0.0.1-rc.1" ) {
47+ testProject(projectDir) {
48+ rootProject {
49+ plugins {
50+ id(" com.netflix.nebula.root" )
51+ id(" com.netflix.nebula.library" )
52+ }
53+ disableMavenPublishTasks()
54+ src {
55+ main {
56+ java(" example/Main.java" , SAMPLE_JAVA_MAIN_CLASS )
57+ }
58+ }
59+ }
60+ }
6861 }
6962 val result = runner.run (
7063 " candidate" ,
@@ -83,8 +76,21 @@ tasks.withType<AbstractPublishToMaven>() {
8376
8477 @Test
8578 fun `test final` () {
86- localCopy.tag.add {
87- name = " v0.0.1"
79+ val runner = withGitTag(projectDir, remoteGitDir, " v0.0.1" ) {
80+ testProject(projectDir) {
81+ rootProject {
82+ plugins {
83+ id(" com.netflix.nebula.root" )
84+ id(" com.netflix.nebula.library" )
85+ }
86+ disableMavenPublishTasks()
87+ src {
88+ main {
89+ java(" example/Main.java" , SAMPLE_JAVA_MAIN_CLASS )
90+ }
91+ }
92+ }
93+ }
8894 }
8995 val result = runner.run (
9096 " final" ,
@@ -104,4 +110,89 @@ tasks.withType<AbstractPublishToMaven>() {
104110 assertThat(result.output).contains(" :closeAndReleaseSonatypeStagingRepository SKIPPED" )
105111 assertThat(result.output).contains(" :final SKIPPED" )
106112 }
113+
114+ @Test
115+ fun `test multi-project library only` () {
116+ val version = " 0.0.1"
117+ val runner = withGitTag(projectDir, remoteGitDir, " v$version " ) {
118+ testProject(projectDir) {
119+ rootProject {
120+ plugins {
121+ id(" com.netflix.nebula.root" )
122+ }
123+ nebulaOssPublishing(" http://localhost:$port " )
124+ overrideSonatypeUrlRoot(" http://localhost:$port " )
125+ contacts()
126+ }
127+ subProject(" library" ) {
128+ plugins {
129+ id(" com.netflix.nebula.library" )
130+ }
131+ rawBuildScript(""" description = "description"""" )
132+ mockSign()
133+ allowInsecure()
134+ src {
135+ main {
136+ java(" example/Main.java" , SAMPLE_JAVA_MAIN_CLASS )
137+ }
138+ }
139+ }
140+ }
141+ }
142+ artifactory.mockNexus()
143+ val libraryVerifications = artifactory.expectPublication(
144+ " gradle-plugins" ,
145+ " com.netflix.nebula" ,
146+ " library" ,
147+ version
148+ ) {
149+ withArtifact(" jar" )
150+ withArtifact(" sources" , " jar" )
151+ withArtifact(" javadoc" , " jar" )
152+ withGradleModuleMetadata()
153+ }
154+ val sonatypeVerifications = artifactory.expectPublication(
155+ " staging/deployByRepositoryId/1" ,
156+ " com.netflix.nebula" ,
157+ " library" ,
158+ version
159+ ) {
160+ withArtifact(" jar" )
161+ withArtifact(" sources" , " jar" )
162+ withArtifact(" javadoc" , " jar" )
163+ withGradleModuleMetadata()
164+ }
165+ val result = runner.run (
166+ " final" ,
167+ " -Prelease.useLastTag=true" ,
168+ " -PnetflixOss.username=user" ,
169+ " -PnetflixOss.password=password" ,
170+ " -Psonatype.username=user" ,
171+ " -Psonatype.password=password" ,
172+ " --stacktrace"
173+ )
174+ assertThat(result.task(" :generatePomFileForNebulaPublication" )).isNull()
175+
176+ assertThat(result.task(" :initializeSonatypeStagingRepository" )).hasOutcome(TaskOutcome .SUCCESS )
177+
178+ // library publication
179+ assertThat(result.task(" :library:javadoc" )).hasOutcome(TaskOutcome .SUCCESS )
180+ assertThat(result.task(" :library:generatePomFileForNebulaPublication" ))
181+ .hasOutcome(TaskOutcome .SUCCESS )
182+ assertThat(result.task(" :library:publishNebulaPublicationToNetflixOSSRepository" ))
183+ .hasOutcome(TaskOutcome .SUCCESS )
184+ assertThat(result.task(" :library:publishNebulaPublicationToSonatypeRepository" ))
185+ .hasOutcome(TaskOutcome .SUCCESS )
186+
187+ // global
188+ assertThat(result.task(" :postRelease" )).hasOutcome(TaskOutcome .SUCCESS )
189+ assertThat(result.task(" :closeSonatypeStagingRepository" )).hasOutcome(TaskOutcome .SUCCESS )
190+ assertThat(result.task(" :releaseSonatypeStagingRepository" )).hasOutcome(TaskOutcome .SUCCESS )
191+ assertThat(result.task(" :closeAndReleaseSonatypeStagingRepository" )).hasOutcome(TaskOutcome .SUCCESS )
192+ assertThat(result.task(" :final" )).hasOutcome(TaskOutcome .SUCCESS )
193+
194+
195+ libraryVerifications.verify(artifactory)
196+ sonatypeVerifications.verify(artifactory)
197+ }
107198}
0 commit comments