Skip to content

Commit b92668a

Browse files
committed
[#4] Base class for staging repository operations
1 parent a7d3812 commit b92668a

File tree

2 files changed

+75
-48
lines changed

2 files changed

+75
-48
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.github.gradlenexus.publishplugin
18+
19+
import org.gradle.api.DefaultTask
20+
import org.gradle.api.model.ObjectFactory
21+
import org.gradle.api.provider.Property
22+
import org.gradle.api.tasks.Input
23+
import org.gradle.api.tasks.Internal
24+
import org.gradle.api.tasks.Optional
25+
import org.gradle.kotlin.dsl.property
26+
import java.net.URI
27+
import java.time.Duration
28+
import javax.inject.Inject
29+
30+
@Suppress("UnstableApiUsage")
31+
abstract class BaseOperationOnNexusStagingRepository @Inject
32+
constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository: NexusRepository) : DefaultTask() {
33+
34+
@get:Input
35+
protected val serverUrl: Property<URI> = objects.property()
36+
37+
@get:Optional
38+
@get:Input
39+
protected val username: Property<String> = objects.property()
40+
41+
@get:Optional
42+
@get:Input
43+
protected val password: Property<String> = objects.property()
44+
45+
@get:Optional
46+
@get:Input
47+
protected val packageGroup: Property<String> = objects.property()
48+
49+
@get:Optional
50+
@get:Input
51+
protected val stagingProfileId: Property<String> = objects.property()
52+
53+
@get:Input
54+
protected val repositoryName: Property<String> = objects.property()
55+
56+
@get:Internal
57+
protected val clientTimeout: Property<Duration> = objects.property()
58+
59+
@get:Internal
60+
protected val connectTimeout: Property<Duration> = objects.property()
61+
62+
init {
63+
serverUrl.set(repository.nexusUrl)
64+
username.set(repository.username)
65+
password.set(repository.password)
66+
packageGroup.set(extension.packageGroup)
67+
stagingProfileId.set(repository.stagingProfileId)
68+
repositoryName.set(repository.name)
69+
clientTimeout.set(extension.clientTimeout)
70+
connectTimeout.set(extension.connectTimeout)
71+
this.onlyIf { extension.useStaging.getOrElse(false) }
72+
}
73+
}

src/main/kotlin/io/github/gradlenexus/publishplugin/InitializeNexusStagingRepository.kt

+2-48
Original file line numberDiff line numberDiff line change
@@ -18,65 +18,19 @@ package io.github.gradlenexus.publishplugin
1818

1919
import io.github.gradlenexus.publishplugin.internal.NexusClient
2020
import io.codearte.gradle.nexus.NexusStagingExtension
21-
import org.gradle.api.DefaultTask
2221
import org.gradle.api.GradleException
2322
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
2423
import org.gradle.api.model.ObjectFactory
25-
import org.gradle.api.provider.Property
2624
import org.gradle.api.publish.PublishingExtension
27-
import org.gradle.api.tasks.Input
28-
import org.gradle.api.tasks.Internal
29-
import org.gradle.api.tasks.Optional
3025
import org.gradle.api.tasks.TaskAction
31-
import org.gradle.kotlin.dsl.property
3226
import org.gradle.kotlin.dsl.the
3327
import java.net.URI
34-
import java.time.Duration
3528
import javax.inject.Inject
3629

3730
@Suppress("UnstableApiUsage")
3831
open class InitializeNexusStagingRepository @Inject
39-
constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository: NexusRepository, private val serverUrlToStagingRepoUrl: MutableMap<URI, URI>) : DefaultTask() {
40-
41-
@get:Input
42-
val serverUrl: Property<URI> = objects.property()
43-
44-
@get:Optional
45-
@get:Input
46-
val username: Property<String> = objects.property()
47-
48-
@get:Optional
49-
@get:Input
50-
val password: Property<String> = objects.property()
51-
52-
@get:Optional
53-
@get:Input
54-
val packageGroup: Property<String> = objects.property()
55-
56-
@get:Optional
57-
@get:Input
58-
val stagingProfileId: Property<String> = objects.property()
59-
60-
@get:Input
61-
val repositoryName: Property<String> = objects.property()
62-
63-
@get:Internal
64-
val clientTimeout: Property<Duration> = objects.property()
65-
66-
@get:Internal
67-
val connectTimeout: Property<Duration> = objects.property()
68-
69-
init {
70-
serverUrl.set(repository.nexusUrl)
71-
username.set(repository.username)
72-
password.set(repository.password)
73-
packageGroup.set(extension.packageGroup)
74-
stagingProfileId.set(repository.stagingProfileId)
75-
repositoryName.set(repository.name)
76-
clientTimeout.set(extension.clientTimeout)
77-
connectTimeout.set(extension.connectTimeout)
78-
this.onlyIf { extension.useStaging.getOrElse(false) }
79-
}
32+
constructor(objects: ObjectFactory, extension: NexusPublishExtension, repository: NexusRepository, private val serverUrlToStagingRepoUrl: MutableMap<URI, URI>) :
33+
BaseOperationOnNexusStagingRepository(objects, extension, repository) {
8034

8135
@TaskAction
8236
fun createStagingRepoAndReplacePublishingRepoUrl() {

0 commit comments

Comments
 (0)