Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4][#6] Close and release tasks #9

Merged
merged 20 commits into from
Jan 23, 2020
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
7 changes: 1 addition & 6 deletions .stutter/java8.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# DO NOT MODIFY: Generated by Stutter plugin.
4.10.3
5.0
5.1.1
5.2.1
5.3.1
5.4.1
5.5.1
5.6.2
5.6.3
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ repositories {
val licenseHeaderFile = file("gradle/license-header.txt")
spotless {
kotlin {
ktlint()
//"import-ordering" required here as it started to fail after spotless plugin upgrade to 0.35.0 - resolve in separate PR
ktlint().userData(mapOf("disabled_rules" to "comment-spacing,import-ordering"))
licenseHeaderFile(licenseHeaderFile)
}
}
Expand Down Expand Up @@ -91,6 +92,7 @@ dependencies {
}

stutter {
isSparse = (findProperty("stutter.sparce")?.toString()?.toBoolean()) ?: true
java(8) {
compatibleRange("4.10")
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ package io.github.gradlenexus.publishplugin
import java.nio.file.Files
import java.nio.file.Path

fun Path.write(text: String) {
fun Path.write(text: String): Path {
Files.createDirectories(parent)
toFile().writeText(text)
return this
}

fun Path.append(text: String): Path {
Files.createDirectories(parent)
toFile().appendText(text)
return this
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.DefaultTask
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.gradle.kotlin.dsl.property
import java.time.Duration
import javax.inject.Inject

@Suppress("UnstableApiUsage")
abstract class AbstractNexusStagingRepositoryTask @Inject
constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository: NexusRepository) : DefaultTask() {

@Internal
val clientTimeout = objects.property<Duration>().apply {
set(extension.clientTimeout)
}

@Internal
val connectTimeout = objects.property<Duration>().apply {
set(extension.connectTimeout)
}

//TODO: Expose externally as interface with getters only
@Nested
val repository = objects.property<NexusRepository>().apply {
set(repository)
}

init {
this.onlyIf { extension.useStaging.getOrElse(false) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 io.github.gradlenexus.publishplugin.internal.NexusClient
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
import org.gradle.kotlin.dsl.property
import javax.inject.Inject

@Suppress("UnstableApiUsage")
open class CloseNexusStagingRepository @Inject
constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository: NexusRepository) :
AbstractNexusStagingRepositoryTask(objects, extension, repository) {

@Input
val stagingRepositoryId = objects.property<String>()

@Option(option = "staging-repository-id", description = "staging repository id to close")
fun setStagingRepositoryId(stagingRepositoryId: String) {
this.stagingRepositoryId.set(stagingRepositoryId)
}

@TaskAction
fun closeStagingRepo() {
val client = NexusClient(repository.get().nexusUrl.get(), repository.get().username.orNull, repository.get().password.orNull, clientTimeout.orNull, connectTimeout.orNull)
logger.info("Closing staging repository with id '{}'", stagingRepositoryId.get())
client.closeStagingRepository(stagingRepositoryId.get()) //should be checked by @Input
// 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 @@ -23,6 +23,7 @@ import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.internal.NamedDomainObjectContainerConfigureDelegate
import org.gradle.util.ConfigureUtil

@Suppress("UnstableApiUsage")
internal class DefaultNexusRepositoryContainer(delegate: NamedDomainObjectContainer<NexusRepository>) : NexusRepositoryContainer, NamedDomainObjectContainer<NexusRepository> by delegate {

override fun sonatype(): NexusRepository = sonatype {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,32 @@ package io.github.gradlenexus.publishplugin

import io.codearte.gradle.nexus.NexusStagingExtension
import io.github.gradlenexus.publishplugin.internal.NexusClient
import java.net.URI
import java.time.Duration
import javax.inject.Inject
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.property
import org.gradle.kotlin.dsl.the
import java.net.URI
import javax.inject.Inject

@Suppress("UnstableApiUsage")
open class InitializeNexusStagingRepository @Inject
constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository: NexusRepository, private val serverUrlToStagingRepoUrl: MutableMap<URI, URI>) : DefaultTask() {

@get:Input
val serverUrl: Property<URI> = objects.property()

@get:Optional
@get:Input
val username: Property<String> = objects.property()

@get:Optional
@get:Input
val password: Property<String> = objects.property()

@get:Optional
@get:Input
val packageGroup: Property<String> = objects.property()

@get:Optional
@get:Input
val stagingProfileId: Property<String> = objects.property()

@get:Input
val repositoryName: Property<String> = objects.property()

@get:Internal
val clientTimeout: Property<Duration> = objects.property()

@get:Internal
val connectTimeout: Property<Duration> = objects.property()

init {
serverUrl.set(repository.nexusUrl)
username.set(repository.username)
password.set(repository.password)
packageGroup.set(extension.packageGroup)
stagingProfileId.set(repository.stagingProfileId)
repositoryName.set(repository.name)
clientTimeout.set(extension.clientTimeout)
connectTimeout.set(extension.connectTimeout)
this.onlyIf { extension.useStaging.getOrElse(false) }
constructor(
objects: ObjectFactory,
extension: NexusPublishExtension,
repository: NexusRepository,
private val serverUrlToStagingRepoUrl: MutableMap<URI, URI>,
private val stagingRepositoryId: (String) -> Unit
) : AbstractNexusStagingRepositoryTask(objects, extension, repository) {

@Optional
@Input
val packageGroup = objects.property<String>().apply {
set(extension.packageGroup)
}

@TaskAction
Expand All @@ -85,28 +53,31 @@ constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository
}

internal fun createStagingRepo(): URI {
return serverUrlToStagingRepoUrl.computeIfAbsent(serverUrl.get()) { serverUrl ->
val client = NexusClient(serverUrl, username.orNull, password.orNull, clientTimeout.orNull, connectTimeout.orNull)
return serverUrlToStagingRepoUrl.computeIfAbsent(repository.get().nexusUrl.get()) { serverUrl ->
val client = NexusClient(serverUrl, repository.get().username.orNull, repository.get().password.orNull, clientTimeout.orNull, connectTimeout.orNull)
val stagingProfileId = determineStagingProfileId(client)
logger.info("Creating staging repository for stagingProfileId '{}'", stagingProfileId)
val stagingRepositoryId = client.createStagingRepository(stagingProfileId)
val stagingRepositoryIdAsString = client.createStagingRepository(stagingProfileId)
stagingRepositoryId.invoke(stagingRepositoryIdAsString)

//TODO: To be removed in next iteration
project.rootProject.plugins.withId("io.codearte.nexus-staging") {
val nexusStagingExtension = project.rootProject.the<NexusStagingExtension>()
try {
nexusStagingExtension.stagingRepositoryId.set(stagingRepositoryId)
nexusStagingExtension.stagingRepositoryId.set(stagingRepositoryIdAsString)
} catch (e: NoSuchMethodError) {
logger.warn("For increased publishing reliability please update the io.codearte.nexus-staging plugin to at least version 0.20.0.\n" +
"If your version is at least 0.20.0, try to update the io.github.gradle-nexus.publish-plugin plugin to its latest version.\n" +
"If this also does not make this warning go away, please report an issue for io.github.gradle-nexus.publish-plugin.")
logger.debug("getStagingRepositoryId method not found on nexusStagingExtension", e)
}
}
client.getStagingRepositoryUri(stagingRepositoryId)
client.getStagingRepositoryUri(stagingRepositoryIdAsString)
}
}

private fun determineStagingProfileId(client: NexusClient): String {
var stagingProfileId = stagingProfileId.orNull
var stagingProfileId = repository.get().stagingProfileId.orNull
if (stagingProfileId == null) {
val packageGroup = packageGroup.get()
logger.debug("No stagingProfileId set, querying for packageGroup '{}'", packageGroup)
Expand All @@ -118,7 +89,7 @@ constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository

private fun replacePublishingRepoUrl(url: URI) {
val publishing = project.the<PublishingExtension>()
val repository = publishing.repositories.getByName(repositoryName.get()) as MavenArtifactRepository
val repository = publishing.repositories.getByName(repository.get().name) as MavenArtifactRepository
logger.info("Updating URL of publishing repository '{}' to '{}'", repository.name, url)
repository.setUrl(url.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package io.github.gradlenexus.publishplugin
import java.time.Duration
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.kotlin.dsl.container
import org.gradle.kotlin.dsl.newInstance
import org.gradle.kotlin.dsl.property
Expand All @@ -31,19 +30,19 @@ open class NexusPublishExtension(project: Project) {
internal const val NAME = "nexusPublishing"
}

val useStaging: Property<Boolean> = project.objects.property<Boolean>().apply {
val useStaging = project.objects.property<Boolean>().apply {
set(project.provider { !project.version.toString().endsWith("-SNAPSHOT") })
}

val packageGroup: Property<String> = project.objects.property<String>().apply {
val packageGroup = project.objects.property<String>().apply {
set(project.provider { project.group.toString() })
}

val clientTimeout: Property<Duration> = project.objects.property<Duration>().apply {
val clientTimeout = project.objects.property<Duration>().apply {
set(Duration.ofMinutes(1))
}

val connectTimeout: Property<Duration> = project.objects.property<Duration>().apply {
val connectTimeout = project.objects.property<Duration>().apply {
set(Duration.ofMinutes(1))
}

Expand Down
Loading