Skip to content

Commit 9360b8b

Browse files
author
mtctx
committed
Changed URL from String to URI & renamed to uri
1 parent 2b5e6ba commit 9360b8b

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ plugins {
2525
}
2626

2727
group = "dev.mtctx.unipub"
28-
version = "1.0.15"
28+
version = "1.0.16"
2929

3030
repositories {
3131
mavenCentral()

src/main/kotlin/dev/mtctx/unipub/UniPub.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class UniPub : Plugin<Project> {
133133
settings.repositories.forEach { repository ->
134134
maven {
135135
name = repository.name
136-
url = uri(repository.url)
136+
url = repository.uri
137137
credentials {
138138
username = repository.username
139139
password = repository.password

src/main/kotlin/dev/mtctx/unipub/UniPubSettings.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
package dev.mtctx.unipub
2020

21+
import dev.mtctx.unipub.serializer.URISerializer
2122
import kotlinx.serialization.SerialName
2223
import kotlinx.serialization.Serializable
24+
import java.net.URI
2325

2426
@Serializable
2527
data class UniPubSettings(
@@ -35,27 +37,28 @@ data class UniPubSettings(
3537
@SerialName("name")
3638
private val _name: String,
3739
@SerialName("url")
38-
private val _url: String,
40+
@Serializable(with = URISerializer::class)
41+
private val _uri: java.net.URI,
3942
@SerialName("username")
4043
private val _username: String,
4144
@SerialName("password")
4245
private val _password: String
4346
) {
4447
val name get() = _name.resolveEnv()
45-
val url get() = _url.resolveEnv()
48+
val uri get() = _uri
4649
val username get() = _username.resolveEnv()
4750
val password get() = _password.resolveEnv()
4851

4952
init {
5053
require(name.isNotBlank()) { "A repository 'name' cannot be blank in the settings file." }
51-
require(url.isNotBlank()) { "The 'url' for repository '$name' cannot be blank." }
54+
requireNotNull(uri.scheme) { "The 'url' for repository '$name' must have a scheme (e.g. https)" }
55+
requireNotNull(uri.host) { "The 'url' for repository '$name' must have a host." }
5256
require(username.isNotBlank()) { "The 'username' for repository '$name' cannot be blank." }
5357
require(password.isNotBlank()) { "The 'password' for repository '$name' cannot be blank." }
5458
}
5559

56-
enum class URL(val url: String) {
57-
MAVEN_CENTRAL("https://s01.oss.sonatype.org/content/repositories/releases/"),
58-
MAVEN_CENTRAL_SNAPSHOTS("https://s01.oss.sonatype.org/content/repositories/snapshots/"),
60+
object URI {
61+
val MAVEN_CENTRAL = URI("https://central.sonatype.com/api/v1/publisher/deploy")
5962
}
6063
}
6164

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* UniPub: URISerializer.kt
3+
* Copyright (C) 2025 mtctx
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package dev.mtctx.unipub.serializer
20+
21+
import dev.mtctx.unipub.resolveEnv
22+
import kotlinx.serialization.KSerializer
23+
import kotlinx.serialization.descriptors.PrimitiveKind
24+
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
25+
import kotlinx.serialization.descriptors.SerialDescriptor
26+
import kotlinx.serialization.encoding.Decoder
27+
import kotlinx.serialization.encoding.Encoder
28+
import java.net.URI
29+
30+
object URISerializer : KSerializer<URI> {
31+
override val descriptor: SerialDescriptor =
32+
PrimitiveSerialDescriptor("URI", PrimitiveKind.STRING)
33+
34+
override fun serialize(encoder: Encoder, value: URI) {
35+
encoder.encodeString(value.toString())
36+
}
37+
38+
override fun deserialize(decoder: Decoder): URI {
39+
return URI.create(decoder.decodeString().resolveEnv())
40+
}
41+
}

src/main/kotlin/dev/mtctx/unipub/task/GenerateSettingsTemplateTasks.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ abstract class UniPubGenerateTemplateSettingsTask : DefaultTask() {
6666
repositories = listOf(
6767
UniPubSettings.Repository(
6868
"maven-central",
69-
UniPubSettings.Repository.URL.MAVEN_CENTRAL.url,
69+
UniPubSettings.Repository.URI.MAVEN_CENTRAL,
7070
"YOUR_USERNAME",
7171
"YOUR_PASSWORD"
7272
)

0 commit comments

Comments
 (0)