diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/BaseOperationOnNexusStagingRepository.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/BaseOperationOnNexusStagingRepository.kt new file mode 100644 index 00000000..7665ae5a --- /dev/null +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/BaseOperationOnNexusStagingRepository.kt @@ -0,0 +1,73 @@ +/* + * 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.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 +import java.time.Duration +import javax.inject.Inject + +@Suppress("UnstableApiUsage") +abstract class BaseOperationOnNexusStagingRepository @Inject +constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository: NexusRepository) : DefaultTask() { + + @get:Input + protected val serverUrl: Property = objects.property() + + @get:Optional + @get:Input + protected val username: Property = objects.property() + + @get:Optional + @get:Input + protected val password: Property = objects.property() + + @get:Optional + @get:Input + protected val packageGroup: Property = objects.property() + + @get:Optional + @get:Input + protected val stagingProfileId: Property = objects.property() + + @get:Input + protected val repositoryName: Property = objects.property() + + @get:Internal + protected val clientTimeout: Property = objects.property() + + @get:Internal + protected val connectTimeout: Property = 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) } + } +} diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/InitializeNexusStagingRepository.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/InitializeNexusStagingRepository.kt index 06a590b2..5eeed67c 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/InitializeNexusStagingRepository.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/InitializeNexusStagingRepository.kt @@ -18,65 +18,19 @@ package io.github.gradlenexus.publishplugin import io.github.gradlenexus.publishplugin.internal.NexusClient import io.codearte.gradle.nexus.NexusStagingExtension -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 java.time.Duration import javax.inject.Inject @Suppress("UnstableApiUsage") open class InitializeNexusStagingRepository @Inject -constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository: NexusRepository, private val serverUrlToStagingRepoUrl: MutableMap) : DefaultTask() { - - @get:Input - val serverUrl: Property = objects.property() - - @get:Optional - @get:Input - val username: Property = objects.property() - - @get:Optional - @get:Input - val password: Property = objects.property() - - @get:Optional - @get:Input - val packageGroup: Property = objects.property() - - @get:Optional - @get:Input - val stagingProfileId: Property = objects.property() - - @get:Input - val repositoryName: Property = objects.property() - - @get:Internal - val clientTimeout: Property = objects.property() - - @get:Internal - val connectTimeout: Property = 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) : + BaseOperationOnNexusStagingRepository(objects, extension, repository) { @TaskAction fun createStagingRepoAndReplacePublishingRepoUrl() {