Skip to content

Commit

Permalink
[#4] Base class for staging repository operations
Browse files Browse the repository at this point in the history
  • Loading branch information
szpak committed Oct 16, 2019
1 parent a7d3812 commit b92668a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -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<URI> = objects.property()

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

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

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

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

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

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

@get:Internal
protected 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) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<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>) :
BaseOperationOnNexusStagingRepository(objects, extension, repository) {

@TaskAction
fun createStagingRepoAndReplacePublishingRepoUrl() {
Expand Down

0 comments on commit b92668a

Please sign in to comment.