Skip to content

Commit

Permalink
[#4] Workaround problem with finalized properties in task
Browse files Browse the repository at this point in the history
  • Loading branch information
szpak committed Jan 3, 2020
1 parent 2531bac commit 716a6b1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ class NexusPublishPluginTests {
repositories {
myNexus {
nexusUrl = uri('${server.baseUrl()}')
snapshotRepositoryUrl = uri('${server.baseUrl()}/snapshots/')
username = 'username'
password = 'password'
}
someOtherNexus {
nexusUrl = uri('http://example.org')
snapshotRepositoryUrl = uri('http://example.org/snapshots/')
}
}
}
Expand Down Expand Up @@ -301,6 +303,7 @@ class NexusPublishPluginTests {
repositories {
myNexus {
nexusUrl = uri('${server.baseUrl()}/a/')
snapshotRepositoryUrl = uri('${server.baseUrl()}/a/snapshots/')
stagingProfileId = 'profile-a'
username = 'username'
password = 'password'
Expand All @@ -313,6 +316,7 @@ class NexusPublishPluginTests {
repositories {
named('myNexus').configure {
nexusUrl = uri('${server.baseUrl()}/b/')
snapshotRepositoryUrl = uri('${server.baseUrl()}/b/snapshots/')
stagingProfileId = 'profile-b'
}
}
Expand Down Expand Up @@ -426,6 +430,7 @@ class NexusPublishPluginTests {
repositories {
myNexus {
nexusUrl = uri('${server.baseUrl()}')
snapshotRepositoryUrl = uri('${server.baseUrl()}/snapshots/')
}
}
}
Expand Down Expand Up @@ -467,6 +472,7 @@ class NexusPublishPluginTests {
repositories {
myNexus {
nexusUrl = uri('${server.baseUrl()}')
snapshotRepositoryUrl = uri('${server.baseUrl()}/snapshots/')
username = 'username'
password = 'password'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.Optional
import org.gradle.kotlin.dsl.property
import java.time.Duration
Expand All @@ -43,7 +44,7 @@ constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository
protected val connectTimeout: Property<Duration> = objects.property()

//TODO: Expose externally as interface with getters only
//@get:Nested //FIXME: @Nested switch values in NexusRepository to state = Final which prevent settings stagingRepositoryId in init task
@get:Nested
protected val repository: Property<NexusRepository> = objects.property()

init {
Expand All @@ -66,6 +67,6 @@ constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository
}

protected fun keepStagingRepositoryIdInExtension(stagingRepositoryIdAsString: String) {
repository.get().stagingRepositoryId.set(stagingRepositoryIdAsString)
repository.get().stagingRepository.set(NexusStagingRepository(stagingRepositoryIdAsString, project))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import io.github.gradlenexus.publishplugin.internal.NexusClient
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
import org.gradle.kotlin.dsl.property
import javax.inject.Inject

Expand All @@ -31,20 +31,22 @@ constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository
AbstractNexusStagingRepositoryTask(objects, extension, repository) {

@get:Input
@get:Option(option = "stagingRepositoryId", description = "stagingRepositoryId to close")
val stagingRepositoryId: Property<String> = objects.property()
@get:Nested
val stagingRepository: Property<NexusStagingRepository> = objects.property()

//TODO: Bring back an ability to define stagingRepositoryId from a command line (and propagate that value back to NexusStagingRepository for Release*)

init {
// TODO: Replace with convention() once only Gradle 5.1+ is supported
stagingRepositoryId.set(repository.stagingRepositoryId)
stagingRepository.set(repository.stagingRepository)
}

@TaskAction
fun closeStagingRepo() {
val client = NexusClient(repository.get().nexusUrl.get(), repository.get().username.orNull, repository.get().password.orNull, clientTimeout.orNull, connectTimeout.orNull)
val stagingProfileId = determineStagingProfileId(client)
logger.info("Closing staging repository with id '{}' for stagingProfileId '{}'", stagingRepositoryId.get(), stagingProfileId)
client.closeStagingRepository(stagingRepositoryId.get())
logger.info("Closing staging repository with id '{}' for stagingProfileId '{}'", stagingRepository.get().stagingRepositoryId.get(), stagingProfileId)
client.closeStagingRepository(stagingRepository.get().stagingRepositoryId.get())
// TODO: Broken with real Nexus - waiting for effective execution is also required https://github.com/gradle-nexus/publish-plugin/issues/7
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package io.github.gradlenexus.publishplugin
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.kotlin.dsl.property
import java.net.URI
Expand Down Expand Up @@ -49,9 +50,8 @@ open class NexusRepository @Inject constructor(@get:Input val name: String, proj
@get:Input
val stagingProfileId: Property<String> = project.objects.property()

@get:Optional
@get:Input
val stagingRepositoryId: Property<String> = project.objects.property()
@get:Internal
val stagingRepository: Property<NexusStagingRepository> = project.objects.property()

internal fun capitalizedName(): String {
return name.capitalize()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.gradlenexus.publishplugin

import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Internal
import org.gradle.kotlin.dsl.property
import javax.inject.Inject

@Suppress("UnstableApiUsage")
open class NexusStagingRepository @Inject constructor(stagingRepositoryIdAsString: String, project: Project) {

@Internal
val stagingRepositoryId: Property<String> = project.objects.property()

init {
stagingRepositoryId.set(stagingRepositoryIdAsString)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,34 @@ import io.github.gradlenexus.publishplugin.internal.NexusClient
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
import org.gradle.kotlin.dsl.property
import javax.inject.Inject

//TODO: Extract the same logic from CloseNexusStagingRepository and ReleaseNexusStagingRepository
@Suppress("UnstableApiUsage")
open class ReleaseNexusStagingRepository @Inject
constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository: NexusRepository) :
AbstractNexusStagingRepositoryTask(objects, extension, repository) {

@get:Input
@get:Option(option = "stagingRepositoryId", description = "stagingRepositoryId to release")
val stagingRepositoryId: Property<String> = objects.property()
@get:Nested
val stagingRepository: Property<NexusStagingRepository> = objects.property()

//TODO: Bring back an ability to define stagingRepositoryId from a command line

init {
// TODO: Replace with convention() once only Gradle 5.1+ is supported
stagingRepositoryId.set(repository.stagingRepositoryId)
stagingRepository.set(repository.stagingRepository)
}

@TaskAction
fun releaseStagingRepo() {
val client = NexusClient(repository.get().nexusUrl.get(), repository.get().username.orNull, repository.get().password.orNull, clientTimeout.orNull, connectTimeout.orNull)
val stagingProfileId = determineStagingProfileId(client) // TODO: Will it update value in extension?
logger.info("Releasing staging repository with id '{}' for stagingProfileId '{}'", stagingRepositoryId.get(), stagingProfileId)
client.releaseStagingRepository(stagingRepositoryId.get())
logger.info("Releasing staging repository with id '{}' for stagingProfileId '{}'", stagingRepository.get().stagingRepositoryId.get(), stagingProfileId)
client.releaseStagingRepository(stagingRepository.get().stagingRepositoryId.get())
// TODO: Broken with real Nexus - waiting for effective execution is also required https://github.com/gradle-nexus/publish-plugin/issues/7
}
}

0 comments on commit 716a6b1

Please sign in to comment.